2015-07-20 00:09:47 -07:00
|
|
|
/* jslint node:true */
|
|
|
|
|
/* 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'),
|
|
|
|
|
database = require('../database.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
expect = require('expect.js'),
|
2016-02-08 16:53:20 -08:00
|
|
|
groupdb = require('../groupdb.js'),
|
|
|
|
|
groups = require('../groups.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'),
|
|
|
|
|
UserError = user.UserError;
|
|
|
|
|
|
|
|
|
|
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;
|
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,
|
|
|
|
|
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
|
|
|
|
|
user.createOwner(USERNAME, PASSWORD, EMAIL, DISPLAY_NAME, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
2016-01-18 15:16:18 +01:00
|
|
|
|
2016-02-08 16:53:20 -08:00
|
|
|
userObject = result;
|
2016-01-18 15:16:18 +01:00
|
|
|
|
2016-02-08 16:53:20 -08:00
|
|
|
done();
|
|
|
|
|
});
|
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-01-18 14:19:20 +01:00
|
|
|
function checkMails(number, done) {
|
|
|
|
|
// mails are enqueued async
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
expect(mailer._getMailQueue().length).to.equal(number);
|
|
|
|
|
mailer._clearMailQueue();
|
|
|
|
|
done();
|
|
|
|
|
}, 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-02-08 21:05:02 -08:00
|
|
|
user.create(USERNAME, 'Fo$%23', EMAIL, DISPLAY_NAME, function (error, result) {
|
2016-01-20 14:50:06 +01:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.BAD_PASSWORD);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to missing upper case password', function (done) {
|
2016-02-08 21:05:02 -08:00
|
|
|
user.create(USERNAME, 'thisiseightch%$234arslong', EMAIL, DISPLAY_NAME, function (error, result) {
|
2016-01-20 14:50:06 +01:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.BAD_PASSWORD);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to missing numerics in password', function (done) {
|
2016-02-08 21:05:02 -08:00
|
|
|
user.create(USERNAME, 'foobaRASDF%', EMAIL, DISPLAY_NAME, function (error, result) {
|
2016-01-20 14:50:06 +01:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.BAD_PASSWORD);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to missing special chars in password', function (done) {
|
2016-02-08 21:05:02 -08:00
|
|
|
user.create(USERNAME, 'foobaRASDF23423', EMAIL, DISPLAY_NAME, function (error, result) {
|
2016-01-20 14:50:06 +01:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(result).to.not.be.ok();
|
|
|
|
|
expect(error.reason).to.equal(UserError.BAD_PASSWORD);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-01-18 14:19:20 +01:00
|
|
|
it('succeeds and attempts to send invite', function (done) {
|
2016-02-08 21:05:02 -08:00
|
|
|
user.createOwner(USERNAME, PASSWORD, EMAIL, DISPLAY_NAME, function (error, result) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).not.to.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
expect(result.username).to.equal(USERNAME);
|
|
|
|
|
expect(result.email).to.equal(EMAIL);
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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-02-08 21:05:02 -08:00
|
|
|
user.create(USERNAME, PASSWORD, EMAIL, DISPLAY_NAME, 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-02-08 21:05:02 -08:00
|
|
|
user.create(USERNAME, '', EMAIL, DISPLAY_NAME, 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.BAD_PASSWORD);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
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);
|
|
|
|
|
expect(owner.email).to.be(EMAIL);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
it('fails due to non existing username', function (done) {
|
|
|
|
|
user.verify(USERNAME+USERNAME, 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(USERNAME, '', 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(USERNAME, 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(USERNAME, PASSWORD, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
user.get(USERNAME, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
2016-01-25 14:08:35 +01:00
|
|
|
expect(result.email).to.equal(EMAIL);
|
|
|
|
|
expect(result.username).to.equal(USERNAME);
|
|
|
|
|
expect(result.displayName).to.equal(DISPLAY_NAME);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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-01-25 14:08:35 +01:00
|
|
|
user.update(USERNAME+USERNAME, USERNAME_NEW, EMAIL_NEW, DISPLAY_NAME_NEW, 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 username', function (done) {
|
2016-01-25 14:08:35 +01:00
|
|
|
user.update(USERNAME, '', EMAIL_NEW, DISPLAY_NAME_NEW, function (error) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.a(UserError);
|
|
|
|
|
expect(error.reason).to.equal(UserError.BAD_USERNAME);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to invalid email', function (done) {
|
2016-01-25 14:08:35 +01:00
|
|
|
user.update(USERNAME, USERNAME_NEW, 'brokenemailaddress', DISPLAY_NAME_NEW, function (error) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.a(UserError);
|
|
|
|
|
expect(error.reason).to.equal(UserError.BAD_EMAIL);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds', function (done) {
|
2016-01-25 14:08:35 +01:00
|
|
|
user.update(USERNAME, USERNAME_NEW, EMAIL_NEW, DISPLAY_NAME_NEW, function (error) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
|
|
|
|
user.get(USERNAME, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
expect(result.email).to.equal(EMAIL_NEW);
|
|
|
|
|
expect(result.username).to.equal(USERNAME_NEW);
|
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) {
|
|
|
|
|
user.update(USERNAME, USERNAME_NEW, EMAIL_NEW, DISPLAY_NAME_NEW, function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
|
|
|
|
|
user.get(USERNAME, function (error, result) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
expect(result.email).to.equal(EMAIL_NEW);
|
|
|
|
|
expect(result.username).to.equal(USERNAME_NEW);
|
|
|
|
|
expect(result.displayName).to.equal(DISPLAY_NAME_NEW);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
it('make second user admin succeeds', function (done) {
|
|
|
|
|
var user1 = {
|
|
|
|
|
username: 'seconduser',
|
2016-01-20 14:50:06 +01:00
|
|
|
password: 'ASDFkljsf#$^%2354',
|
2015-07-20 00:09:47 -07:00
|
|
|
email: 'some@thi.ng'
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-08 21:05:02 -08:00
|
|
|
var invitor = { username: USERNAME, email: EMAIL };
|
|
|
|
|
user.create(user1.username, user1.password, user1.email, DISPLAY_NAME, { 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-02-11 11:05:31 +01:00
|
|
|
groups.setGroups(user1.username, [ groups.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-02-11 11:05:31 +01:00
|
|
|
checkMails(1, done);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-09 06:18:39 +01:00
|
|
|
xit('succeeds to remove admin flag of first user', function (done) {
|
2016-02-11 11:05:31 +01:00
|
|
|
groups.setGroups(USERNAME, [], function (error) {
|
|
|
|
|
expect(error).to.eql(null);
|
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);
|
|
|
|
|
expect(admins[0].username).to.equal(USERNAME);
|
|
|
|
|
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 };
|
|
|
|
|
user.create(user1.username, user1.password, user1.email, DISPLAY_NAME, { invitor: invitor }, function (error, result) {
|
2016-01-15 16:12:45 +01:00
|
|
|
expect(error).to.eql(null);
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
|
2016-02-11 11:05:31 +01:00
|
|
|
groups.setGroups(user1.username, [ groups.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);
|
|
|
|
|
expect(admins[0].username).to.equal(USERNAME);
|
|
|
|
|
expect(admins[1].username).to.equal(user1.username);
|
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
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
describe('password change', 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 wrong arumgent count', function () {
|
|
|
|
|
expect(function () { user.changePassword(); }).to.throwError();
|
|
|
|
|
expect(function () { user.changePassword(USERNAME); }).to.throwError();
|
|
|
|
|
expect(function () { user.changePassword(USERNAME, PASSWORD, NEW_PASSWORD); }).to.throwError();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to wrong arumgents', function () {
|
|
|
|
|
expect(function () { user.changePassword(USERNAME, {}, NEW_PASSWORD, function () {}); }).to.throwError();
|
|
|
|
|
expect(function () { user.changePassword(1337, PASSWORD, NEW_PASSWORD, function () {}); }).to.throwError();
|
|
|
|
|
expect(function () { user.changePassword(USERNAME, PASSWORD, 1337, function () {}); }).to.throwError();
|
|
|
|
|
expect(function () { user.changePassword(USERNAME, PASSWORD, NEW_PASSWORD, 'some string'); }).to.throwError();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to wrong password', function (done) {
|
|
|
|
|
user.changePassword(USERNAME, 'wrongpassword', NEW_PASSWORD, function (error) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to empty new password', function (done) {
|
|
|
|
|
user.changePassword(USERNAME, PASSWORD, '', function (error) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fails due to unknown user', function (done) {
|
|
|
|
|
user.changePassword('somerandomuser', PASSWORD, NEW_PASSWORD, function (error) {
|
|
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('succeeds', function (done) {
|
|
|
|
|
user.changePassword(USERNAME, PASSWORD, NEW_PASSWORD, function (error) {
|
|
|
|
|
expect(error).to.not.be.ok();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('actually changed the password (unable to login with old pasword)', function (done) {
|
|
|
|
|
user.verify(USERNAME, 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('actually changed the password (login with new password)', function (done) {
|
|
|
|
|
user.verify(USERNAME, NEW_PASSWORD, function (error, result) {
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|