Files
wekan/tests/boardActor.test.cjs
T
Lauri Ojansivu 5ba1098521 Server tests pass again: four faults the repaired test build found, fixed.
- A password sign-in refused by policy (PASSWORD_LOGIN_ENABLED=false,
  forgot password off, LDAP's password-login guard) was counted by the
  lockout as a wrong password, which threw its own 403 "Incorrect password"
  over the policy's error: the person was told the wrong thing, and enough
  attempts locked the account because of a setting. Policy refusals are no
  guesses now (loginFailureDecision.js).
- Auto-archive fetched its boards without their members, so boardActorId
  found nobody and every auto-archive was recorded as no user.
- Every upload got two "added" rows in the card history: the upload hook's
  and the content index's. The index writes its row only for an attachment
  that has none, and never for a durable rule copy, whose plan writes it.
- Not found is undefined from Meteor 3's findOneAsync: the Admin Panel
  addresses test accepts either.

meteor test --full-app: 699 passing, 0 failing (was 693 / 6).

Thanks to xet7 !
2026-11-24 17:49:56 +02:00

70 lines
3.6 KiB
JavaScript

'use strict';
// Scheduled rules, auto-archive and attachment retention act as the board.
// They read `board.createdBy`, which the Boards schema does not have, so a
// scheduled rule ran as nobody and its "create card" action failed on every
// run: "scheduledRules: error running trigger ... User ID is required in cards
// insertAsync" (production docker log, v13.13).
// Run: node --test tests/boardActor.test.cjs
const test = require('node:test');
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const { boardActorId } = require('../models/lib/boardActor');
const ROOT = path.join(__dirname, '..');
const read = rel => fs.readFileSync(path.join(ROOT, rel), 'utf8');
test('the board acts as its first active admin, else its first active member', () => {
assert.strictEqual(boardActorId({ members: [
{ userId: 'gone-admin', isActive: false, isAdmin: true },
{ userId: 'member', isActive: true },
{ userId: 'admin', isActive: true, isAdmin: true },
] }), 'admin');
assert.strictEqual(boardActorId({ members: [{ userId: 'gone', isActive: false }, { userId: 'member', isActive: true }] }), 'member');
});
test('negative: a board with no active member acts as nobody, and createdBy is not read', () => {
assert.strictEqual(boardActorId({ createdBy: 'someone', members: [{ userId: 'gone', isActive: false, isAdmin: true }] }), null);
for (const board of [null, undefined, {}, { members: 'x' }, { members: [null, { isActive: true }, { userId: '', isActive: true }] }]) {
assert.strictEqual(boardActorId(board), null);
}
});
test('the Boards schema has no createdBy, so nothing may read board.createdBy', () => {
assert.doesNotMatch(read('models/boards.js'), /^\s+createdBy:\s*\{/m, 'if Boards gains createdBy, revisit boardActor.js');
const hits = [];
const walk = dir => {
for (const entry of fs.readdirSync(path.join(ROOT, dir), { withFileTypes: true })) {
const rel = path.join(dir, entry.name);
if (entry.isDirectory()) {
if (!['node_modules', '.build', '.tools', 'tests'].includes(entry.name) && !entry.name.startsWith('_build')) walk(rel);
}
// Code only: the comments that explain the change name it.
else if (/\.(c?js|mjs)$/.test(entry.name)
&& /\bboard\??\.createdBy\b/.test(read(rel).replace(/\/\/.*$/gm, '').replace(/\/\*[\s\S]*?\*\//g, ''))) hits.push(rel);
}
};
for (const dir of ['server', 'models', 'client', 'imports']) walk(dir);
assert.deepStrictEqual(hits, []);
});
test('a scheduled rule acts as the board, and its created card names its author', () => {
const scheduled = read('server/scheduledRules.js');
assert.match(scheduled, /^import \{ boardActorId \} from '\/models\/lib\/boardActor';$/m);
assert.match(scheduled, /const userId = boardActorId\(board\) \|\| undefined;/);
const helper = read('server/rulesHelper.js');
const create = helper.slice(helper.indexOf("if (action.actionType === 'createCard') {"));
assert.match(create.slice(0, 1200), /const authorId = resolveActingUserId\(activity\);[\s\S]*\.\.\.\(authorId \? \{ userId: authorId \} : \{\}\),/);
});
test('auto-archive fetches the members boardActorId decides from (negative: not createdBy)', () => {
// The scan projected { createdBy } only, so boardActorId saw no members and
// every auto-archive was recorded as nobody.
const src = read('server/autoArchiveCards.js');
const scan = src.slice(src.indexOf('export async function scanAutoArchive'));
const fields = /fields:\s*\{([^}]*)\}/.exec(scan);
assert.ok(fields, 'scanAutoArchive projects its boards');
assert.match(fields[1], /\bmembers:\s*1\b/);
assert.doesNotMatch(fields[1], /createdBy/);
});