Files
wekan/tests/adminAttachmentRead.test.cjs
T
Lauri Ojansivu c3caf87a13 Enforce disabled account status and revoke existing sessions.
Fix InactiveBleed across REST, attachment and export authentication, header login, LDAP token issuance and People account controls. Apply administrator-created account flags before insertion and guard token creation atomically.

Thanks to esbrito81 and xet7 !
2026-09-26 01:27:36 +03:00

38 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
const assert = require('node:assert/strict');
const fs = require('node:fs');
const vm = require('node:vm');
const { test } = require('node:test');
const source = fs.readFileSync('server/routes/universalFileServer.js', 'utf8');
const resolver = source.slice(source.indexOf(' async function getUserFromToken('), source.indexOf(' /**\n * Authorization helper'));
const guard = source.slice(source.indexOf(' async function isAuthorizedForBoard('), source.indexOf(' /**\n * Helper function to properly encode'));
const board = { isVisibleBy: user => user?._id === 'member' };
function policy(user) {
return vm.runInNewContext(`${resolver}\n${guard}\nisAuthorizedForBoard`, {
require: () => ({ activeUserByToken: async () => user?.loginDisabled ? null : user }),
extractLoginToken: req => req.token,
isSandstormRequest: () => false,
canReadBoard: (id, value) => !!value?.isVisibleBy(id ? { _id: id } : null),
process: { env: {} },
});
}
test('Files Report administrator can read another member’s private attachment', async () => {
assert.equal(await policy({ _id: 'admin', isAdmin: true })({ token: 'valid-token-123' }, board), true);
});
test('ordinary private-board access still requires membership', async () => {
for (const [user, expected] of [[{ _id: 'member' }, true], [{ _id: 'member', loginDisabled: true }, false], [{ _id: 'outsider' }, false], [null, false]]) {
assert.equal(await policy(user)({ token: 'valid-token-123' }, board), expected);
}
});
test('missing credentials, disabled admin, non-boolean admin and missing board do not grant access', async () => {
assert.equal(await policy({ _id: 'admin', isAdmin: true })({}, board), false);
assert.equal(await policy({ _id: 'admin', isAdmin: true })({ token: 'short' }, board), false);
for (const user of [{ _id: 'admin', isAdmin: true, loginDisabled: true }, { _id: 'outsider', isAdmin: 'true' }]) {
assert.equal(await policy(user)({ token: 'valid-token-123' }, board), false);
}
assert.equal(await policy({ _id: 'admin', isAdmin: true })({ token: 'valid-token-123' }, null), false);
});
test('public attachments remain readable without credentials', async () => {
assert.equal(await policy(null)({}, { isVisibleBy: () => true }), true);
});