Files
pulse-signage/test/admin-users-password-route.test.js
T
lzstealth 203d0bfc01
Publish Docker Image / build-and-push-existing-registry (./build/Dockerfile, web, pulse-signage-web) (push) Successful in 1m49s
Publish Docker Image / build-and-push-existing-registry (./build/Dockerfile.player, player, pulse-signage-player) (push) Successful in 32s
Release 2.8.0
2026-08-16 17:15:31 +01:00

78 lines
2.2 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const registerUsersRoutes = require('../src/web/routes/admin/users');
const { validatePasswordStrength } = require('../src/auth');
test('user password reset redirects back to the selected user edit page', async () => {
const handlers = {};
const app = {
post(path, ...routeHandlers) {
handlers[path] = routeHandlers;
},
get() {}
};
const deps = {
pool: {
async query(sql) {
if (sql.includes('SELECT id FROM a_users WHERE id = ? LIMIT 1')) {
return [[{ id: 7 }]];
}
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: {
fetchDuplicateName: async () => null
},
pages: {},
formatDashboardDate: () => '',
getAuditUserId: () => 3,
hashPassword: () => ({ hash: 'hash', salt: 'salt', iterations: 1 }),
validatePasswordStrength: validatePasswordStrength,
readArrayField: () => [],
rbacData: {
fetchRoles: async () => [],
fetchUsersWithRolesPage: async () => ({ users: [], totalItems: 0, currentPage: 1 }),
fetchUserWithRoles: async () => ({ id: 7, name: 'User', username: 'user', roleIds: [], inUse: false }),
syncUserRoles: async () => {}
},
requirePermission() {
return function (_req, _res, next) {
next();
};
}
};
registerUsersRoutes(app, deps);
const routeHandlers = handlers['/settings/users/:id/password'];
assert.equal(Array.isArray(routeHandlers), true);
const req = {
params: { id: '7' },
body: { password: 'NewPassword!1', confirm_password: 'NewPassword!1' },
currentUser: { id: 1 }
};
const res = {
redirect(url) {
this.redirectedTo = url;
},
status() {
return this;
},
send() {
return this;
}
};
await routeHandlers[1](req, res, () => {});
assert.equal(res.redirectedTo, '/settings/users/7/edit?message=Password%20updated.');
});