mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 10:48:06 -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.
34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
// Pure planning for imported-placeholder reconciliation (see
|
|
// server/importedUserReconciliation.js), split out so it is unit-testable without a DB.
|
|
//
|
|
// Given the imported placeholder users and the set of candidate real accounts, decide:
|
|
// - merges: placeholders that have a matching VALID account (same username, and
|
|
// that account is itself not an imported placeholder) → merge in.
|
|
// - deactivations: placeholders with no matching valid account (e.g. a person not in
|
|
// LDAP) → leave inactive.
|
|
// A placeholder never matches itself or another placeholder.
|
|
function planReconciliation(placeholders, realUsers) {
|
|
const byUsername = new Map();
|
|
for (const u of realUsers || []) {
|
|
if (u && u.username && u._id && u.authenticationMethod !== 'imported') {
|
|
if (!byUsername.has(u.username)) byUsername.set(u.username, u._id);
|
|
}
|
|
}
|
|
const merges = [];
|
|
const deactivations = [];
|
|
for (const ph of placeholders || []) {
|
|
if (!ph || !ph._id) continue;
|
|
const targetId = ph.username ? byUsername.get(ph.username) : undefined;
|
|
if (targetId && targetId !== ph._id) {
|
|
merges.push({ placeholderId: ph._id, targetId });
|
|
} else {
|
|
deactivations.push(ph._id);
|
|
}
|
|
}
|
|
return { merges, deactivations };
|
|
}
|
|
|
|
module.exports = { planReconciliation };
|