mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Split the testable, security- and correctness-critical logic of the new avatars +
original-members feature into pure Node modules (module.exports, no Meteor) and cover them
with plain-Node tests/*.test.cjs (positive AND negative), matching the repo's existing
unit-test style. Wired into the test:unit:node script.
- models/lib/avatarUrlSafety.js (from server/lib/localizeAvatar.js): isExternalAvatarUrl,
isBlockedIp (SSRF ranges), decodeDataUri, checkUrlHostSync. Tests assert external vs
local/relative/non-http URLs, that private/loopback/link-local/CGNAT/metadata/multicast
IPv4+IPv6 (incl. IPv4-mapped) are blocked while genuine public addresses and near-miss
ranges are allowed, data: decoding, and that non-http(s) schemes, localhost and
metadata hosts are rejected.
- models/lib/importedUserReconciliationPlan.js (from server/importedUserReconciliation.js):
planReconciliation. Tests: matches merge, non-matches deactivate, never match another
placeholder or self or a username-less placeholder.
- packages/wekan-ldap/server/ldapPhoto.js (from sync.js): getLdapPhotoBuffer. Tests the
Buffer / array / {type:'Buffer'} / base64 shapes and jpegPhoto>thumbnailPhoto, and that
missing/empty/short values yield null (never throw).
- models/lib/importedBoardMemberPlan.js (from wekanCreator.js): planImportedBoardMember.
Tests: unmapped member kept by original id but inactive+non-admin, mapped role preserved,
importer and id-less members dropped.
The extractions are behaviour-preserving; the app modules now import these helpers.
Thanks to xet7.
59 lines
2.6 KiB
JavaScript
59 lines
2.6 KiB
JavaScript
'use strict';
|
|
|
|
// Plain-Node unit test (no Meteor) for how an imported board member becomes a member of
|
|
// the new board. Run: node tests/importedBoardMemberPlan.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const { planImportedBoardMember } = require('../models/lib/importedBoardMemberPlan');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
const IMPORTER = 'importer-id';
|
|
|
|
// ── positive: original member kept, inactive + non-admin when unmapped ───────
|
|
test('unmapped member is kept by original id, inactive and non-admin', () => {
|
|
const e = planImportedBoardMember({ userId: 'alice', isActive: true, isAdmin: true }, IMPORTER);
|
|
assert.strictEqual(e.userId, 'alice');
|
|
assert.strictEqual(e.wekanId, 'alice');
|
|
assert.strictEqual(e.isActive, false, 'imported member must be inactive until reconciled');
|
|
assert.strictEqual(e.isAdmin, false, 'imported member must not silently gain admin');
|
|
});
|
|
test('supports the id field (client mapper renames userId -> id)', () => {
|
|
const e = planImportedBoardMember({ id: 'bob' }, IMPORTER);
|
|
assert.strictEqual(e.userId, 'bob');
|
|
assert.strictEqual(e.wekanId, 'bob');
|
|
});
|
|
test('a real mapping preserves the mapped role (active + admin)', () => {
|
|
const e = planImportedBoardMember({ userId: 'src', wekanId: 'target', isActive: true, isAdmin: true }, IMPORTER);
|
|
assert.strictEqual(e.userId, 'target');
|
|
assert.strictEqual(e.wekanId, 'target');
|
|
assert.strictEqual(e.isActive, true);
|
|
assert.strictEqual(e.isAdmin, true);
|
|
});
|
|
test('a mapped-but-inactive member stays inactive', () => {
|
|
const e = planImportedBoardMember({ userId: 'src', wekanId: 'target', isActive: false }, IMPORTER);
|
|
assert.strictEqual(e.isActive, false);
|
|
assert.strictEqual(e.isAdmin, false);
|
|
});
|
|
|
|
// ── negative: no member is produced ──────────────────────────────────────────
|
|
test('the importer themselves is not re-added', () => {
|
|
assert.strictEqual(planImportedBoardMember({ userId: IMPORTER, isAdmin: true }, IMPORTER), null);
|
|
assert.strictEqual(planImportedBoardMember({ wekanId: IMPORTER }, IMPORTER), null);
|
|
});
|
|
test('a member with no id is dropped', () => {
|
|
assert.strictEqual(planImportedBoardMember({ isAdmin: true }, IMPORTER), null);
|
|
assert.strictEqual(planImportedBoardMember({}, IMPORTER), null);
|
|
});
|
|
test('null / undefined member is dropped', () => {
|
|
assert.strictEqual(planImportedBoardMember(null, IMPORTER), null);
|
|
assert.strictEqual(planImportedBoardMember(undefined, IMPORTER), null);
|
|
});
|
|
|
|
console.log(`\nimportedBoardMemberPlan: ${passed} tests passed`);
|