Files
wekan/tests/inviteMemberEmailCase.test.cjs
T
Lauri Ojansivu 5c2fc294f3 Tests and docs follow this round's changes: Retention documented, a real regex escape, the snap guards.
The full node suite found three breakages in this round's own work:
- adminPanelDocsMatchMenu: Admin Panel / Attachments / Retention was in the
  product and not in docs/Features/Admin-Panel/Attachments/README.md. It has
  its section and its row in the URL table now.
- incompleteEscaping: the test from the #6788 patch hand-wrote a regex escape.
  It now uses the same escape-string-regexp package the server imports.
- releaseSnapArches: two guards read the Launchpad step's text. infra_failure()
  (the v12.56 Launchpad-outage retries) also reads snapcraft-wekan-*.txt
  before the loop, and the fixed `sleep 60` became `sleep "$pause"`. The
  guards now look for the log printing after the no-snap message, and for the
  pause variable, and say why. These two had been failing since that change.
  An earlier run's report that this suite was only "load-related" was wrong:
  the FAIL lines had been filtered out of the output that was read.

Thanks to xet7 !
2026-10-20 14:05:13 +03:00

53 lines
2.4 KiB
JavaScript

'use strict';
// Adding a colleague to a board (Board menu > Members > +):
// 1. inviteUserToBoard matched the typed email address case-sensitively. LDAP
// and OIDC store the address as the directory spells it, so typing an
// existing colleague's address in lower case found nobody, and WeKan tried
// to create a new account instead - refused ("This user is not created")
// with registration disabled, else a raw 403 "Email already exists".
// 2. searchUsers read 5 users and filtered afterwards, so other matches ahead
// of the colleague could hide them; disabled accounts were offered although
// inviting them is refused.
// Run: node tests/inviteMemberEmailCase.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const src = fs.readFileSync(path.join(__dirname, '../server/models/users.js'), 'utf8');
const invite = src.split('async inviteUserToBoard(')[1].split('\n },\n')[0];
const search = src.split('async searchUsers(query, boardId)')[1].split('\n },\n')[0];
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
test('invite by email matches the address case-insensitively and anchored', () => {
assert.match(invite, /address: new RegExp\(`\^\$\{escapeForRegex\(username\.trim\(\)\)\}\$`, 'i'\)/);
assert.doesNotMatch(invite, /\$elemMatch: \{ address: username \}/);
});
test('the regex used matches the same address in any case, and only that one', () => {
// The same escape-string-regexp the server imports - not a copy of it, which
// tests/incompleteEscaping.test.cjs refuses anywhere in the tree.
const escapeModule = require('escape-string-regexp');
const escape = escapeModule.default || escapeModule;
const re = new RegExp(`^${escape(' jan.jansen@example.com '.trim())}$`, 'i');
assert.ok(re.test('Jan.Jansen@Example.com'));
assert.ok(!re.test('janXjansen@example.com'), 'a dot is literal');
assert.ok(!re.test('mr.jan.jansen@example.com'), 'anchored');
});
test('search filters before limiting to five results', () => {
assert.match(search, /limit: 50,/);
assert.match(search, /filteredUsers\.slice\(0, 5\)/);
assert.match(search, /filteredUsers = filteredUsers\.filter\(candidate =>/);
});
test('search does not offer disabled accounts', () => {
assert.match(search, /candidate\.loginDisabled !== true/);
assert.match(search, /loginDisabled: 1,/);
});
console.log(`\n${passed} tests passed`);