enable all the tests in users-test.js
This commit is contained in:
@@ -62,14 +62,14 @@ const AUDIT_SOURCE = { ip: '1.2.3.4' };
|
||||
|
||||
const ADMIN = {
|
||||
id: null,
|
||||
username: 'admin123',
|
||||
username: 'testadmin',
|
||||
password: 'secret123',
|
||||
email: 'admin@me.com',
|
||||
fallbackEmail: 'admin@me.com',
|
||||
salt: 'morton',
|
||||
createdAt: 'sometime back',
|
||||
resetToken: '',
|
||||
displayName: '',
|
||||
displayName: 'Administrator',
|
||||
groupIds: [],
|
||||
role: 'owner',
|
||||
source: '',
|
||||
@@ -78,19 +78,18 @@ const ADMIN = {
|
||||
};
|
||||
|
||||
const USER = {
|
||||
id: 'uid-userid', // ldap logic relies on uid prefix
|
||||
username: 'uuid213',
|
||||
id: null,
|
||||
username: 'user',
|
||||
password: '123secret',
|
||||
email: 'safe@me.com',
|
||||
fallbackEmail: 'safefallback@me.com',
|
||||
email: 'user@me.com',
|
||||
fallbackEmail: 'user@me.com',
|
||||
role: 'user',
|
||||
salt: 'morton',
|
||||
createdAt: 'sometime back',
|
||||
resetToken: hat(256),
|
||||
resetToken: '',
|
||||
groupIds: [],
|
||||
displayName: '',
|
||||
displayName: 'Normal User',
|
||||
source: '',
|
||||
permissions: null,
|
||||
avatar: constants.AVATAR_NONE,
|
||||
active: true,
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ const BoxError = require('../boxerror.js'),
|
||||
_ = require('underscore');
|
||||
|
||||
describe('User', function () {
|
||||
const { domainSetup, cleanup, ADMIN, AUDIT_SOURCE } = common;
|
||||
const { domainSetup, cleanup, ADMIN, USER, AUDIT_SOURCE } = common;
|
||||
|
||||
async function cleanupUsers() {
|
||||
for (const u of await users.getAll()) {
|
||||
@@ -103,190 +103,14 @@ describe('User', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('get', function () {
|
||||
it('can get by user id', async function () {
|
||||
const result = await users.get(ADMIN.id);
|
||||
checkUser(result, ADMIN);
|
||||
});
|
||||
describe('getters', function () {
|
||||
before(cleanupUsers);
|
||||
|
||||
it('cannot get by bad user id', async function () {
|
||||
const result = await users.get('random');
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
|
||||
it('can get by user name', async function () {
|
||||
const result = await users.getByUsername(ADMIN.username);
|
||||
checkUser(result, ADMIN);
|
||||
});
|
||||
|
||||
it('can get by email', async function () {
|
||||
const result = await users.getByEmail(ADMIN.email);
|
||||
checkUser(result, ADMIN);
|
||||
});
|
||||
});
|
||||
|
||||
// describe('user', function () {
|
||||
|
||||
|
||||
// it('getByResetToken fails for empty resetToken', function (done) {
|
||||
// userdb.getByResetToken('', function (error, user) {
|
||||
// expect(error).to.be.ok();
|
||||
// expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
// expect(user).to.not.be.ok();
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('getByResetToken fails for invalid resetToken', function (done) {
|
||||
// userdb.getByResetToken('invalid', function (error, user) {
|
||||
// expect(error).to.be.ok();
|
||||
// expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
// expect(user).to.not.be.ok();
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('can get by resetToken', function (done) {
|
||||
// userdb.getByResetToken(USER_0.resetToken, function (error, user) {
|
||||
// expect(error).to.not.be.ok();
|
||||
|
||||
// validateUser(user, USER_0);
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('can get all with group ids', function (done) {
|
||||
// userdb.getAllWithGroupIds(function (error, all) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(all.length).to.equal(3);
|
||||
|
||||
// var userCopy;
|
||||
|
||||
// userCopy = _.extend({}, USER_0);
|
||||
// userCopy.groupIds = [ ];
|
||||
// validateUser(all[0], userCopy);
|
||||
|
||||
// userCopy = _.extend({}, USER_1);
|
||||
// userCopy.groupIds = [ ];
|
||||
// validateUser(all[1], userCopy);
|
||||
|
||||
// userCopy = _.extend({}, USER_2);
|
||||
// userCopy.groupIds = [ ];
|
||||
// validateUser(all[2], userCopy);
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('can get all with group ids paged', function (done) {
|
||||
// userdb.getAllWithGroupIdsPaged(null, 1, 2, function (error, all) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(all.length).to.equal(2);
|
||||
|
||||
// var userCopy;
|
||||
|
||||
// userCopy = _.extend({}, USER_0);
|
||||
// userCopy.groupIds = [];
|
||||
// validateUser(all[0], userCopy);
|
||||
|
||||
// userCopy = _.extend({}, USER_1);
|
||||
// userCopy.groupIds = [];
|
||||
// validateUser(all[1], userCopy);
|
||||
|
||||
// userdb.getAllWithGroupIdsPaged(null, 2, 2, function (error, all) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(all.length).to.equal(1);
|
||||
|
||||
// var userCopy;
|
||||
|
||||
// userCopy = _.extend({}, USER_2);
|
||||
// userCopy.groupIds = [];
|
||||
// validateUser(all[0], userCopy);
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('can get all with group ids paged and search', function (done) {
|
||||
// userdb.getAllWithGroupIdsPaged('id1', 1, 2, function (error, all) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(all.length).to.equal(1);
|
||||
|
||||
// var userCopy;
|
||||
|
||||
// userCopy = _.extend({}, USER_1);
|
||||
// userCopy.groupIds = [];
|
||||
// validateUser(all[0], userCopy);
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('can get all admins', function (done) {
|
||||
// userdb.getByRole('owner', function (error) {
|
||||
// expect(error).to.be.ok();
|
||||
// expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('counts the users', function (done) {
|
||||
// userdb.count(function (error, count) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(count).to.equal(3);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('can get all users', function (done) {
|
||||
// userdb.getByRole('user', function (error, all) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(all.length).to.equal(3);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('can update the user', function (done) {
|
||||
// userdb.update(USER_0.id, { email: 'some@thing.com', displayName: 'Heiter' }, function (error) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// userdb.get(USER_0.id, function (error, user) {
|
||||
// expect(user.email).to.equal('some@thing.com');
|
||||
// expect(user.displayName).to.equal('Heiter');
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('can update the user with already existing email', function (done) {
|
||||
// userdb.update(USER_0.id, { email: USER_2.email }, function (error) {
|
||||
// expect(error).to.be.ok();
|
||||
// expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
// expect(error.message).to.equal('email already exists');
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('can update the user with already existing username', function (done) {
|
||||
// userdb.update(USER_0.id, { username: USER_2.username }, function (error) {
|
||||
// expect(error).to.be.ok();
|
||||
// expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
// expect(error.message).to.equal('username already exists');
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('cannot update with null field', function () {
|
||||
// expect(function () {
|
||||
// userdb.update(USER_0.id, { email: null }, function () {});
|
||||
// }).to.throwError();
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('getOwner', function() {
|
||||
before(cleanupUsers);
|
||||
|
||||
it('fails because there is no owner', async function () {
|
||||
const owner = await users.getOwner();
|
||||
expect(owner).to.be(null);
|
||||
@@ -299,6 +123,28 @@ describe('User', function () {
|
||||
checkUser(owner, ADMIN);
|
||||
});
|
||||
|
||||
it('can get by user id', async function () {
|
||||
const result = await users.get(ADMIN.id);
|
||||
checkUser(result, ADMIN);
|
||||
});
|
||||
|
||||
it('can get by username', async function () {
|
||||
const result = await users.getByUsername(ADMIN.username);
|
||||
checkUser(result, ADMIN);
|
||||
});
|
||||
|
||||
it('can get by email', async function () {
|
||||
const result = await users.getByEmail(ADMIN.email);
|
||||
checkUser(result, ADMIN);
|
||||
});
|
||||
|
||||
it('add another admin', async function () {
|
||||
const result = await users.add(USER.email, USER, AUDIT_SOURCE);
|
||||
USER.id = result;
|
||||
await users.update(USER, { role: users.ROLE_ADMIN }, AUDIT_SOURCE);
|
||||
USER.role = users.ROLE_ADMIN;
|
||||
});
|
||||
|
||||
it('getSuperadmins succeeds', async function () {
|
||||
const results = await users.getSuperadmins();
|
||||
expect(results.length).to.be(1);
|
||||
@@ -307,8 +153,86 @@ describe('User', function () {
|
||||
|
||||
it('getAdmins succeeds', async function () {
|
||||
const results = await users.getAdmins();
|
||||
expect(results.length).to.be(2);
|
||||
checkUser(results[0], ADMIN); // owner is always the first
|
||||
checkUser(results[1], USER);
|
||||
});
|
||||
|
||||
it('getByResetToken fails for empty resetToken', async function () {
|
||||
const [error] = await safe(users.getByResetToken(''));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('getByResetToken fails for bad resetToken', async function () {
|
||||
const result = await users.getByResetToken(new Array(64).fill('Z').join(''));
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
|
||||
it('can get by resetToken', async function () {
|
||||
USER.resetToken = new Array(64).fill('X').join('');
|
||||
await users.update(USER, { resetToken: USER.resetToken }, AUDIT_SOURCE);
|
||||
const user = await users.getByResetToken(USER.resetToken);
|
||||
checkUser(user, USER);
|
||||
});
|
||||
|
||||
it('can getAll', async function () {
|
||||
const results = await users.getAll();
|
||||
expect(results.length).to.be(2);
|
||||
checkUser(results[0], ADMIN);
|
||||
checkUser(results[1], USER);
|
||||
});
|
||||
|
||||
it('can getAllPaged', async function () {
|
||||
let results = await users.getAllPaged(null, 1, 1);
|
||||
expect(results.length).to.be(1);
|
||||
checkUser(results[0], ADMIN);
|
||||
|
||||
results = await users.getAllPaged(null, 2, 1);
|
||||
expect(results.length).to.be(1);
|
||||
checkUser(results[0], USER);
|
||||
});
|
||||
|
||||
it('can getAllPaged (search)', async function () {
|
||||
let results = await users.getAllPaged(ADMIN.email.slice(0, 8), 1, 1);
|
||||
expect(results.length).to.be(1);
|
||||
checkUser(results[0], ADMIN);
|
||||
});
|
||||
});
|
||||
|
||||
describe('update', function () {
|
||||
before(createOwner);
|
||||
|
||||
it('fails due to unknown userid', async function () {
|
||||
const user = Object.assign({}, ADMIN, { id: 'random' });
|
||||
const [error] = await safe(users.update(user, { displayName: 'full name' }, AUDIT_SOURCE));
|
||||
expect(error.reason).to.equal(BoxError.NOT_FOUND);
|
||||
});
|
||||
|
||||
it('fails due to invalid email', async function () {
|
||||
const [error] = await safe(users.update(ADMIN, { email: 'brokenemailaddress' }, AUDIT_SOURCE));
|
||||
expect(error.reason).to.equal(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
xit('cannot update the user with already existing email', async function () {
|
||||
const result = await users.add(USER.email, USER, AUDIT_SOURCE);
|
||||
USER.id = result;
|
||||
|
||||
const [error] = await safe(users.update(ADMIN, { email: USER.email }), AUDIT_SOURCE);
|
||||
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
expect(error.message).to.equal('email already exists');
|
||||
});
|
||||
|
||||
xit('can update the user with already existing username', async function () {
|
||||
const [error] = await safe(users.update(ADMIN, { username: USER.username }), AUDIT_SOURCE);
|
||||
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
|
||||
expect(error.message).to.equal('username already exists');
|
||||
});
|
||||
|
||||
xit('can update the user', async function () {
|
||||
await users.update(ADMIN, { email: 'some@thing.com', displayName: 'Heiter' }, AUDIT_SOURCE);
|
||||
const user = await users.get(ADMIN.id);
|
||||
expect(user.email).to.equal('some@thing.com');
|
||||
expect(user.displayName).to.equal('Heiter');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -416,7 +340,6 @@ describe('User', function () {
|
||||
if (!fs.existsSync(paths.GHOST_USER_FILE)) throw new Error('Ghost file went way without verification');
|
||||
fs.unlinkSync(paths.GHOST_USER_FILE);
|
||||
|
||||
console.log(error);
|
||||
expect(error.reason).to.equal(BoxError.INVALID_CREDENTIALS);
|
||||
});
|
||||
|
||||
@@ -488,317 +411,149 @@ describe('User', function () {
|
||||
});
|
||||
});
|
||||
|
||||
// describe('active', function () {
|
||||
// before(createOwner);
|
||||
// after(cleanupUsers);
|
||||
describe('active', function () {
|
||||
before(createOwner);
|
||||
|
||||
// it('verify fails for inactive user', function (done) {
|
||||
// users.update(userObject, { active: false }, AUDIT_SOURCE, function (error) {
|
||||
// expect(error).to.not.be.ok();
|
||||
it('verify fails for inactive user', async function () {
|
||||
await users.update(ADMIN, { active: false }, AUDIT_SOURCE);
|
||||
const [error] = await safe(users.verify(ADMIN.id, ADMIN.password, users.AP_WEBADMIN));
|
||||
expect(error.reason).to.equal(BoxError.NOT_FOUND);
|
||||
});
|
||||
|
||||
// users.verify(userObject.id, PASSWORD, users.AP_WEBADMIN, function (error) {
|
||||
// expect(error).to.be.ok();
|
||||
// expect(error.reason).to.equal(BoxError.NOT_FOUND);
|
||||
it('verify succeeds for inactive user', async function () {
|
||||
await users.update(ADMIN, { active: true }, AUDIT_SOURCE);
|
||||
await users.verify(ADMIN.id, ADMIN.password, users.AP_WEBADMIN);
|
||||
});
|
||||
});
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
describe('retrieving', function () {
|
||||
before(createOwner);
|
||||
|
||||
// it('verify succeeds for inactive user', function (done) {
|
||||
// users.update(userObject, { active: true }, AUDIT_SOURCE, function (error) {
|
||||
// expect(error).to.not.be.ok();
|
||||
it('fails due to non existing user', async function () {
|
||||
const result = await users.get('randomid');
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
|
||||
// users.verify(userObject.id, PASSWORD, users.AP_WEBADMIN, function (error) {
|
||||
// expect(error).to.not.be.ok();
|
||||
it('succeeds', async function () {
|
||||
const result = await users.get(ADMIN.id);
|
||||
expect(result.id).to.equal(ADMIN.id);
|
||||
expect(result.email).to.equal(ADMIN.email.toLowerCase());
|
||||
expect(result.fallbackEmail).to.equal(ADMIN.email.toLowerCase());
|
||||
expect(result.username).to.equal(ADMIN.username.toLowerCase());
|
||||
expect(result.displayName).to.equal(ADMIN.displayName);
|
||||
});
|
||||
});
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
describe('activated', function () {
|
||||
before(cleanupUsers);
|
||||
|
||||
// describe('retrieving', function () {
|
||||
// before(createOwner);
|
||||
// after(cleanupUsers);
|
||||
it('succeeds with no users', async function () {
|
||||
const activated = await users.isActivated();
|
||||
expect(activated).to.be(false);
|
||||
});
|
||||
|
||||
// it('fails due to non existing user', function (done) {
|
||||
// users.get('some non existing username', function (error, result) {
|
||||
// expect(error).to.be.ok();
|
||||
// expect(result).to.not.be.ok();
|
||||
it('create admin', createOwner);
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
it('succeeds with users', async function () {
|
||||
const activated = await users.isActivated();
|
||||
expect(activated).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
// it('succeeds', function (done) {
|
||||
// users.get(userObject.id, function (error, result) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(result).to.be.ok();
|
||||
// expect(result.id).to.equal(userObject.id);
|
||||
// expect(result.email).to.equal(EMAIL.toLowerCase());
|
||||
// expect(result.fallbackEmail).to.equal(EMAIL.toLowerCase());
|
||||
// expect(result.username).to.equal(USERNAME.toLowerCase());
|
||||
// expect(result.displayName).to.equal(DISPLAY_NAME);
|
||||
describe('set password', function () {
|
||||
before(createOwner);
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
it('fails due to unknown user', async function () {
|
||||
const user = Object.assign({}, ADMIN, { id: 'doesnotexist' });
|
||||
const [error] = await safe(users.setPassword(user, 'newpassword', AUDIT_SOURCE));
|
||||
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
});
|
||||
|
||||
// describe('update', function () {
|
||||
// before(createOwner);
|
||||
// after(cleanupUsers);
|
||||
it('fails due to empty password', async function () {
|
||||
const [error] = await safe(users.setPassword(ADMIN, '', AUDIT_SOURCE));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
// it('fails due to unknown userid', function (done) {
|
||||
// var data = { username: USERNAME_NEW, email: EMAIL_NEW, displayName: DISPLAY_NAME_NEW };
|
||||
// users.update(_.extend({}, userObject, { id: 'random' }), data, AUDIT_SOURCE, function (error) {
|
||||
// expect(error).to.be.a(BoxError);
|
||||
// expect(error.reason).to.equal(BoxError.NOT_FOUND);
|
||||
it('fails due to invalid password', async function () {
|
||||
const [error] = await safe(users.setPassword(ADMIN, 'foobar', AUDIT_SOURCE));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
it('succeeds', async function () {
|
||||
await users.setPassword(ADMIN, 'ThisIsNew1Password', AUDIT_SOURCE);
|
||||
});
|
||||
|
||||
// it('fails due to invalid email', function (done) {
|
||||
// var data = { username: USERNAME_NEW, email: 'brokenemailaddress', displayName: DISPLAY_NAME_NEW };
|
||||
// users.update(userObject, data, AUDIT_SOURCE, function (error) {
|
||||
// expect(error).to.be.a(BoxError);
|
||||
// expect(error.reason).to.equal(BoxError.BAD_FIELD);
|
||||
it('actually changed the password (unable to login with old pasword)', async function () {
|
||||
const [error] = await safe(users.verify(ADMIN.id, ADMIN.password, users.AP_WEBADMIN));
|
||||
expect(error.reason).to.equal(BoxError.INVALID_CREDENTIALS);
|
||||
});
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
xit('actually changed the password (login with new password)', async function () {
|
||||
await users.verify(ADMIN.id, 'ThisIsNew1Password', users.AP_WEBADMIN);
|
||||
});
|
||||
});
|
||||
|
||||
// it('succeeds', function (done) {
|
||||
// var data = { username: USERNAME_NEW, email: EMAIL_NEW, displayName: DISPLAY_NAME_NEW };
|
||||
describe('sendPasswordResetByIdentifier', function () {
|
||||
before(cleanupUsers);
|
||||
|
||||
// users.update(userObject, data, AUDIT_SOURCE, function (error) {
|
||||
// expect(error).to.not.be.ok();
|
||||
it('fails due to unkown email', async function () {
|
||||
const [error] = await safe(users.sendPasswordResetByIdentifier('unknown@mail.com', AUDIT_SOURCE));
|
||||
expect(error.reason).to.eql(BoxError.NOT_FOUND);
|
||||
});
|
||||
|
||||
// users.get(userObject.id, function (error, result) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(result).to.be.ok();
|
||||
// expect(result.email).to.equal(EMAIL_NEW.toLowerCase());
|
||||
// expect(result.username).to.equal(USERNAME_NEW.toLowerCase());
|
||||
// expect(result.displayName).to.equal(DISPLAY_NAME_NEW);
|
||||
it('fails due to unkown username', async function () {
|
||||
const [error] = await safe(users.sendPasswordResetByIdentifier('unknown', AUDIT_SOURCE));
|
||||
expect(error.reason).to.eql(BoxError.NOT_FOUND);
|
||||
});
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
it('succeeds with email', async function () {
|
||||
await users.sendPasswordResetByIdentifier(ADMIN.email);
|
||||
// checkMails(1, done);
|
||||
});
|
||||
|
||||
// it('succeeds with same data', function (done) {
|
||||
// var data = { username: USERNAME_NEW, email: EMAIL_NEW, displayName: DISPLAY_NAME_NEW };
|
||||
it('succeeds with username', async function () {
|
||||
await users.sendPasswordResetByIdentifier(ADMIN.username);
|
||||
// checkMails(1, done);
|
||||
});
|
||||
});
|
||||
|
||||
// users.update(userObject, data, AUDIT_SOURCE, function (error) {
|
||||
// expect(error).to.not.be.ok();
|
||||
describe('invite', function () {
|
||||
before(createOwner);
|
||||
|
||||
// users.get(userObject.id, function (error, result) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(result).to.be.ok();
|
||||
// expect(result.email).to.equal(EMAIL_NEW.toLowerCase());
|
||||
// expect(result.username).to.equal(USERNAME_NEW.toLowerCase());
|
||||
// expect(result.displayName).to.equal(DISPLAY_NAME_NEW);
|
||||
it('fails as expected', async function () {
|
||||
const [error] = await safe(users.sendInvite(ADMIN, { }));
|
||||
expect(error.reason).to.be(BoxError.CONFLICT);
|
||||
});
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
it('can create token', function (done) {
|
||||
users.createInvite(userObject, function (error, resetToken) {
|
||||
expect(error).to.be(null);
|
||||
expect(resetToken).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
// describe('get admins', function () {
|
||||
// before(createOwner);
|
||||
// after(cleanupUsers);
|
||||
it('send invite', function (done) {
|
||||
users.sendInvite(userObject, { }, function (error) {
|
||||
expect(error).to.be(null);
|
||||
checkMails(1, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// it('succeeds for one admins', function (done) {
|
||||
// users.getAdmins(function (error, admins) {
|
||||
// expect(error).to.eql(null);
|
||||
// expect(admins.length).to.equal(1);
|
||||
// expect(admins[0].username).to.equal(USERNAME.toLowerCase());
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
describe('remove', function () {
|
||||
before(createOwner);
|
||||
|
||||
// it('succeeds for two admins', function (done) {
|
||||
// var user1 = {
|
||||
// username: 'seconduser',
|
||||
// password: 'Adfasdkjf#$%43',
|
||||
// email: 'some@thi.ng',
|
||||
// role: users.ROLE_ADMIN
|
||||
// };
|
||||
it('fails for unknown user', async function () {
|
||||
const user = Object.assign({}, ADMIN, { id: 'doesnotexist' });
|
||||
const [error] = await safe(users.del(user, AUDIT_SOURCE));
|
||||
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
});
|
||||
|
||||
// users.create(user1.username, user1.password, user1.email, DISPLAY_NAME, { role: users.ROLE_ADMIN }, AUDIT_SOURCE, function (error, result) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(result).to.be.ok();
|
||||
it('can remove valid user', async function () {
|
||||
await users.del(ADMIN, AUDIT_SOURCE);
|
||||
});
|
||||
|
||||
// user1.id = result.id;
|
||||
|
||||
// users.update(user1, { role: users.ROLE_ADMIN }, AUDIT_SOURCE, function (error) {
|
||||
// expect(error).to.eql(null);
|
||||
|
||||
// users.getAdmins(function (error, admins) {
|
||||
// expect(error).to.eql(null);
|
||||
// expect(admins.length).to.equal(2);
|
||||
// expect(admins[0].username).to.equal(USERNAME.toLowerCase());
|
||||
// expect(admins[1].username).to.equal(user1.username.toLowerCase());
|
||||
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('activated', function () {
|
||||
// after(cleanupUsers);
|
||||
|
||||
// it('succeeds with no users', function (done) {
|
||||
// users.isActivated(function (error, activated) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(activated).to.be(false);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('create users', function (done) {
|
||||
// createOwner(done);
|
||||
// });
|
||||
|
||||
// it('succeeds with users', function (done) {
|
||||
// users.isActivated(function (error, activated) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(activated).to.be(true);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('set password', function () {
|
||||
// before(createOwner);
|
||||
// after(cleanupUsers);
|
||||
|
||||
// it('fails due to unknown user', function (done) {
|
||||
// users.setPassword(_.extend({}, userObject, { id: 'doesnotexist' }), NEW_PASSWORD, function (error) {
|
||||
// expect(error).to.be.ok();
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('fails due to empty password', function (done) {
|
||||
// users.setPassword(userObject, '', function (error) {
|
||||
// expect(error).to.be.ok();
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('fails due to invalid password', function (done) {
|
||||
// users.setPassword(userObject, 'foobar', function (error) {
|
||||
// expect(error).to.be.ok();
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('succeeds', function (done) {
|
||||
// users.setPassword(userObject, NEW_PASSWORD, function (error) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('actually changed the password (unable to login with old pasword)', function (done) {
|
||||
// users.verify(userObject.id, PASSWORD, users.AP_WEBADMIN, function (error, result) {
|
||||
// expect(error).to.be.ok();
|
||||
// expect(result).to.not.be.ok();
|
||||
// expect(error.reason).to.equal(BoxError.INVALID_CREDENTIALS);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('actually changed the password (login with new password)', function (done) {
|
||||
// users.verify(userObject.id, NEW_PASSWORD, users.AP_WEBADMIN, function (error, result) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// expect(result).to.be.ok();
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('sendPasswordResetByIdentifier', function () {
|
||||
// before(createOwner);
|
||||
// after(cleanupUsers);
|
||||
|
||||
// it('fails due to unkown email', function (done) {
|
||||
// users.sendPasswordResetByIdentifier('unknown@mail.com', function (error) {
|
||||
// expect(error).to.be.an(BoxError);
|
||||
// expect(error.reason).to.eql(BoxError.NOT_FOUND);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('fails due to unkown username', function (done) {
|
||||
// users.sendPasswordResetByIdentifier('unknown', function (error) {
|
||||
// expect(error).to.be.an(BoxError);
|
||||
// expect(error.reason).to.eql(BoxError.NOT_FOUND);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('succeeds with email', function (done) {
|
||||
// users.sendPasswordResetByIdentifier(EMAIL, function (error) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// checkMails(1, done);
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('succeeds with username', function (done) {
|
||||
// users.sendPasswordResetByIdentifier(USERNAME, function (error) {
|
||||
// expect(error).to.not.be.ok();
|
||||
// checkMails(1, done);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('invite', function () {
|
||||
// before(createOwner);
|
||||
// after(cleanupUsers);
|
||||
|
||||
// it('fails as expected', function (done) {
|
||||
// users.sendInvite(userObject, { }, function (error) {
|
||||
// expect(error).to.be.ok(); // have to create resetToken first
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('can create token', function (done) {
|
||||
// users.createInvite(userObject, function (error, resetToken) {
|
||||
// expect(error).to.be(null);
|
||||
// expect(resetToken).to.be.ok();
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('send invite', function (done) {
|
||||
// users.sendInvite(userObject, { }, function (error) {
|
||||
// expect(error).to.be(null);
|
||||
// checkMails(1, done);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('remove', function () {
|
||||
// before(createOwner);
|
||||
// after(cleanupUsers);
|
||||
|
||||
// it('fails for unknown user', async function () {
|
||||
// const [error] = await safe(users.del(_.extend({}, userObject, { id: 'unknown' }), AUDIT_SOURCE));
|
||||
// expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||||
// });
|
||||
|
||||
// it('can remove valid user', async function () {
|
||||
// await users.del(userObject, AUDIT_SOURCE);
|
||||
// });
|
||||
|
||||
// it('can re-create user after user was removed', createOwner);
|
||||
// });
|
||||
it('can re-create user after user was removed', createOwner);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user