Release v2.5.6
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const registerAccountRoutes = require('../src/web/routes/admin/account');
|
||||
const { validatePasswordStrength } = require('../src/auth');
|
||||
|
||||
test('account password update redirects back to the account page', async () => {
|
||||
const handlers = {};
|
||||
const app = {
|
||||
post(path, ...routeHandlers) {
|
||||
handlers[path] = routeHandlers;
|
||||
},
|
||||
get() {}
|
||||
};
|
||||
|
||||
const deps = {
|
||||
pool: {
|
||||
async query(sql) {
|
||||
if (sql.includes('SELECT id, name, username, password_hash, password_salt, password_iterations FROM a_users WHERE id = ? LIMIT 1')) {
|
||||
return [[{ id: 5, password_hash: 'hash', password_salt: 'salt', password_iterations: 1 }]];
|
||||
}
|
||||
if (sql.includes('UPDATE a_users SET password_hash = ?, password_salt = ?, password_iterations = ?, modified_by = ? WHERE id = ?')) {
|
||||
return [{ affectedRows: 1 }];
|
||||
}
|
||||
if (sql.includes('DELETE FROM a_sessions WHERE user_id = ?')) {
|
||||
return [{ affectedRows: 1 }];
|
||||
}
|
||||
return [[]];
|
||||
}
|
||||
},
|
||||
common: {},
|
||||
pages: {},
|
||||
formatDashboardDate: () => '',
|
||||
getAuditUserId: () => 9,
|
||||
verifyPassword: () => true,
|
||||
validatePasswordStrength: validatePasswordStrength,
|
||||
hashPassword: () => ({ hash: 'new-hash', salt: 'new-salt', iterations: 2 }),
|
||||
createUserSession: async () => 'session-token',
|
||||
setSessionCookie: () => {}
|
||||
};
|
||||
|
||||
registerAccountRoutes(app, deps);
|
||||
|
||||
const routeHandlers = handlers['/account/password'];
|
||||
assert.equal(Array.isArray(routeHandlers), true);
|
||||
|
||||
const req = {
|
||||
body: {
|
||||
current_password: 'current-password',
|
||||
new_password: 'NewPassword!1',
|
||||
confirm_password: 'NewPassword!1'
|
||||
},
|
||||
currentUser: { id: 5 }
|
||||
};
|
||||
const res = {
|
||||
redirect(url) {
|
||||
this.redirectedTo = url;
|
||||
},
|
||||
status() {
|
||||
return this;
|
||||
},
|
||||
send() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
await routeHandlers[0](req, res, () => {});
|
||||
|
||||
assert.equal(res.redirectedTo, '/account?message=Password%20updated.');
|
||||
});
|
||||
Reference in New Issue
Block a user