mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: tests for password change
This commit is contained in:
@@ -105,10 +105,6 @@ winston.info('environment ' + global.env);
|
||||
const db = require('../../src/database');
|
||||
module.exports = db;
|
||||
|
||||
after(async function () {
|
||||
await db.flushdb();
|
||||
});
|
||||
|
||||
before(async function () {
|
||||
this.timeout(30000);
|
||||
await db.init();
|
||||
|
||||
26
test/user.js
26
test/user.js
@@ -824,6 +824,32 @@ describe('User', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not let user change another user\'s password', async function () {
|
||||
const regularUserUid = await User.create({ username: 'regularuserpwdchange', password: 'regularuser1234' });
|
||||
const uid = await User.create({ username: 'changeadminpwd1', password: '123456' });
|
||||
let err;
|
||||
try {
|
||||
await socketUser.changePassword({ uid: uid }, { uid: regularUserUid, newPassword: '654321', currentPassword: '123456' });
|
||||
} catch (_err) {
|
||||
err = _err;
|
||||
}
|
||||
assert.equal(err.message, '[[user:change_password_error_privileges]]');
|
||||
});
|
||||
|
||||
it('should not let user change admin\'s password', async function () {
|
||||
const adminUid = await User.create({ username: 'adminpwdchange', password: 'admin1234' });
|
||||
await groups.join('administrators', adminUid);
|
||||
const uid = await User.create({ username: 'changeadminpwd2', password: '123456' });
|
||||
|
||||
let err;
|
||||
try {
|
||||
await socketUser.changePassword({ uid: uid }, { uid: adminUid, newPassword: '654321', currentPassword: '123456' });
|
||||
} catch (_err) {
|
||||
err = _err;
|
||||
}
|
||||
assert.equal(err.message, '[[user:change_password_error_privileges]]');
|
||||
});
|
||||
|
||||
it('should change username', function (done) {
|
||||
socketUser.changeUsernameEmail({ uid: uid }, { uid: uid, username: 'updatedAgain', password: '123456' }, function (err) {
|
||||
assert.ifError(err);
|
||||
|
||||
Reference in New Issue
Block a user