Files
pulse-signage/test/audit-log-route.test.js
T
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

114 lines
4.0 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
require('../src/common');
const registerAuditLogRoutes = require('../src/web/routes/settings/audit-log');
test('audit log uses its own read permission and shared pagination partial', async () => {
const handlers = {};
const app = {
get(path, ...routeHandlers) {
handlers[path] = routeHandlers;
}
};
registerAuditLogRoutes(app, {
pool: {
async query(sql) {
if (String(sql).includes('FROM o_audit_events')) {
return [[
{
id: 1,
occurred_at: '2026-08-16T12:00:00.000Z',
category: 'authentication',
event_type: 'login.success',
target_label: 'newer',
details_json: JSON.stringify({
changes: {
content: {
from: { title: 'Same', body: { color: 'red', keep: 'same' } },
to: { title: 'Same', body: { color: 'blue', keep: 'same' } }
},
permissions: {
from: ['dashboard.read', 'screens.read'],
to: ['screens.read', 'playlists.read']
},
backgroundColor: {
from: null,
to: '#111111'
},
logoPath: {
from: '',
to: '/media/logo.png'
}
}
})
},
{
id: 2,
occurred_at: '2026-08-15T12:00:00.000Z',
category: 'authentication',
event_type: 'login.failed',
target_label: 'older',
details_json: null
}
]];
}
return [[]];
}
},
formatDashboardDate() {
return 'Aug 16, 2026';
}
});
assert.ok(handlers['/settings/audit-log']);
const request = {
currentUser: { id: 7, permissions: ['audit-log.read', 'audit-log.allow'] },
query: {}
};
let continued = false;
handlers['/settings/audit-log'][0](request, {}, function () {
continued = true;
});
assert.equal(continued, true);
const response = { send(value) { this.body = value; } };
await handlers['/settings/audit-log'][1](request, response, function (error) {
throw error;
});
assert.match(response.body, /Audit log/);
assert.ok(response.body.indexOf('>All categories</option>') < response.body.indexOf('>announcements</option>'));
assert.ok(response.body.indexOf('>announcements</option>') < response.body.indexOf('>api-sources</option>'));
assert.ok(response.body.indexOf('>api-sources</option>') < response.body.indexOf('>canvas-sizes</option>'));
assert.match(response.body, /table-pagination/);
assert.match(response.body, /data-local-datetime/);
assert.match(response.body, /audit-event-type-options/);
assert.match(response.body, /login\.success/);
assert.match(response.body, /content\.body\.color/);
assert.match(response.body, />red</);
assert.match(response.body, />blue</);
assert.doesNotMatch(response.body, /content\.body\.keep/);
assert.match(response.body, /permissions removed/);
assert.match(response.body, /permissions added/);
assert.match(response.body, /dashboard\.read/);
assert.match(response.body, /playlists\.read/);
assert.match(response.body, /backgroundColor added/);
assert.match(response.body, /logoPath added/);
assert.ok(response.body.indexOf('login.success') < response.body.indexOf('login.failed'));
assert.match(response.body, />Export</);
assert.ok(handlers['/settings/audit-log/export']);
const exportResponse = {
headers: {},
setHeader(name, value) { this.headers[name] = value; },
send(value) { this.body = value; }
};
await handlers['/settings/audit-log/export'][1](request, exportResponse, function (error) {
throw error;
});
assert.match(exportResponse.headers['Content-Type'], /text\/csv/);
assert.match(exportResponse.body, /Occurred At \(UTC\)/);
assert.match(exportResponse.body, /login.success/);
});