Files
pulse-signage/test/admin-account-password-route.test.js
lzstealth ea72747822
Publish Docker Image / build-and-push-existing-registry (./build/Dockerfile, web, pulse-signage-web) (push) Successful in 1m12s
Publish Docker Image / build-and-push-existing-registry (./build/Dockerfile.player, player, pulse-signage-player) (push) Successful in 34s
Release 2.8.2
2026-08-16 22:41:39 +01:00

72 lines
2.0 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
require('../src/common');
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.');
});