mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Admin Panel / People showed "Last active" as "-" for every user but the administrator: the people publication did not carry lastConnectionDate. USERS_DISABLE_INACTIVE_AFTER_DAYS disables, once a night, accounts that have not used WeKan for that many days, and revokes their logins. Admins are never disabled. An account with no recorded activity starts its count on the first run rather than from createdAt, and re-enabling an account restarts it. The setting is in Admin Panel / People / Login as well as in the environment, and the job resolves it every night, so a change there needs no restart. Every platform's settings file lists it. LDAP background sync looked a user up by id without LDAP_USER_SEARCH_FILTER, so an account the filter excludes - one disabled in Active Directory - could not log in but was still "found". It was never disabled, and a manual disable was undone on the next run. The filter is now ANDed into the lookup. An account disabled for inactivity is not re-enabled by the sync. From the patch by Raymond-Voogt, with the setting moved into the Admin Panel's login settings. Tests: tests/inactiveUsers.test.cjs, tests/ldapBackgroundSync.test.cjs, tests/ldapUserIdFilter.test.cjs, tests/authConfigCatalog.test.cjs and tests/playwright/specs/inactive-users-last-active.e2e.js. Thanks to Raymond-Voogt and xet7 ! Fixes #6783, Fixes #6784, Fixes #6785.
143 lines
6.1 KiB
JavaScript
143 lines
6.1 KiB
JavaScript
'use strict';
|
|
|
|
// Plain-Node unit test for issue #4654: LDAP background sync
|
|
// (LDAP_BACKGROUND_SYNC_KEEP_EXISTANT_USERS_UPDATED) only worked once for new
|
|
// users. getUserById() built its search filter from LDAP_UNIQUE_IDENTIFIER_FIELD
|
|
// alone: unset -> TypeError (undefined.split) aborting the whole sync run;
|
|
// empty -> invalid filter "(|(=value))" (seen in the issue logs), so existing
|
|
// users were never found again ("Can't sync user"). The stored id can also come
|
|
// from LDAP_USER_SEARCH_FIELD (getLdapUserUniqueID fallback), so the filter must
|
|
// consider both settings.
|
|
// Run: node tests/ldapUserIdFilter.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const {
|
|
splitFieldSetting,
|
|
buildUserIdFilter,
|
|
} = require('../packages/wekan-ldap/server/userIdFilter');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
// ── splitFieldSetting ─────────────────────────────────────────────────────────
|
|
|
|
test('split: comma list with whitespace', () => {
|
|
assert.deepStrictEqual(splitFieldSetting(' guid , sAMAccountName '), ['guid', 'sAMAccountName']);
|
|
});
|
|
|
|
test('split: unset/empty/non-string means no fields', () => {
|
|
assert.deepStrictEqual(splitFieldSetting(undefined), []);
|
|
assert.deepStrictEqual(splitFieldSetting(''), []);
|
|
assert.deepStrictEqual(splitFieldSetting(null), []);
|
|
assert.deepStrictEqual(splitFieldSetting(123), []);
|
|
});
|
|
|
|
test('split: drops empty entries so no "(=value)" clause can be built', () => {
|
|
assert.deepStrictEqual(splitFieldSetting('a,,b,'), ['a', 'b']);
|
|
assert.deepStrictEqual(splitFieldSetting(' , '), []);
|
|
});
|
|
|
|
// ── buildUserIdFilter: positive cases ─────────────────────────────────────────
|
|
|
|
test('stored idAttribute wins and is used directly', () => {
|
|
assert.strictEqual(
|
|
buildUserIdFilter('sAMAccountName', '\\6d\\2e', 'guid', 'uid'),
|
|
'(sAMAccountName=\\6d\\2e)',
|
|
);
|
|
});
|
|
|
|
test('single unique identifier field gives a plain equality filter', () => {
|
|
assert.strictEqual(
|
|
buildUserIdFilter(undefined, '\\01\\02', 'objectGUID', ''),
|
|
'(objectGUID=\\01\\02)',
|
|
);
|
|
});
|
|
|
|
test('multiple fields are OR-ed', () => {
|
|
assert.strictEqual(
|
|
buildUserIdFilter(undefined, 'v', 'guid,entryUUID', 'uid'),
|
|
'(|(guid=v)(entryUUID=v)(uid=v))',
|
|
);
|
|
});
|
|
|
|
test('#4654 config: unset LDAP_UNIQUE_IDENTIFIER_FIELD falls back to LDAP_USER_SEARCH_FIELD', () => {
|
|
// The issue reporter had only LDAP_USER_SEARCH_FIELD=sAMAccountName set;
|
|
// the old code crashed on settings_get(...).split(',') here.
|
|
assert.strictEqual(
|
|
buildUserIdFilter(undefined, '\\6d\\2e\\75\\73\\65\\72', undefined, 'sAMAccountName'),
|
|
'(sAMAccountName=\\6d\\2e\\75\\73\\65\\72)',
|
|
);
|
|
});
|
|
|
|
test('duplicate attribute across both settings is de-duplicated', () => {
|
|
// The workaround from the issue comments: LDAP_UNIQUE_IDENTIFIER_FIELD set
|
|
// to the same attribute as LDAP_USER_SEARCH_FIELD.
|
|
assert.strictEqual(
|
|
buildUserIdFilter(undefined, 'v', 'sAMAccountName', 'sAMAccountName'),
|
|
'(sAMAccountName=v)',
|
|
);
|
|
});
|
|
|
|
// ── buildUserIdFilter: negative cases ─────────────────────────────────────────
|
|
|
|
test('empty unique identifier field never yields the invalid "(|(=value))" filter', () => {
|
|
// Old behavior: ''.split(',') -> [''] -> "(|(=m.user))" as in the issue log.
|
|
const filter = buildUserIdFilter(undefined, 'm.user', '', 'sAMAccountName');
|
|
assert.strictEqual(filter, '(sAMAccountName=m.user)');
|
|
assert.ok(!filter.includes('(='), 'filter must not contain an empty attribute name');
|
|
});
|
|
|
|
test('no usable attribute anywhere returns null instead of throwing or "(|)"', () => {
|
|
assert.strictEqual(buildUserIdFilter(undefined, 'v', undefined, undefined), null);
|
|
assert.strictEqual(buildUserIdFilter(undefined, 'v', '', ''), null);
|
|
assert.strictEqual(buildUserIdFilter(null, 'v', ' , ', ' '), null);
|
|
});
|
|
|
|
test('old implementation would have failed on the issue configuration', () => {
|
|
// Documents the regression this test guards against: the pre-fix code path.
|
|
const oldGetUserByIdFilter = (uniqueIdentifierSetting, escapedValue) => {
|
|
const fields = uniqueIdentifierSetting.split(','); // throws when unset
|
|
return `(|${fields.map((item) => `(${item}=${escapedValue})`).join('')})`;
|
|
};
|
|
assert.throws(() => oldGetUserByIdFilter(undefined, 'm.user'), TypeError);
|
|
assert.strictEqual(oldGetUserByIdFilter('', 'm.user'), '(|(=m.user))'); // invalid filter
|
|
});
|
|
|
|
// ── LDAP_USER_SEARCH_FILTER in the background-sync lookup ─────────────────────
|
|
// An account LDAP_USER_SEARCH_FILTER excludes cannot log in; background sync
|
|
// must not "find" it either, or LDAP_BACKGROUND_SYNC_DISABLE_NONEXISTANT_USERS
|
|
// never disables a user that was disabled in the directory (and re-enables one
|
|
// an admin disabled by hand).
|
|
|
|
const AD_ENABLED_ONLY = '(&(objectClass=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))';
|
|
|
|
test('search filter is ANDed with the stored-attribute filter', () => {
|
|
assert.strictEqual(
|
|
buildUserIdFilter('objectGUID', '\\01\\02', '', '', AD_ENABLED_ONLY),
|
|
`(&${AD_ENABLED_ONLY}(objectGUID=\\01\\02))`,
|
|
);
|
|
});
|
|
|
|
test('search filter is ANDed with an OR over the configured fields', () => {
|
|
assert.strictEqual(
|
|
buildUserIdFilter(undefined, 'm.user', 'guid', 'sAMAccountName', '(objectClass=person)'),
|
|
'(&(objectClass=person)(|(guid=m.user)(sAMAccountName=m.user)))',
|
|
);
|
|
});
|
|
|
|
test('empty or missing search filter leaves the id filter unchanged', () => {
|
|
assert.strictEqual(buildUserIdFilter('uid', 'a', '', '', ''), '(uid=a)');
|
|
assert.strictEqual(buildUserIdFilter('uid', 'a', '', '', ' '), '(uid=a)');
|
|
assert.strictEqual(buildUserIdFilter('uid', 'a', '', ''), '(uid=a)');
|
|
});
|
|
|
|
test('no id attribute configured is still null with a search filter', () => {
|
|
assert.strictEqual(buildUserIdFilter(undefined, 'v', '', '', '(objectClass=person)'), null);
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|