2015-07-20 00:09:47 -07:00
|
|
|
/* global it:false */
|
|
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2016-02-08 16:53:20 -08:00
|
|
|
var async = require('async'),
|
2016-09-27 14:52:45 +02:00
|
|
|
config = require('../config.js'),
|
2016-02-08 16:53:20 -08:00
|
|
|
database = require('../database.js'),
|
2016-09-25 23:54:27 -07:00
|
|
|
DatabaseError = require('../databaseerror.js'),
|
2016-07-12 10:07:55 -07:00
|
|
|
constants = require('../constants.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
expect = require('expect.js'),
|
2016-07-12 10:07:55 -07:00
|
|
|
fs = require('fs'),
|
2016-02-08 16:53:20 -08:00
|
|
|
groupdb = require('../groupdb.js'),
|
|
|
|
|
groups = require('../groups.js'),
|
2016-09-21 15:34:58 -07:00
|
|
|
mailboxdb = require('../mailboxdb.js'),
|
2016-01-18 14:19:20 +01:00
|
|
|
mailer = require('../mailer.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
user = require('../user.js'),
|
|
|
|
|
userdb = require('../userdb.js'),
|
2016-09-27 14:52:45 +02:00
|
|
|
settings = require('../settings.js'),
|
|
|
|
|
settingsdb = require('../settingsdb.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
UserError = user.UserError;
|
|
|
|
|
|
2016-04-13 12:15:49 +02:00
|
|
|
var USERNAME = 'noBody';
|
|
|
|
|
var USERNAME_NEW = 'noBodyNew';
|
|
|
|
|
var EMAIL = 'noBody@no.body';
|
|
|
|
|
var EMAIL_NEW = 'noBodyNew@no.body';
|
2016-01-20 14:50:06 +01:00
|
|
|
var PASSWORD = 'sTrOnG#$34134';
|
|
|
|
|
var NEW_PASSWORD = 'oTHER@#$235';
|
2016-01-19 23:34:49 -08:00
|
|
|
var DISPLAY_NAME = 'Nobody cares';
|
2016-01-25 14:08:35 +01:00
|
|
|
var DISPLAY_NAME_NEW = 'Somone cares';
|
2016-01-18 15:16:18 +01:00
|
|
|
var userObject = null;
|
2016-05-04 13:54:32 +02:00
|
|
|
var NON_ADMIN_GROUP = 'members';
|
2016-05-01 20:01:34 -07:00
|
|
|
var AUDIT_SOURCE = { ip: '1.2.3.4' };
|
|
|
|
|
|
2016-09-27 14:52:45 +02:00
|
|
|
var USERNAME_1 = 'secondUser';
|
|
|
|
|
var EMAIL_1 = 'second@user.com';
|
|
|
|
|
var PASSWORD_1 = 'Sup2345$@strong';
|
|
|
|
|
var DISPLAY_NAME_1 = 'Second User';
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
function cleanupUsers(done) {
|
2016-02-08 16:53:20 -08:00
|
|
|
async.series([
|
|
|
|
|
groupdb._clear,
|
|
|
|
|
userdb._clear,
|
2016-09-21 15:34:58 -07:00
|
|
|
mailboxdb._clear,
|
2016-02-08 16:53:20 -08:00
|
|
|
mailer._clearMailQueue
|
|
|
|
|
], done);
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
2016-02-08 15:16:59 -08:00
|
|
|
function createOwner(done) {
|
2016-02-08 16:53:20 -08:00
|
|
|
groups.create('admin', function () { // ignore error since it might already exist
|
2016-05-04 13:54:32 +02:00
|
|
|
groups.create(NON_ADMIN_GROUP, function () { // ignore error since it might already exist
|
|
|
|
|
user.createOwner(USERNAME, PASSWORD, EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
2016-01-18 15:16:18 +01:00
|
|
|
|
2016-05-04 13:54:32 +02:00
|
|
|
userObject = result;
|
2016-01-18 15:16:18 +01:00
|
|
|
|
2016-05-04 13:54:32 +02:00
|
|
|
done();
|
|
|
|
|
});
|
2016-02-08 16:53:20 -08:00
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setup(done) {
|
2016-02-08 21:17:21 -08:00
|
|
|
async.series([
|
|
|
|
|
database.initialize,
|
|
|
|
|
database._clear,
|
|
|
|
|
mailer._clearMailQueue
|
|
|
|
|
], done);
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cleanup(done) {
|
2016-01-18 14:19:20 +01:00
|
|
|
mailer._clearMailQueue();
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
database._clear(done);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-27 14:52:45 +02:00
|
|
|
function checkMails(number, options, callback) {
|
|
|
|
|
if (typeof options === 'function') {
|
|
|
|
|
callback = options;
|
|
|
|
|
options = null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 14:19:20 +01:00
|
|
|
// mails are enqueued async
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
expect(mailer._getMailQueue().length).to.equal(number);
|
2016-09-27 14:52:45 +02:00
|
|
|
|
|
|
|
|
if (options && options.sentTo) expect(mailer._getMailQueue().some(function (mail) { return mail.to === options.sentTo; }));
|
|
|
|
|
|
2016-01-18 14:19:20 +01:00
|
|
|
mailer._clearMailQueue();
|
2016-09-27 14:52:45 +02:00
|
|
|
|
|
|
|
|
callback();
|
2016-01-18 14:19:20 +01:00
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
describe('User', function () {
|
|
|
|
|
before(setup);
|
|
|
|
|
after(cleanup);
|
|
|
|
|
|
|
|
|
|
describe('create', function() {
|
|
|
|
|
before(cleanupUsers);
|
|
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
2016-01-20 14:50:06 +01:00
|
|
|
it('fails due to short password', function (done) {
|
2016-05-01 20:01:34 -07:00
|
|
|
user.create(USERNAME, 'Fo$%23', EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
2016-01-20 14:50:06 +01:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
2016-06-02 00:06:54 -07:00
|
|
|
expect(error.reason).to.equal(UserError.BAD_FIELD);
|
2016-01-20 14:50:06 +01:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to missing upper case password', function (done) {
|
2016-05-01 20:01:34 -07:00
|
|
|
user.create(USERNAME, 'thisiseightch%$234arslong', EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
2016-01-20 14:50:06 +01:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
2016-06-02 00:06:54 -07:00
|
|
|
expect(error.reason).to.equal(UserError.BAD_FIELD);
|
2016-01-20 14:50:06 +01:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to missing numerics in password', function (done) {
|
2016-05-01 20:01:34 -07:00
|
|
|
user.create(USERNAME, 'foobaRASDF%', EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
2016-01-20 14:50:06 +01:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
2016-06-02 00:06:54 -07:00
|
|
|
expect(error.reason).to.equal(UserError.BAD_FIELD);
|
2016-01-20 14:50:06 +01:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to missing special chars in password', function (done) {
|
2016-05-01 20:01:34 -07:00
|
|
|
user.create(USERNAME, 'foobaRASDF23423', EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
2016-01-20 14:50:06 +01:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
2016-06-02 00:06:54 -07:00
|
|
|
expect(error.reason).to.equal(UserError.BAD_FIELD);
|
2016-01-20 14:50:06 +01:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-04-14 16:30:31 +02:00
|
|
|
it('fails due to reserved username', function (done) {
|
2016-05-01 20:01:34 -07:00
|
|
|
user.create('admin', PASSWORD, EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
2016-04-14 16:30:31 +02:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
2016-06-02 00:06:54 -07:00
|
|
|
expect(error.reason).to.equal(UserError.BAD_FIELD);
|
2016-04-14 16:30:31 +02:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to reserved username', function (done) {
|
2016-05-23 14:52:29 -07:00
|
|
|
user.create('Mailer-Daemon', PASSWORD, EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
2016-04-14 16:30:31 +02:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
2016-06-02 00:06:54 -07:00
|
|
|
expect(error.reason).to.equal(UserError.BAD_FIELD);
|
2016-04-14 16:30:31 +02:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-05-23 14:56:09 -07:00
|
|
|
it('fails due to short username', function (done) {
|
|
|
|
|
user.create('Z', PASSWORD, EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
2016-06-02 00:06:54 -07:00
|
|
|
expect(error.reason).to.equal(UserError.BAD_FIELD);
|
2016-05-23 14:56:09 -07:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to long username', function (done) {
|
|
|
|
|
user.create(new Array(257).fill('Z').join(''), PASSWORD, EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
2016-06-02 00:06:54 -07:00
|
|
|
expect(error.reason).to.equal(UserError.BAD_FIELD);
|
2016-05-23 14:56:09 -07:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to reserved pattern', function (done) {
|
|
|
|
|
user.create('maybe-app', PASSWORD, EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
2016-06-02 00:06:54 -07:00
|
|
|
expect(error.reason).to.equal(UserError.BAD_FIELD);
|
2016-05-23 14:56:09 -07:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-01-18 14:19:20 +01:00
|
|
|
it('succeeds and attempts to send invite', function (done) {
|
2016-05-01 20:01:34 -07:00
|
|
|
user.createOwner(USERNAME, PASSWORD, EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).not.to.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
2016-04-14 16:25:46 +02:00
|
|
|
expect(result.username).to.equal(USERNAME.toLowerCase());
|
|
|
|
|
expect(result.email).to.equal(EMAIL.toLowerCase());
|
2016-09-27 14:52:45 +02:00
|
|
|
expect(result.alternativeEmail).not.to.be.ok();
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2016-01-18 16:11:00 +01:00
|
|
|
// first user is owner, do not send mail to admins
|
2016-02-08 21:17:21 -08:00
|
|
|
checkMails(0, done);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-09-25 23:51:39 -07:00
|
|
|
it('did create mailbox', function (done) {
|
|
|
|
|
mailboxdb.getMailbox(USERNAME.toLowerCase(), function (error, mailbox) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(mailbox.ownerType).to.be(mailboxdb.TYPE_USER);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
it('fails because of invalid BAD_FIELD', function (done) {
|
|
|
|
|
expect(function () {
|
|
|
|
|
user.create(EMAIL, {}, function () {});
|
|
|
|
|
}).to.throwException();
|
|
|
|
|
expect(function () {
|
|
|
|
|
user.create(12345, PASSWORD, EMAIL, function () {});
|
|
|
|
|
}).to.throwException();
|
|
|
|
|
expect(function () {
|
|
|
|
|
user.create(USERNAME, PASSWORD, EMAIL, {});
|
|
|
|
|
}).to.throwException();
|
|
|
|
|
expect(function () {
|
|
|
|
|
user.create(USERNAME, PASSWORD, EMAIL, {}, function () {});
|
|
|
|
|
}).to.throwException();
|
|
|
|
|
expect(function () {
|
|
|
|
|
user.create(USERNAME, PASSWORD, EMAIL, {});
|
|
|
|
|
}).to.throwException();
|
2016-01-18 13:50:54 +01:00
|
|
|
expect(function () {
|
|
|
|
|
user.create(USERNAME, PASSWORD, EMAIL, false, null, 'foobar');
|
|
|
|
|
}).to.throwException();
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails because user exists', function (done) {
|
2016-05-01 20:01:34 -07:00
|
|
|
user.create(USERNAME, PASSWORD, EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).not.to.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.ALREADY_EXISTS);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails because password is empty', function (done) {
|
2016-05-01 20:01:34 -07:00
|
|
|
user.create(USERNAME, '', EMAIL, DISPLAY_NAME, AUDIT_SOURCE, function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).not.to.be.ok();
|
2016-06-02 00:06:54 -07:00
|
|
|
expect(error.reason).to.equal(UserError.BAD_FIELD);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-09-27 14:52:45 +02:00
|
|
|
|
|
|
|
|
it('succeeds and attempts to send invite to alternativeEmail', function (done) {
|
|
|
|
|
// user settingsdb instead of settings, to not trigger further events
|
|
|
|
|
settingsdb.set(settings.MAIL_CONFIG_KEY, JSON.stringify({ enabled: true }), function (error) {
|
|
|
|
|
expect(error).not.to.be.ok();
|
|
|
|
|
|
|
|
|
|
user.create(USERNAME_1, PASSWORD_1, EMAIL_1, DISPLAY_NAME_1, AUDIT_SOURCE, { sendInvite: true }, function (error, result) {
|
|
|
|
|
expect(error).not.to.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
expect(result.username).to.equal(USERNAME_1.toLowerCase());
|
|
|
|
|
expect(result.email).to.equal(USERNAME_1.toLowerCase() + '@' + config.fqdn());
|
|
|
|
|
expect(result.alternativeEmail).to.equal(EMAIL_1.toLowerCase());
|
|
|
|
|
|
|
|
|
|
// first user is owner, do not send mail to admins
|
|
|
|
|
checkMails(2, { sentTo: EMAIL_1.toLowerCase() }, function (error) {
|
|
|
|
|
expect(error).not.to.be.ok();
|
|
|
|
|
|
|
|
|
|
settingsdb.set(settings.MAIL_CONFIG_KEY, JSON.stringify({ enabled: false }), done);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
2016-01-13 12:28:38 -08:00
|
|
|
describe('getOwner', function() {
|
|
|
|
|
before(cleanupUsers);
|
|
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
|
|
|
|
it('fails because there is no owner', function (done) {
|
|
|
|
|
user.getOwner(function (error) {
|
|
|
|
|
expect(error.reason).to.be(UserError.NOT_FOUND);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds', function (done) {
|
2016-02-08 15:16:59 -08:00
|
|
|
createOwner(function (error) {
|
2016-01-13 12:28:38 -08:00
|
|
|
if (error) return done(error);
|
|
|
|
|
|
|
|
|
|
user.getOwner(function (error, owner) {
|
|
|
|
|
expect(error).to.be(null);
|
2016-04-13 12:15:49 +02:00
|
|
|
expect(owner.email).to.be(EMAIL.toLowerCase());
|
2016-01-13 12:28:38 -08:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
describe('verify', function () {
|
2016-02-08 15:16:59 -08:00
|
|
|
before(createOwner);
|
2015-07-20 00:09:47 -07:00
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
2016-04-05 16:27:04 +02:00
|
|
|
it('fails due to non existing user', function (done) {
|
|
|
|
|
user.verify('somerandomid', PASSWORD, function (error, result) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.NOT_FOUND);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to empty password', function (done) {
|
|
|
|
|
user.verify(userObject.id, '', function (error, result) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.WRONG_PASSWORD);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to wrong password', function (done) {
|
|
|
|
|
user.verify(userObject.id, PASSWORD+PASSWORD, function (error, result) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.WRONG_PASSWORD);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds', function (done) {
|
|
|
|
|
user.verify(userObject.id, PASSWORD, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-07-12 10:07:55 -07:00
|
|
|
|
|
|
|
|
it('fails for ghost if not enabled', function (done) {
|
|
|
|
|
user.verify(userObject.id, 'foobar', function (error) {
|
|
|
|
|
expect(error).to.be.a(UserError);
|
|
|
|
|
expect(error.reason).to.equal(UserError.WRONG_PASSWORD);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails for ghost with wrong password', function (done) {
|
|
|
|
|
var ghost = { };
|
|
|
|
|
ghost[userObject.username] = 'testpassword';
|
|
|
|
|
fs.writeFileSync(constants.GHOST_USER_FILE, JSON.stringify(ghost), 'utf8');
|
|
|
|
|
|
|
|
|
|
user.verify(userObject.id, 'foobar', function (error) {
|
|
|
|
|
fs.unlinkSync(constants.GHOST_USER_FILE);
|
|
|
|
|
|
|
|
|
|
expect(error).to.be.a(UserError);
|
|
|
|
|
expect(error.reason).to.equal(UserError.WRONG_PASSWORD);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds for ghost', function (done) {
|
|
|
|
|
var ghost = { };
|
|
|
|
|
ghost[userObject.username] = 'testpassword';
|
|
|
|
|
fs.writeFileSync(constants.GHOST_USER_FILE, JSON.stringify(ghost), 'utf8');
|
|
|
|
|
|
|
|
|
|
user.verify(userObject.id, 'testpassword', function (error, result) {
|
|
|
|
|
fs.unlinkSync(constants.GHOST_USER_FILE);
|
|
|
|
|
|
|
|
|
|
expect(error).to.equal(null);
|
|
|
|
|
expect(result.id).to.equal(userObject.id);
|
|
|
|
|
expect(result.username).to.equal(userObject.username);
|
|
|
|
|
expect(result.email).to.equal(userObject.email);
|
|
|
|
|
expect(result.displayName).to.equal(userObject.displayName);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds for normal user password when ghost file exists', function (done) {
|
|
|
|
|
var ghost = { };
|
|
|
|
|
ghost[userObject.username] = 'testpassword';
|
|
|
|
|
fs.writeFileSync(constants.GHOST_USER_FILE, JSON.stringify(ghost), 'utf8');
|
|
|
|
|
|
|
|
|
|
user.verify(userObject.id, PASSWORD, function (error, result) {
|
|
|
|
|
fs.unlinkSync(constants.GHOST_USER_FILE);
|
|
|
|
|
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
2016-04-05 16:27:04 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('verifyWithUsername', function () {
|
|
|
|
|
before(createOwner);
|
|
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
it('fails due to non existing username', function (done) {
|
2016-04-05 16:27:04 +02:00
|
|
|
user.verifyWithUsername(USERNAME+USERNAME, PASSWORD, function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.NOT_FOUND);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to empty password', function (done) {
|
2016-04-05 16:27:04 +02:00
|
|
|
user.verifyWithUsername(USERNAME, '', function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.WRONG_PASSWORD);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to wrong password', function (done) {
|
2016-04-05 16:27:04 +02:00
|
|
|
user.verifyWithUsername(USERNAME, PASSWORD+PASSWORD, function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.WRONG_PASSWORD);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds', function (done) {
|
2016-04-05 16:27:04 +02:00
|
|
|
user.verifyWithUsername(USERNAME, PASSWORD, function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-04-13 12:15:49 +02:00
|
|
|
|
|
|
|
|
it('succeeds for different username case', function (done) {
|
|
|
|
|
user.verifyWithUsername(USERNAME.toUpperCase(), PASSWORD, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-07-12 10:07:55 -07:00
|
|
|
|
|
|
|
|
it('fails for ghost with wrong password', function (done) {
|
|
|
|
|
var ghost = { };
|
|
|
|
|
ghost[userObject.username] = 'testpassword';
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(constants.GHOST_USER_FILE, JSON.stringify(ghost), 'utf8');
|
|
|
|
|
|
|
|
|
|
user.verifyWithUsername(USERNAME, 'foobar', function (error) {
|
|
|
|
|
fs.unlinkSync(constants.GHOST_USER_FILE);
|
|
|
|
|
|
|
|
|
|
expect(error).to.be.a(UserError);
|
|
|
|
|
expect(error.reason).to.equal(UserError.WRONG_PASSWORD);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds for ghost', function (done) {
|
|
|
|
|
var ghost = { };
|
|
|
|
|
ghost[userObject.username] = 'testpassword';
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(constants.GHOST_USER_FILE, JSON.stringify(ghost), 'utf8');
|
|
|
|
|
|
|
|
|
|
user.verifyWithUsername(USERNAME, 'testpassword', function (error, result) {
|
|
|
|
|
fs.unlinkSync(constants.GHOST_USER_FILE);
|
|
|
|
|
|
|
|
|
|
expect(error).to.equal(null);
|
|
|
|
|
expect(result.id).to.equal(userObject.id);
|
|
|
|
|
expect(result.username).to.equal(userObject.username);
|
|
|
|
|
expect(result.email).to.equal(userObject.email);
|
|
|
|
|
expect(result.displayName).to.equal(userObject.displayName);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('verifyWithEmail', function () {
|
2016-02-08 15:16:59 -08:00
|
|
|
before(createOwner);
|
2015-07-20 00:09:47 -07:00
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
|
|
|
|
it('fails due to non existing user', function (done) {
|
|
|
|
|
user.verifyWithEmail(EMAIL+EMAIL, PASSWORD, function (error, result) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.NOT_FOUND);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to empty password', function (done) {
|
|
|
|
|
user.verifyWithEmail(EMAIL, '', function (error, result) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.WRONG_PASSWORD);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to wrong password', function (done) {
|
|
|
|
|
user.verifyWithEmail(EMAIL, PASSWORD+PASSWORD, function (error, result) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.WRONG_PASSWORD);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds', function (done) {
|
|
|
|
|
user.verifyWithEmail(EMAIL, PASSWORD, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-04-13 12:15:49 +02:00
|
|
|
|
|
|
|
|
it('succeeds for different email case', function (done) {
|
|
|
|
|
user.verifyWithEmail(EMAIL.toUpperCase(), PASSWORD, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-07-12 10:07:55 -07:00
|
|
|
|
|
|
|
|
it('fails for ghost with wrong password', function (done) {
|
|
|
|
|
var ghost = { };
|
|
|
|
|
ghost[userObject.username] = 'testpassword';
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(constants.GHOST_USER_FILE, JSON.stringify(ghost), 'utf8');
|
|
|
|
|
|
|
|
|
|
user.verifyWithEmail(EMAIL, 'foobar', function (error) {
|
|
|
|
|
fs.unlinkSync(constants.GHOST_USER_FILE);
|
|
|
|
|
|
|
|
|
|
expect(error).to.be.a(UserError);
|
|
|
|
|
expect(error.reason).to.equal(UserError.WRONG_PASSWORD);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds for ghost', function (done) {
|
|
|
|
|
var ghost = { };
|
|
|
|
|
ghost[userObject.username] = 'testpassword';
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(constants.GHOST_USER_FILE, JSON.stringify(ghost), 'utf8');
|
|
|
|
|
|
|
|
|
|
user.verifyWithEmail(EMAIL, 'testpassword', function (error, result) {
|
|
|
|
|
fs.unlinkSync(constants.GHOST_USER_FILE);
|
|
|
|
|
|
|
|
|
|
expect(error).to.equal(null);
|
|
|
|
|
expect(result.id).to.equal(userObject.id);
|
|
|
|
|
expect(result.username).to.equal(userObject.username);
|
|
|
|
|
expect(result.email).to.equal(userObject.email);
|
|
|
|
|
expect(result.displayName).to.equal(userObject.displayName);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('retrieving', function () {
|
2016-02-08 15:16:59 -08:00
|
|
|
before(createOwner);
|
2015-07-20 00:09:47 -07:00
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
|
|
|
|
it('fails due to non existing user', function (done) {
|
|
|
|
|
user.get('some non existing username', function (error, result) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds', function (done) {
|
2016-04-04 16:40:47 +02:00
|
|
|
user.get(userObject.id, function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
2016-04-04 16:40:47 +02:00
|
|
|
expect(result.id).to.equal(userObject.id);
|
2016-04-13 12:15:49 +02:00
|
|
|
expect(result.email).to.equal(EMAIL.toLowerCase());
|
2016-09-27 15:03:10 +02:00
|
|
|
expect(result.alternativeEmail).not.to.be.ok();
|
2016-04-13 12:15:49 +02:00
|
|
|
expect(result.username).to.equal(USERNAME.toLowerCase());
|
2016-01-25 14:08:35 +01:00
|
|
|
expect(result.displayName).to.equal(DISPLAY_NAME);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-09-27 15:03:10 +02:00
|
|
|
|
|
|
|
|
it('succeeds with email enabled', function (done) {
|
|
|
|
|
// user settingsdb instead of settings, to not trigger further events
|
|
|
|
|
settingsdb.set(settings.MAIL_CONFIG_KEY, JSON.stringify({ enabled: true }), function (error) {
|
|
|
|
|
expect(error).not.to.be.ok();
|
|
|
|
|
|
|
|
|
|
user.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(USERNAME.toLowerCase() + '@' + config.fqdn());
|
|
|
|
|
expect(result.alternativeEmail).to.equal(EMAIL.toLowerCase());
|
|
|
|
|
expect(result.username).to.equal(USERNAME.toLowerCase());
|
|
|
|
|
expect(result.displayName).to.equal(DISPLAY_NAME);
|
|
|
|
|
|
|
|
|
|
settingsdb.set(settings.MAIL_CONFIG_KEY, JSON.stringify({ enabled: false }), done);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('update', function () {
|
2016-02-08 15:16:59 -08:00
|
|
|
before(createOwner);
|
2015-07-20 00:09:47 -07:00
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
|
|
|
|
it('fails due to unknown userid', function (done) {
|
2016-06-02 23:53:06 -07:00
|
|
|
var data = { username: USERNAME_NEW, email: EMAIL_NEW, displayName: DISPLAY_NAME_NEW };
|
|
|
|
|
user.update(USERNAME, data, AUDIT_SOURCE, function (error) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.a(UserError);
|
|
|
|
|
expect(error.reason).to.equal(UserError.NOT_FOUND);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to invalid email', function (done) {
|
2016-06-02 23:53:06 -07:00
|
|
|
var data = { username: USERNAME_NEW, email: 'brokenemailaddress', displayName: DISPLAY_NAME_NEW };
|
|
|
|
|
user.update(userObject.id, data, AUDIT_SOURCE, function (error) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.a(UserError);
|
2016-06-02 00:06:54 -07:00
|
|
|
expect(error.reason).to.equal(UserError.BAD_FIELD);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds', function (done) {
|
2016-06-02 23:53:06 -07:00
|
|
|
var data = { username: USERNAME_NEW, email: EMAIL_NEW, displayName: DISPLAY_NAME_NEW };
|
|
|
|
|
|
|
|
|
|
user.update(userObject.id, data, AUDIT_SOURCE, function (error) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
2016-04-04 16:40:47 +02:00
|
|
|
user.get(userObject.id, function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
2016-04-13 12:15:49 +02:00
|
|
|
expect(result.email).to.equal(EMAIL_NEW.toLowerCase());
|
|
|
|
|
expect(result.username).to.equal(USERNAME_NEW.toLowerCase());
|
2016-01-25 14:08:35 +01:00
|
|
|
expect(result.displayName).to.equal(DISPLAY_NAME_NEW);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-01-25 14:58:02 +01:00
|
|
|
|
|
|
|
|
it('succeeds with same data', function (done) {
|
2016-06-02 23:53:06 -07:00
|
|
|
var data = { username: USERNAME_NEW, email: EMAIL_NEW, displayName: DISPLAY_NAME_NEW };
|
|
|
|
|
|
|
|
|
|
user.update(userObject.id, data, AUDIT_SOURCE, function (error) {
|
2016-01-25 14:58:02 +01:00
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
2016-04-04 16:40:47 +02:00
|
|
|
user.get(userObject.id, function (error, result) {
|
2016-01-25 14:58:02 +01:00
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
2016-04-13 12:15:49 +02:00
|
|
|
expect(result.email).to.equal(EMAIL_NEW.toLowerCase());
|
|
|
|
|
expect(result.username).to.equal(USERNAME_NEW.toLowerCase());
|
2016-01-25 14:58:02 +01:00
|
|
|
expect(result.displayName).to.equal(DISPLAY_NAME_NEW);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-09-25 23:58:17 -07:00
|
|
|
|
|
|
|
|
it('updated the mailbox', function (done) {
|
|
|
|
|
mailboxdb.getMailbox(USERNAME, function (error) {
|
|
|
|
|
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
|
|
|
|
|
|
|
|
|
|
mailboxdb.getMailbox(USERNAME_NEW.toLowerCase(), function (error, mailbox) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(mailbox.ownerId).to.be(userObject.id);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
2016-03-09 06:18:39 +01:00
|
|
|
describe('admin change triggers mail', function () {
|
2016-02-08 15:16:59 -08:00
|
|
|
before(createOwner);
|
2015-07-20 00:09:47 -07:00
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
2016-05-04 13:54:32 +02:00
|
|
|
var user1 = {
|
|
|
|
|
username: 'seconduser',
|
|
|
|
|
password: 'ASDFkljsf#$^%2354',
|
|
|
|
|
email: 'some@thi.ng'
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
it('make second user admin succeeds', function (done) {
|
|
|
|
|
|
2016-02-08 21:05:02 -08:00
|
|
|
var invitor = { username: USERNAME, email: EMAIL };
|
2016-05-01 20:01:34 -07:00
|
|
|
user.create(user1.username, user1.password, user1.email, DISPLAY_NAME, AUDIT_SOURCE, { invitor: invitor }, function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
|
2016-04-04 16:40:47 +02:00
|
|
|
user1.id = result.id;
|
|
|
|
|
|
2016-09-20 15:07:11 -07:00
|
|
|
user.setGroups(user1.id, [ constants.ADMIN_GROUP_ID ], function (error) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.not.be.ok();
|
2016-01-18 14:19:20 +01:00
|
|
|
|
2016-01-18 16:11:00 +01:00
|
|
|
// one mail for user creation, one mail for admin change
|
2016-05-04 13:54:32 +02:00
|
|
|
checkMails(2, done);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-05-04 13:54:32 +02:00
|
|
|
it('add user to non admin group does not trigger admin mail', function (done) {
|
2016-09-20 15:07:11 -07:00
|
|
|
user.setGroups(user1.id, [ constants.ADMIN_GROUP_ID, NON_ADMIN_GROUP ], function (error) {
|
2016-05-04 13:54:32 +02:00
|
|
|
expect(error).to.equal(null);
|
|
|
|
|
|
|
|
|
|
checkMails(0, done);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds to remove admin flag', function (done) {
|
|
|
|
|
user.setGroups(user1.id, [ NON_ADMIN_GROUP ], function (error) {
|
2016-02-11 11:05:31 +01:00
|
|
|
expect(error).to.eql(null);
|
2016-05-04 13:54:32 +02:00
|
|
|
|
2016-01-18 14:19:20 +01:00
|
|
|
checkMails(1, done);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-01-15 16:12:45 +01:00
|
|
|
describe('get admins', function () {
|
2016-02-08 15:16:59 -08:00
|
|
|
before(createOwner);
|
2016-01-15 16:12:45 +01:00
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
|
|
|
|
it('succeeds for one admins', function (done) {
|
|
|
|
|
user.getAllAdmins(function (error, admins) {
|
|
|
|
|
expect(error).to.eql(null);
|
|
|
|
|
expect(admins.length).to.equal(1);
|
2016-04-13 12:15:49 +02:00
|
|
|
expect(admins[0].username).to.equal(USERNAME.toLowerCase());
|
2016-01-15 16:12:45 +01:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds for two admins', function (done) {
|
|
|
|
|
var user1 = {
|
|
|
|
|
username: 'seconduser',
|
2016-01-20 14:50:06 +01:00
|
|
|
password: 'Adfasdkjf#$%43',
|
2016-01-15 16:12:45 +01:00
|
|
|
email: 'some@thi.ng'
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-08 21:05:02 -08:00
|
|
|
var invitor = { username: USERNAME, email: EMAIL };
|
2016-05-01 20:01:34 -07:00
|
|
|
user.create(user1.username, user1.password, user1.email, DISPLAY_NAME, AUDIT_SOURCE, { invitor: invitor }, function (error, result) {
|
2016-01-15 16:12:45 +01:00
|
|
|
expect(error).to.eql(null);
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
|
2016-04-04 16:40:47 +02:00
|
|
|
user1.id = result.id;
|
|
|
|
|
|
2016-09-20 15:07:11 -07:00
|
|
|
groups.setGroups(user1.id, [ constants.ADMIN_GROUP_ID ], function (error) {
|
2016-01-15 16:12:45 +01:00
|
|
|
expect(error).to.eql(null);
|
|
|
|
|
|
|
|
|
|
user.getAllAdmins(function (error, admins) {
|
|
|
|
|
expect(error).to.eql(null);
|
|
|
|
|
expect(admins.length).to.equal(2);
|
2016-04-13 12:15:49 +02:00
|
|
|
expect(admins[0].username).to.equal(USERNAME.toLowerCase());
|
|
|
|
|
expect(admins[1].username).to.equal(user1.username.toLowerCase());
|
2016-01-18 14:19:20 +01:00
|
|
|
|
2016-01-18 16:11:00 +01:00
|
|
|
// one mail for user creation one mail for admin change
|
2016-02-11 11:05:31 +01:00
|
|
|
checkMails(1, done); // FIXME should be 2 for admin change
|
2016-01-15 16:12:45 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-06-07 09:59:29 -07:00
|
|
|
|
|
|
|
|
describe('count', function () {
|
|
|
|
|
before(createOwner);
|
|
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
|
|
|
|
it('succeeds', function (done) {
|
|
|
|
|
user.count(function (error, count) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(count).to.be(1);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-01-15 16:12:45 +01:00
|
|
|
|
2016-09-26 00:06:26 -07:00
|
|
|
describe('aliases', function () {
|
|
|
|
|
before(createOwner);
|
|
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
2016-09-26 00:20:47 -07:00
|
|
|
it('cannot set invalid alias', function (done) {
|
|
|
|
|
user.setAliases(userObject.id, [ 'a$scii' ], function (error) {
|
|
|
|
|
expect(error.reason).to.be(UserError.BAD_FIELD);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-09-26 00:06:26 -07:00
|
|
|
it('can set aliases', function (done) {
|
|
|
|
|
user.setAliases(userObject.id, [ 'everything', 'is', 'awesome' ], function (error) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('get get aliases', function (done) {
|
|
|
|
|
user.getAliases(userObject.id, function (error, aliases) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(aliases.length).to.be(3);
|
|
|
|
|
expect(aliases[0]).to.be('awesome');
|
|
|
|
|
expect(aliases[1]).to.be('everything');
|
|
|
|
|
expect(aliases[2]).to.be('is');
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot create user with username conflicting with existing alias', function (done) {
|
|
|
|
|
user.create('awesome', PASSWORD, 'test@test.com', DISPLAY_NAME, AUDIT_SOURCE, function (error) {
|
|
|
|
|
expect(error.reason).to.be(UserError.ALREADY_EXISTS);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-04-17 19:17:01 +02:00
|
|
|
describe('set password', function () {
|
2016-02-08 15:16:59 -08:00
|
|
|
before(createOwner);
|
2015-07-20 00:09:47 -07:00
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
2016-04-17 19:17:01 +02:00
|
|
|
it('fails due to unknown user', function (done) {
|
|
|
|
|
user.setPassword('doesnotexist', NEW_PASSWORD, function (error) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-04-17 19:17:01 +02:00
|
|
|
it('fails due to empty password', function (done) {
|
|
|
|
|
user.setPassword(userObject.id, '', function (error) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-04-17 19:17:01 +02:00
|
|
|
it('fails due to invalid password', function (done) {
|
|
|
|
|
user.setPassword(userObject.id, 'foobar', function (error) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds', function (done) {
|
2016-04-17 19:17:01 +02:00
|
|
|
user.setPassword(userObject.id, NEW_PASSWORD, function (error) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('actually changed the password (unable to login with old pasword)', function (done) {
|
2016-04-17 19:17:01 +02:00
|
|
|
user.verify(userObject.id, PASSWORD, function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.WRONG_PASSWORD);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('actually changed the password (login with new password)', function (done) {
|
2016-04-17 19:17:01 +02:00
|
|
|
user.verify(userObject.id, NEW_PASSWORD, function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('resetPasswordByIdentifier', function () {
|
2016-02-08 15:16:59 -08:00
|
|
|
before(createOwner);
|
2015-07-20 00:09:47 -07:00
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
|
|
|
|
it('fails due to unkown email', function (done) {
|
|
|
|
|
user.resetPasswordByIdentifier('unknown@mail.com', function (error) {
|
|
|
|
|
expect(error).to.be.an(UserError);
|
|
|
|
|
expect(error.reason).to.eql(UserError.NOT_FOUND);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to unkown username', function (done) {
|
|
|
|
|
user.resetPasswordByIdentifier('unknown', function (error) {
|
|
|
|
|
expect(error).to.be.an(UserError);
|
|
|
|
|
expect(error.reason).to.eql(UserError.NOT_FOUND);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds with email', function (done) {
|
|
|
|
|
user.resetPasswordByIdentifier(EMAIL, function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
2016-01-18 14:19:20 +01:00
|
|
|
checkMails(1, done);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds with username', function (done) {
|
|
|
|
|
user.resetPasswordByIdentifier(USERNAME, function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
2016-01-18 14:19:20 +01:00
|
|
|
checkMails(1, done);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-01-18 15:16:18 +01:00
|
|
|
|
|
|
|
|
describe('send invite', function () {
|
2016-02-08 15:16:59 -08:00
|
|
|
before(createOwner);
|
2016-01-18 15:16:18 +01:00
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
|
|
|
|
it('fails for unknown user', function (done) {
|
|
|
|
|
user.sendInvite('unknown user', function (error) {
|
|
|
|
|
expect(error).to.be.a(UserError);
|
|
|
|
|
expect(error.reason).to.equal(UserError.NOT_FOUND);
|
|
|
|
|
|
|
|
|
|
checkMails(0, done);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds', function (done) {
|
|
|
|
|
user.sendInvite(userObject.id, function (error) {
|
|
|
|
|
expect(error).to.eql(null);
|
2016-01-18 16:11:00 +01:00
|
|
|
checkMails(1, done);
|
2016-01-18 15:16:18 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-06-02 22:25:48 -07:00
|
|
|
|
|
|
|
|
describe('remove', function () {
|
|
|
|
|
before(createOwner);
|
|
|
|
|
after(cleanupUsers);
|
|
|
|
|
|
|
|
|
|
it('fails for unkown user', function (done) {
|
|
|
|
|
user.remove('unknown', { }, function (error) {
|
|
|
|
|
expect(error.reason).to.be(UserError.NOT_FOUND);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-09-26 00:14:03 -07:00
|
|
|
it('can set aliases', function (done) {
|
|
|
|
|
user.setAliases(userObject.id, [ 'everything', 'is', 'awesome' ], function (error) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
|
2016-09-26 14:02:23 -07:00
|
|
|
mailboxdb.getAliasesForName(USERNAME.toLowerCase(), function (error, results) {
|
2016-09-26 00:14:03 -07:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(results.length).to.be(3);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-02 22:25:48 -07:00
|
|
|
it('can remove valid user', function (done) {
|
|
|
|
|
user.remove(userObject.id, { }, function (error) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-09-25 23:54:27 -07:00
|
|
|
|
2016-09-26 00:14:03 -07:00
|
|
|
it('did delete mailbox and aliases', function (done) {
|
2016-09-25 23:54:27 -07:00
|
|
|
mailboxdb.getMailbox(userObject.username.toLowerCase(), function (error, mailbox) {
|
|
|
|
|
expect(error.reason).to.be(DatabaseError.NOT_FOUND);
|
2016-09-26 00:14:03 -07:00
|
|
|
|
2016-09-26 14:02:23 -07:00
|
|
|
mailboxdb.getAliasesForName(USERNAME.toLowerCase(), function (error, results) {
|
2016-09-26 00:14:03 -07:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(results.length).to.be(0);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-09-25 23:54:27 -07:00
|
|
|
});
|
|
|
|
|
});
|
2016-06-02 22:25:48 -07:00
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|