Files
wekan/tests/linkedWritePolicy.test.cjs
T
Lauri Ojansivu 7595727917 Boards every signed-in user may edit, per-list permissions, board keys and shared labels.
A board can let every signed-in user edit it, when Admin Panel / Settings /
Visibility allows it: a non-member then comments, edits and moves cards like
a Normal member, and their first edit makes them one. Board-wide settings
stay members-only.

Lists can allow or refuse editing and commenting per role (list menu, board
admins): built-in roles, custom roles and, on an open board, everyone signed
in. The server applies it to card, checklist, attachment and comment writes
and to moves into the list; the REST API honours a list's refusal on every
per-list card route. A direct client write of the setting is refused and
shown in Admin Panel / Problems.

Every board has a key, unique in the instance, suggested from its title and
set for existing boards at startup; card numbers show as KEY-7 and searching
for KEY-7 finds the card.

Shared labels in Admin Panel / Labels, for every board or an organization's
or team's boards; a board uses them beside its own, and a rename or colour
change reaches every board that uses it.

New strings translated in all languages. Low confidence: chr, tlh, wal, ay,
ace, nah, gn, iu, zgh, rup, wo, se, ff, tig, vo, bm, kl, bua, nap, mai, to,
ks, qu, bo, fj, haw, om, ss, ts, ve-PP, lld, scn.

Thanks to Meeques, justinr1234, tiFabGrinch, ejlkemper and xet7 !

Fixes #4575,
Fixes #4527,
Fixes #2449,
Fixes #2450,
Fixes #2761,
Fixes #4698.
2026-10-14 09:28:45 +03:00

54 lines
3.7 KiB
JavaScript

'use strict';
// Hall of Fame regression coverage: LinkedWriteBleed.
const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const vm = require('node:vm');
const { sourceRoleBlocksDelegation } = require('../models/lib/linkedWritePolicy');
const { BOARD_ROLES, ROLE_FLAGS, roleCan, memberCan } = require('../models/lib/boardRoleCapabilities');
test('live links cannot promote explicit non-writing source roles', async () => {
const text = fs.readFileSync('server/lib/linkedCardPermission.js', 'utf8');
for (const role of BOARD_ROLES) {
const member = { userId: 'u', isActive: true, [ROLE_FLAGS[role] || 'normal']: true };
const source = { _id: 'A', members: [member] };
assert.equal(sourceRoleBlocksDelegation('u', source), !roleCan(role, 'write'));
const logs = [], context = {
sourceRoleBlocksDelegation, recordLinkedWriteDenial: source => logs.push(source),
allowIsBoardMemberWithWriteAccess: (id, board) => Boolean(board && memberCan(board.members, id, 'write')),
canUserSeeBoard: async () => true,
// #4527: the card's list is asked first; these lists make no exception,
// so the source role alone decides, as this test is about.
listException: async () => undefined,
require: () => ({ exceptionFor: () => undefined }),
Boards: { findOneAsync: async () => source, find: () => ({ fetchAsync: async () => [{ members: [{ userId: 'u', isActive: true, isAdmin: true }] }] }) },
Cards: { find: () => ({ fetchAsync: async () => [{ boardId: 'self-owned' }] }) },
};
vm.runInNewContext(text.replace(/^import .*;\n/gm, '').replace(/^export async function/gm, 'async function'), context);
assert.equal(await context.canEditCardOrLinkedCard('u', { _id: 'card', boardId: 'A' }), roleCan(role, 'write'));
assert.equal(logs.length, roleCan(role, 'write') ? 0 : 1);
const count = logs.length;
assert.equal(await context.canEditCardOrLinkedCard('u', { _id: 'card', boardId: 'A' }, source, { recordDenial: false }), roleCan(role, 'write'));
assert.equal(logs.length, count, 'read-side capability checks must not emit write-denial events');
}
});
test('negative: method, DDP insert and link-pointer updates enforce source write access', () => {
const methods = fs.readFileSync('server/models/cards.js', 'utf8');
const at = methods.indexOf('async function createLinkedCardFor(');
const body = methods.slice(at, methods.indexOf('Meteor.methods({', at));
assert.doesNotMatch(body, /allowIsBoardMember\(/);
assert.match(body, /allowIsBoardMemberWithWriteAccess\(userId, sourceBoard\)/);
// An assigned-only member links only cards assigned to them.
assert.match(body, /isAssignedOnlyMember\(sourceBoard, userId\) && !\(sourceCard\.assignees \|\| \[\]\)\.includes\(userId\)/);
// The method and the REST route (linkedId) both use that one rule; the REST
// route used to check only read access and clone the whole source card.
assert.match(methods, /return createLinkedCardFor\(this\.userId, [^)]*'createLinkedCard'\)/);
assert.match(methods, /await createLinkedCardFor\(req\.userId, [\s\S]*?'rest:card-link'\)/);
const rest = methods.slice(methods.indexOf("if (req.body.linkedId) {"), methods.indexOf("const linkedCard = await ReactiveCache.getCard(linkedNewId);"));
assert.doesNotMatch(rest, /checkBoardAccess|\.link\(/);
const ddp = fs.readFileSync('server/permissions/cards.js', 'utf8');
assert.equal((ddp.match(/await denyUnauthorizedCardLink\(/g) || []).length, 2);
assert.match(ddp, /allowIsBoardMemberWithWriteAccess\(userId, board\)/);
const helper = fs.readFileSync('server/lib/linkedCardPermission.js', 'utf8');
assert.ok(helper.indexOf('sourceRoleBlocksDelegation(userId, sourceBoard)') < helper.indexOf('const links ='));
});