You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
533 lines
15 KiB
JavaScript
533 lines
15 KiB
JavaScript
8 years ago
|
'use strict';
|
||
8 years ago
|
|
||
8 years ago
|
|
||
4 years ago
|
const assert = require('assert');
|
||
4 years ago
|
const url = require('url');
|
||
4 years ago
|
const async = require('async');
|
||
|
const nconf = require('nconf');
|
||
|
const request = require('request');
|
||
4 years ago
|
const util = require('util');
|
||
8 years ago
|
|
||
4 years ago
|
const db = require('./mocks/databasemock');
|
||
|
const user = require('../src/user');
|
||
|
const utils = require('../src/utils');
|
||
|
const meta = require('../src/meta');
|
||
|
const privileges = require('../src/privileges');
|
||
|
const helpers = require('./helpers');
|
||
8 years ago
|
|
||
4 years ago
|
describe('authentication', () => {
|
||
4 years ago
|
const jar = request.jar();
|
||
|
let regularUid;
|
||
4 years ago
|
before((done) => {
|
||
|
user.create({ username: 'regular', password: 'regularpwd', email: '[email protected]' }, (err, uid) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
8 years ago
|
regularUid = uid;
|
||
3 years ago
|
assert.strictEqual(uid, 1);
|
||
8 years ago
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
3 years ago
|
it('should allow login with email for uid 1', async () => {
|
||
|
const oldValue = meta.config.allowLoginWith;
|
||
3 years ago
|
meta.config.allowLoginWith = 'username-email';
|
||
3 years ago
|
const { res } = await helpers.loginUser('[email protected]', 'regularpwd');
|
||
|
assert.strictEqual(res.statusCode, 200);
|
||
|
meta.config.allowLoginWith = oldValue;
|
||
|
});
|
||
|
|
||
|
it('second user should fail to login with email since email is not confirmed', async () => {
|
||
|
const oldValue = meta.config.allowLoginWith;
|
||
3 years ago
|
meta.config.allowLoginWith = 'username-email';
|
||
3 years ago
|
const uid = await user.create({ username: '2nduser', password: '2ndpassword', email: '[email protected]' });
|
||
|
const { res, body } = await helpers.loginUser('[email protected]', '2ndpassword');
|
||
|
assert.strictEqual(res.statusCode, 403);
|
||
|
assert.strictEqual(body, '[[error:invalid-login-credentials]]');
|
||
|
meta.config.allowLoginWith = oldValue;
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to create user if username is too short', (done) => {
|
||
7 years ago
|
helpers.registerUser({
|
||
|
username: 'a',
|
||
|
password: '123456',
|
||
4 years ago
|
}, (err, jar, response, body) => {
|
||
7 years ago
|
assert.ifError(err);
|
||
|
assert.equal(response.statusCode, 400);
|
||
|
assert.equal(body, '[[error:username-too-short]]');
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to create user if userslug is too short', (done) => {
|
||
7 years ago
|
helpers.registerUser({
|
||
|
username: '----a-----',
|
||
|
password: '123456',
|
||
4 years ago
|
}, (err, jar, response, body) => {
|
||
7 years ago
|
assert.ifError(err);
|
||
|
assert.equal(response.statusCode, 400);
|
||
|
assert.equal(body, '[[error:username-too-short]]');
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to create user if userslug is too short', (done) => {
|
||
7 years ago
|
helpers.registerUser({
|
||
|
username: ' a',
|
||
|
password: '123456',
|
||
4 years ago
|
}, (err, jar, response, body) => {
|
||
7 years ago
|
assert.ifError(err);
|
||
|
assert.equal(response.statusCode, 400);
|
||
|
assert.equal(body, '[[error:username-too-short]]');
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to create user if userslug is too short', (done) => {
|
||
7 years ago
|
helpers.registerUser({
|
||
|
username: 'a ',
|
||
|
password: '123456',
|
||
4 years ago
|
}, (err, jar, response, body) => {
|
||
7 years ago
|
assert.ifError(err);
|
||
|
assert.equal(response.statusCode, 400);
|
||
|
assert.equal(body, '[[error:username-too-short]]');
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should register and login a user', (done) => {
|
||
8 years ago
|
request({
|
||
4 years ago
|
url: `${nconf.get('url')}/api/config`,
|
||
8 years ago
|
json: true,
|
||
8 years ago
|
jar: jar,
|
||
4 years ago
|
}, (err, response, body) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
|
||
4 years ago
|
request.post(`${nconf.get('url')}/register`, {
|
||
8 years ago
|
form: {
|
||
|
email: '[email protected]',
|
||
|
username: 'admin',
|
||
|
password: 'adminpwd',
|
||
8 years ago
|
'password-confirm': 'adminpwd',
|
||
8 years ago
|
userLang: 'it',
|
||
7 years ago
|
gdpr_consent: true,
|
||
8 years ago
|
},
|
||
|
json: true,
|
||
|
jar: jar,
|
||
|
headers: {
|
||
8 years ago
|
'x-csrf-token': body.csrf_token,
|
||
|
},
|
||
4 years ago
|
}, (err, response, body) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
assert(body);
|
||
|
|
||
|
request({
|
||
4 years ago
|
url: `${nconf.get('url')}/api/self`,
|
||
8 years ago
|
json: true,
|
||
8 years ago
|
jar: jar,
|
||
4 years ago
|
}, (err, response, body) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
assert(body);
|
||
|
assert.equal(body.username, 'admin');
|
||
|
assert.equal(body.email, '[email protected]');
|
||
4 years ago
|
user.getSettings(body.uid, (err, settings) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
assert.equal(settings.userLang, 'it');
|
||
|
done();
|
||
|
});
|
||
8 years ago
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should logout a user', (done) => {
|
||
|
helpers.logoutUser(jar, (err) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
8 years ago
|
request({
|
||
4 years ago
|
url: `${nconf.get('url')}/api/me`,
|
||
8 years ago
|
json: true,
|
||
|
jar: jar,
|
||
4 years ago
|
}, (err, res, body) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
7 years ago
|
assert.equal(res.statusCode, 401);
|
||
4 years ago
|
assert.strictEqual(body.status.code, 'not-authorised');
|
||
8 years ago
|
done();
|
||
8 years ago
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should login a user', (done) => {
|
||
3 years ago
|
helpers.loginUser('regular', 'regularpwd', (err, data) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
3 years ago
|
assert(data.body);
|
||
8 years ago
|
request({
|
||
4 years ago
|
url: `${nconf.get('url')}/api/self`,
|
||
8 years ago
|
json: true,
|
||
3 years ago
|
jar: data.jar,
|
||
4 years ago
|
}, (err, response, body) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
assert(body);
|
||
8 years ago
|
assert.equal(body.username, 'regular');
|
||
|
assert.equal(body.email, '[email protected]');
|
||
4 years ago
|
db.getObject(`uid:${regularUid}:sessionUUID:sessionId`, (err, sessions) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
8 years ago
|
assert(sessions);
|
||
|
assert(Object.keys(sessions).length > 0);
|
||
|
done();
|
||
8 years ago
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should regenerate the session identifier on successful login', async () => {
|
||
|
const matchRegexp = /express\.sid=s%3A(.+?);/;
|
||
4 years ago
|
const { hostname, path } = url.parse(nconf.get('url'));
|
||
4 years ago
|
|
||
4 years ago
|
const sid = String(jar._jar.store.idx[hostname][path]['express.sid']).match(matchRegexp)[1];
|
||
3 years ago
|
await helpers.logoutUser(jar);
|
||
|
const newJar = (await helpers.loginUser('regular', 'regularpwd')).jar;
|
||
4 years ago
|
const newSid = String(newJar._jar.store.idx[hostname][path]['express.sid']).match(matchRegexp)[1];
|
||
4 years ago
|
|
||
|
assert.notStrictEqual(newSid, sid);
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should revoke all sessions', (done) => {
|
||
4 years ago
|
const socketAdmin = require('../src/socket.io/admin');
|
||
4 years ago
|
db.sortedSetCard(`uid:${regularUid}:sessions`, (err, count) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
assert(count);
|
||
4 years ago
|
socketAdmin.deleteAllSessions({ uid: 1 }, {}, (err) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
4 years ago
|
db.sortedSetCard(`uid:${regularUid}:sessions`, (err, count) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
assert(!count);
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to login if ip address is invalid', (done) => {
|
||
4 years ago
|
const jar = request.jar();
|
||
7 years ago
|
request({
|
||
4 years ago
|
url: `${nconf.get('url')}/api/config`,
|
||
7 years ago
|
json: true,
|
||
|
jar: jar,
|
||
4 years ago
|
}, (err, response, body) => {
|
||
7 years ago
|
if (err) {
|
||
|
return done(err);
|
||
|
}
|
||
|
|
||
4 years ago
|
request.post(`${nconf.get('url')}/login`, {
|
||
7 years ago
|
form: {
|
||
|
username: 'regular',
|
||
|
password: 'regularpwd',
|
||
|
},
|
||
|
json: true,
|
||
|
jar: jar,
|
||
|
headers: {
|
||
|
'x-csrf-token': body.csrf_token,
|
||
|
'x-forwarded-for': '<script>alert("xss")</script>',
|
||
|
},
|
||
4 years ago
|
}, (err, response, body) => {
|
||
7 years ago
|
assert.ifError(err);
|
||
|
assert.equal(response.statusCode, 500);
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to login if user does not exist', (done) => {
|
||
3 years ago
|
helpers.loginUser('doesnotexist', 'nopassword', (err, data) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
3 years ago
|
assert.equal(data.res.statusCode, 403);
|
||
|
assert.equal(data.body, '[[error:invalid-login-credentials]]');
|
||
8 years ago
|
done();
|
||
|
});
|
||
|
});
|
||
8 years ago
|
|
||
4 years ago
|
it('should fail to login if username is empty', (done) => {
|
||
3 years ago
|
helpers.loginUser('', 'some password', (err, data) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
3 years ago
|
assert.equal(data.res.statusCode, 403);
|
||
|
assert.equal(data.body, '[[error:invalid-username-or-password]]');
|
||
8 years ago
|
done();
|
||
8 years ago
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to login if password is empty', (done) => {
|
||
3 years ago
|
helpers.loginUser('someuser', '', (err, data) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
3 years ago
|
assert.equal(data.res.statusCode, 403);
|
||
|
assert.equal(data.body, '[[error:invalid-username-or-password]]');
|
||
8 years ago
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to login if username and password are empty', (done) => {
|
||
3 years ago
|
helpers.loginUser('', '', (err, data) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
3 years ago
|
assert.equal(data.res.statusCode, 403);
|
||
|
assert.equal(data.body, '[[error:invalid-username-or-password]]');
|
||
8 years ago
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to login if user does not have password field in db', (done) => {
|
||
|
user.create({ username: 'hasnopassword', email: '[email protected]' }, (err, uid) => {
|
||
6 years ago
|
assert.ifError(err);
|
||
3 years ago
|
helpers.loginUser('hasnopassword', 'doesntmatter', (err, data) => {
|
||
6 years ago
|
assert.ifError(err);
|
||
3 years ago
|
assert.equal(data.res.statusCode, 403);
|
||
|
assert.equal(data.body, '[[error:invalid-login-credentials]]');
|
||
6 years ago
|
done();
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to login if password is longer than 4096', (done) => {
|
||
4 years ago
|
let longPassword;
|
||
|
for (let i = 0; i < 5000; i++) {
|
||
8 years ago
|
longPassword += 'a';
|
||
|
}
|
||
3 years ago
|
helpers.loginUser('someuser', longPassword, (err, data) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
3 years ago
|
assert.equal(data.res.statusCode, 403);
|
||
|
assert.equal(data.body, '[[error:password-too-long]]');
|
||
8 years ago
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to login if local login is disabled', (done) => {
|
||
|
privileges.global.rescind(['groups:local:login'], 'registered-users', (err) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
3 years ago
|
helpers.loginUser('regular', 'regularpwd', (err, data) => {
|
||
6 years ago
|
assert.ifError(err);
|
||
3 years ago
|
assert.equal(data.res.statusCode, 403);
|
||
|
assert.equal(data.body, '[[error:local-login-disabled]]');
|
||
5 years ago
|
privileges.global.give(['groups:local:login'], 'registered-users', done);
|
||
6 years ago
|
});
|
||
8 years ago
|
});
|
||
|
});
|
||
8 years ago
|
|
||
4 years ago
|
it('should fail to register if registraton is disabled', (done) => {
|
||
8 years ago
|
meta.config.registrationType = 'disabled';
|
||
4 years ago
|
helpers.registerUser({
|
||
|
username: 'someuser',
|
||
|
password: 'somepassword',
|
||
|
}, (err, jar, response, body) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
assert.equal(response.statusCode, 403);
|
||
|
assert.equal(body, 'Forbidden');
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should return error if invitation is not valid', (done) => {
|
||
8 years ago
|
meta.config.registrationType = 'invite-only';
|
||
4 years ago
|
helpers.registerUser({
|
||
|
username: 'someuser',
|
||
|
password: 'somepassword',
|
||
|
}, (err, jar, response, body) => {
|
||
8 years ago
|
meta.config.registrationType = 'normal';
|
||
|
assert.ifError(err);
|
||
|
assert.equal(response.statusCode, 400);
|
||
4 years ago
|
assert.equal(body, '[[register:invite.error-invite-only]]');
|
||
8 years ago
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to register if username is falsy or too short', (done) => {
|
||
4 years ago
|
helpers.registerUser({
|
||
|
username: '',
|
||
|
password: 'somepassword',
|
||
|
}, (err, jar, response, body) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
assert.equal(response.statusCode, 400);
|
||
|
assert.equal(body, '[[error:username-too-short]]');
|
||
4 years ago
|
helpers.registerUser({
|
||
|
username: 'a',
|
||
|
password: 'somepassword',
|
||
|
}, (err, jar, response, body) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
assert.equal(response.statusCode, 400);
|
||
|
assert.equal(body, '[[error:username-too-short]]');
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should fail to register if username is too long', (done) => {
|
||
4 years ago
|
helpers.registerUser({
|
||
|
username: 'thisisareallylongusername',
|
||
|
password: '123456',
|
||
|
}, (err, jar, response, body) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
assert.equal(response.statusCode, 400);
|
||
|
assert.equal(body, '[[error:username-too-long]]');
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should queue user if ip is used before', (done) => {
|
||
6 years ago
|
meta.config.registrationApprovalType = 'admin-approval-ip';
|
||
4 years ago
|
helpers.registerUser({
|
||
|
email: '[email protected]',
|
||
|
username: 'anotheruser',
|
||
|
password: 'anotherpwd',
|
||
|
gdpr_consent: 1,
|
||
|
}, (err, jar, response, body) => {
|
||
6 years ago
|
meta.config.registrationApprovalType = 'normal';
|
||
8 years ago
|
assert.ifError(err);
|
||
|
assert.equal(response.statusCode, 200);
|
||
|
assert.equal(body.message, '[[register:registration-added-to-queue]]');
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
|
||
4 years ago
|
it('should be able to login with email', async () => {
|
||
|
const uid = await user.create({ username: 'ginger', password: '123456', email: '[email protected]' });
|
||
|
await user.email.confirmByUid(uid);
|
||
3 years ago
|
const { res } = await helpers.loginUser('[email protected]', '123456');
|
||
|
assert.equal(res.statusCode, 200);
|
||
8 years ago
|
});
|
||
|
|
||
4 years ago
|
it('should fail to login if login type is username and an email is sent', (done) => {
|
||
8 years ago
|
meta.config.allowLoginWith = 'username';
|
||
3 years ago
|
helpers.loginUser('[email protected]', '123456', (err, data) => {
|
||
8 years ago
|
meta.config.allowLoginWith = 'username-email';
|
||
|
assert.ifError(err);
|
||
3 years ago
|
assert.equal(data.res.statusCode, 400);
|
||
|
assert.equal(data.body, '[[error:wrong-login-type-username]]');
|
||
8 years ago
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should send 200 if not logged in', (done) => {
|
||
4 years ago
|
const jar = request.jar();
|
||
8 years ago
|
request({
|
||
4 years ago
|
url: `${nconf.get('url')}/api/config`,
|
||
8 years ago
|
json: true,
|
||
|
jar: jar,
|
||
4 years ago
|
}, (err, response, body) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
|
||
4 years ago
|
request.post(`${nconf.get('url')}/logout`, {
|
||
8 years ago
|
form: {},
|
||
|
json: true,
|
||
|
jar: jar,
|
||
|
headers: {
|
||
|
'x-csrf-token': body.csrf_token,
|
||
|
},
|
||
4 years ago
|
}, (err, res, body) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
|
assert.equal(res.statusCode, 200);
|
||
|
assert.equal(body, 'not-logged-in');
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
4 years ago
|
describe('banned user authentication', () => {
|
||
4 years ago
|
const bannedUser = {
|
||
|
username: 'banme',
|
||
|
pw: '123456',
|
||
|
uid: null,
|
||
|
};
|
||
|
|
||
4 years ago
|
before(async () => {
|
||
4 years ago
|
bannedUser.uid = await user.create({ username: 'banme', password: '123456', email: '[email protected]' });
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should prevent banned user from logging in', (done) => {
|
||
|
user.bans.ban(bannedUser.uid, 0, 'spammer', (err) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
3 years ago
|
helpers.loginUser(bannedUser.username, bannedUser.pw, (err, data) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
3 years ago
|
assert.equal(data.res.statusCode, 403);
|
||
|
delete data.body.timestamp;
|
||
|
assert.deepStrictEqual(data.body, {
|
||
3 years ago
|
banned_until: 0,
|
||
|
banned_until_readable: '',
|
||
|
expiry: 0,
|
||
|
expiry_readable: '',
|
||
|
reason: 'spammer',
|
||
3 years ago
|
uid: bannedUser.uid,
|
||
3 years ago
|
});
|
||
4 years ago
|
user.bans.unban(bannedUser.uid, (err) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
4 years ago
|
const expiry = Date.now() + 10000;
|
||
4 years ago
|
user.bans.ban(bannedUser.uid, expiry, '', (err) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
3 years ago
|
helpers.loginUser(bannedUser.username, bannedUser.pw, (err, data) => {
|
||
8 years ago
|
assert.ifError(err);
|
||
3 years ago
|
assert.equal(data.res.statusCode, 403);
|
||
|
assert(data.body.banned_until);
|
||
|
assert(data.body.reason, '[[user:info.banned-no-reason]]');
|
||
8 years ago
|
done();
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|
||
4 years ago
|
|
||
4 years ago
|
it('should allow banned user to log in if the "banned-users" group has "local-login" privilege', async () => {
|
||
4 years ago
|
await privileges.global.give(['groups:local:login'], 'banned-users');
|
||
3 years ago
|
const { res } = await helpers.loginUser(bannedUser.username, bannedUser.pw);
|
||
4 years ago
|
assert.strictEqual(res.statusCode, 200);
|
||
|
});
|
||
|
|
||
4 years ago
|
it('should allow banned user to log in if the user herself has "local-login" privilege', async () => {
|
||
4 years ago
|
await privileges.global.rescind(['groups:local:login'], 'banned-users');
|
||
|
await privileges.categories.give(['local:login'], 0, bannedUser.uid);
|
||
3 years ago
|
const { res } = await helpers.loginUser(bannedUser.username, bannedUser.pw);
|
||
4 years ago
|
assert.strictEqual(res.statusCode, 200);
|
||
|
});
|
||
8 years ago
|
});
|
||
|
|
||
4 years ago
|
it('should lockout account on 3 failed login attempts', (done) => {
|
||
8 years ago
|
meta.config.loginAttempts = 3;
|
||
4 years ago
|
let uid;
|
||
8 years ago
|
async.waterfall([
|
||
|
function (next) {
|
||
|
user.create({ username: 'lockme', password: '123456' }, next);
|
||
|
},
|
||
|
function (_uid, next) {
|
||
|
uid = _uid;
|
||
3 years ago
|
helpers.loginUser('lockme', 'abcdef', next);
|
||
8 years ago
|
},
|
||
3 years ago
|
function (data, next) {
|
||
|
helpers.loginUser('lockme', 'abcdef', next);
|
||
8 years ago
|
},
|
||
3 years ago
|
function (data, next) {
|
||
|
helpers.loginUser('lockme', 'abcdef', next);
|
||
8 years ago
|
},
|
||
3 years ago
|
function (data, next) {
|
||
|
helpers.loginUser('lockme', 'abcdef', next);
|
||
8 years ago
|
},
|
||
3 years ago
|
function (data, next) {
|
||
8 years ago
|
meta.config.loginAttempts = 5;
|
||
3 years ago
|
assert.equal(data.res.statusCode, 403);
|
||
|
assert.equal(data.body, '[[error:account-locked]]');
|
||
|
helpers.loginUser('lockme', 'abcdef', next);
|
||
8 years ago
|
},
|
||
3 years ago
|
function (data, next) {
|
||
|
assert.equal(data.res.statusCode, 403);
|
||
|
assert.equal(data.body, '[[error:account-locked]]');
|
||
4 years ago
|
db.exists(`lockout:${uid}`, next);
|
||
8 years ago
|
},
|
||
|
function (locked, next) {
|
||
|
assert(locked);
|
||
|
next();
|
||
|
},
|
||
|
], done);
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should clear all reset tokens upon successful login', async () => {
|
||
|
const code = await user.reset.generate(regularUid);
|
||
3 years ago
|
await helpers.loginUser('regular', 'regularpwd');
|
||
4 years ago
|
const valid = await user.reset.validate(code);
|
||
|
assert.strictEqual(valid, false);
|
||
|
});
|
||
8 years ago
|
});
|