1
0
Fork 0

code now fits to the documentation of the arangoUser object inside th… (#8352)

* code now fits to the documentation of the arangoUser object inside the foxx request object

* more tests
This commit is contained in:
Heiko 2019-03-11 12:43:59 +01:00 committed by Michael Hackstein
parent 85227e00e4
commit def7b613db
2 changed files with 149 additions and 1 deletions

View File

@ -191,7 +191,11 @@ module.exports =
}
get arangoUser () {
return this._raw.user;
if (this._raw.authorized) {
return this._raw.user;
} else {
return null;
}
}
get arangoVersion () {

View File

@ -40,4 +40,148 @@ describe('Foxx arangoUser', function () {
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: 'root'}));
});
it('should not set the arangoUser object if not authenticated correctly - used invalid password', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer('root:invalidpassword').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
it('should not set the arangoUser object if not authenticated correctly - used invalid username', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer('iamnotavaliduser:').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
it('should not set the arangoUser object if not authenticated correctly - used invalid username and password', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer('iamnotavaliduser:noriamavalidpassword').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
it('should not set the arangoUser object if not authenticated correctly - empty username and empty password', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer(':').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
it('should not set the arangoUser object if not authenticated correctly - empty password', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer('iamnotavaliduser:').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
it('should not set the arangoUser object if not authenticated correctly - empty user', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer(':somerandompass').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
it('should not set the arangoUser object if not authenticated correctly - empty string', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer('').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
it('should not set the arangoUser object if not authenticated correctly - str boolean true', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer('true').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
it('should not set the arangoUser object if not authenticated correctly - str boolean false', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer('false').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
it('should not set the arangoUser object if not authenticated correctly - str array', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer('[]').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
it('should not set the arangoUser object if not authenticated correctly - str obj', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer('{}').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
it('should not set the arangoUser object if not authenticated correctly - str array', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer([]).toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
it('should not set the arangoUser object if not authenticated correctly - str obj', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer({}).toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: null}));
});
});