Files
wekan/tests/ldapGroupFilterConfig.test.cjs
T
Lauri Ojansivu 5f0716fc74 UCS: refuse to publish an app whose LDAP group settings refuse every login.
After the 12.32 UCS upgrade every LDAP login failed with "LDAP authentication
failed". The UCS compose (wekan/univention) kept the 6.09 setting
LDAP_GROUP_FILTER_ENABLE=true with no group id attribute and no group name.
6.09 read that as "in any group". WeKan now refuses an incomplete group
filter, as intended since #3700, so isUserInGroup refused everyone. The
compose is fixed in wekan/univention: the filter is off, because UCS grants
access through (wekanActivated=TRUE), and the group id attribute is cn, so
Domain Admins become admins again.

releases/ucs-release.py now applies WeKan's own group-setting rule to the
compose before it prepares a portal upload. With the group filter or admin
sync on, it needs the three group lookup settings, and an enabled filter
needs a group name. A compose that would refuse every LDAP login is not
published. It refuses the 12.32 compose and passes the fixed one.
tests/ucsRelease.test.py covers both, plus the rule.
tests/ldapGroupFilterConfig.test.cjs shows that WeKan refuses the 6.09 UCS
settings and needs nothing missing with the fixed ones.

The UCS README describes the failure and gives a workaround for installs that
already upgraded: two appcenter/env/wekan UCR values and univention-app
reinitialize. It also explains the cross-origin error seen when WeKan is
opened through a host other than ROOT_URL.

Thanks to xet7 !
2026-10-11 22:59:15 +03:00

160 lines
6.0 KiB
JavaScript

'use strict';
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const {
missingGroupLookupSettings,
missingLoginGroupFilterSettings,
splitGroupNames,
loginGroupNames,
} = require('../packages/wekan-ldap/server/groupFilterConfig');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
const complete = {
group_filter_group_id_attribute: 'cn',
group_filter_group_member_attribute: 'member',
group_filter_group_member_format: 'dn',
group_filter_group_name: 'allowed-users',
};
test('complete Samba/AD group settings permit a membership lookup', () => {
assert.deepStrictEqual(missingGroupLookupSettings(complete), []);
assert.deepStrictEqual(missingLoginGroupFilterSettings(complete), []);
});
test('missing member attribute is named instead of silently omitting membership', () => {
assert.deepStrictEqual(missingGroupLookupSettings({
...complete,
group_filter_group_member_attribute: '',
}), ['LDAP_GROUP_FILTER_GROUP_MEMBER_ATTRIBUTE']);
});
test('undefined, null, empty and whitespace-only lookup values fail closed', () => {
const options = {
...complete,
group_filter_group_id_attribute: undefined,
group_filter_group_member_attribute: null,
group_filter_group_member_format: ' ',
};
assert.deepStrictEqual(missingGroupLookupSettings(options), [
'LDAP_GROUP_FILTER_GROUP_ID_ATTRIBUTE',
'LDAP_GROUP_FILTER_GROUP_MEMBER_ATTRIBUTE',
'LDAP_GROUP_FILTER_GROUP_MEMBER_FORMAT',
]);
});
test('login filtering requires an allowed group name', () => {
assert.deepStrictEqual(missingLoginGroupFilterSettings({
...complete,
group_filter_group_name: '',
}), ['LDAP_GROUP_FILTER_GROUP_NAME']);
});
test('configured admin groups are also valid allowed login groups', () => {
assert.deepStrictEqual(missingLoginGroupFilterSettings({
...complete,
group_filter_group_name: '',
}, 'Domain Admins'), []);
});
test('#4036 admin-only users and every configured login group are admitted', () => {
assert.deepStrictEqual(loginGroupNames({
...complete,
group_filter_group_name: 'Users A, Users B',
}, true, 'Domain Admins, Operators'), [
'Users A',
'Users B',
'Domain Admins',
'Operators',
]);
});
test('#4036 disabled admin sync does not broaden the login groups', () => {
assert.deepStrictEqual(loginGroupNames(complete, false, 'Domain Admins'), [
'allowed-users',
]);
});
test('group lists discard blanks and duplicate names case-insensitively', () => {
assert.deepStrictEqual(splitGroupNames('Users, , users,Admins,'), [
'Users',
'Admins',
]);
assert.deepStrictEqual(missingLoginGroupFilterSettings({
...complete,
group_filter_group_name: ' , ',
}, ', ,'), ['LDAP_GROUP_FILTER_GROUP_NAME']);
});
test('source refuses before either LDAP group search when configuration is incomplete', () => {
const source = fs.readFileSync(path.join(
__dirname, '..', 'packages', 'wekan-ldap', 'server', 'ldap.js',
), 'utf8');
const groups = source.slice(
source.indexOf('async getUserGroups('),
source.indexOf('async isUserInGroup('),
);
const login = source.slice(
source.indexOf('async isUserInGroup('),
source.indexOf('async auth(', source.indexOf('async isUserInGroup(')),
);
assert.ok(groups.indexOf('missingGroupLookupSettings') < groups.indexOf('searchAll('));
assert.ok(login.indexOf('missingLoginGroupFilterSettings') < login.indexOf('getUserGroups('));
assert.ok(login.indexOf('missingLoginGroupFilterSettings') < login.indexOf('searchAll('));
assert.match(groups, /Answering with NO groups/);
assert.match(login, /Refusing login/);
assert.match(login, /loginGroupNames\(/);
assert.match(login, /escapeLdapFilterValue\(name\)/);
});
// UCS (wekan/univention component/compose). Its settings, as the App Center
// renders them, decide whether anyone can log in after an upgrade.
function ucsOptions(env) {
return {
group_filter_group_id_attribute: env.LDAP_GROUP_FILTER_GROUP_ID_ATTRIBUTE,
group_filter_group_member_attribute: env.LDAP_GROUP_FILTER_GROUP_MEMBER_ATTRIBUTE,
group_filter_group_member_format: env.LDAP_GROUP_FILTER_GROUP_MEMBER_FORMAT,
group_filter_group_name: env.LDAP_GROUP_FILTER_GROUP_NAME,
};
}
const UCS_609 = {
LDAP_GROUP_FILTER_ENABLE: 'true',
LDAP_GROUP_FILTER_GROUP_ID_ATTRIBUTE: '',
LDAP_GROUP_FILTER_GROUP_MEMBER_ATTRIBUTE: 'uniqueMember',
LDAP_GROUP_FILTER_GROUP_MEMBER_FORMAT: 'dn',
LDAP_GROUP_FILTER_GROUP_NAME: '',
};
// Negative: the settings UCS carried from 6.09 into the 12.32 upgrade. 6.09
// read them as "in any group"; this release refuses them, which is the
// "LDAP authentication failed" every UCS user got after upgrading. The refusal
// is right (#3700) - the fix is in the UCS compose, below.
test('the 6.09 UCS group settings are refused at login, and give no admin groups', () => {
const options = ucsOptions(UCS_609);
assert.deepStrictEqual(
missingLoginGroupFilterSettings(options, 'Domain Admins'),
['LDAP_GROUP_FILTER_GROUP_ID_ATTRIBUTE'],
);
assert.deepStrictEqual(missingGroupLookupSettings(options), ['LDAP_GROUP_FILTER_GROUP_ID_ATTRIBUTE']);
});
// The fixed UCS settings: access by (wekanActivated=TRUE), no group filter, and
// a complete group lookup so Domain Admins still become WeKan admins.
test('the fixed UCS settings need no group filter and can still find admin groups', () => {
const fixed = { ...UCS_609, LDAP_GROUP_FILTER_ENABLE: 'false', LDAP_GROUP_FILTER_GROUP_ID_ATTRIBUTE: 'cn' };
assert.strictEqual(fixed.LDAP_GROUP_FILTER_ENABLE, 'false', 'isUserInGroup returns true when the filter is off');
assert.deepStrictEqual(missingGroupLookupSettings(ucsOptions(fixed)), [],
'getUserGroups can answer, so LDAP_SYNC_ADMIN_GROUPS works');
// And if somebody turns the filter back on without naming a group, it is
// still refused rather than read as "anyone": the guard is unchanged.
assert.deepStrictEqual(
missingLoginGroupFilterSettings(ucsOptions({ ...fixed, LDAP_GROUP_FILTER_ENABLE: 'true' })),
['LDAP_GROUP_FILTER_GROUP_NAME'],
);
});
console.log(`\n${passed} passed`);