2018-03-24 15:37:35 +00:00
|
|
|
const test = require('../testlib');
|
2018-03-23 17:16:39 +00:00
|
|
|
|
2018-03-24 15:37:35 +00:00
|
|
|
test.run(async function () {
|
2018-03-26 17:32:32 +00:00
|
|
|
await test('admin', async function (assert, req) {
|
2018-03-24 14:09:33 +00:00
|
|
|
//Try to login with invalid username and password
|
|
|
|
var res = await req({
|
|
|
|
url: '/sessions',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
username: 'foo',
|
|
|
|
password: 'bar'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 403, 'Status not valid');
|
|
|
|
|
|
|
|
//Try to login with invalid username
|
|
|
|
var res = await req({
|
|
|
|
url: '/sessions',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
username: 'foo',
|
|
|
|
password: 'admin'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 403, 'Status not valid');
|
|
|
|
|
|
|
|
//Try to login with invalid password
|
|
|
|
var res = await req({
|
|
|
|
url: '/sessions',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
username: 'admin',
|
|
|
|
password: 'foo'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 403, 'Status not valid');
|
|
|
|
|
|
|
|
//Try to login with missing field
|
|
|
|
var res = await req({
|
|
|
|
url: '/sessions',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
password: 'admin'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 422, 'Status not valid');
|
|
|
|
|
2018-04-03 11:43:56 +00:00
|
|
|
//Try to login with prefix
|
2018-03-24 14:09:33 +00:00
|
|
|
var res = await req({
|
|
|
|
url: '/sessions',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
2018-04-05 12:53:56 +00:00
|
|
|
username: 'config/configuser',
|
|
|
|
password: 'configuser'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 201, 'Status not valid');
|
|
|
|
|
|
|
|
//Try to login with prefix but no db entry
|
|
|
|
var res = await req({
|
|
|
|
url: '/sessions',
|
|
|
|
method: 'post',
|
|
|
|
data: {
|
|
|
|
username: 'config/notindb',
|
|
|
|
password: 'notindb'
|
2018-03-24 14:09:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.status, 201, 'Status not valid');
|
2018-03-23 17:16:39 +00:00
|
|
|
});
|
2018-03-24 15:37:35 +00:00
|
|
|
});
|