'use strict'; // Plain-Node unit test (no Meteor) for the default authentication-method helpers. // Run: node tests/authenticationMethod.test.cjs // // Regression guard for #5879: // 1. DEFAULT_AUTHENTICATION_METHOD env var was ignored (settings only ever // seeded 'password'); it must now win when set. // 2. Admin Panel > Layout > Save appeared to hang / not persist: the auth // method value does NOT overwrite the stored method', () => { // The layout-save case: select not populated yet -> '' / null, stored is ldap. assert.strictEqual(resolveDefaultAuthenticationMethod('', 'ldap'), 'ldap'); assert.strictEqual(resolveDefaultAuthenticationMethod(null, 'ldap'), 'ldap'); assert.strictEqual(resolveDefaultAuthenticationMethod(undefined, 'ldap'), 'ldap'); }); test('NEGATIVE: never resolves to an empty/undefined string (required schema field)', () => { // Even with everything empty, the result is always a usable required string. const r = resolveDefaultAuthenticationMethod('', ''); assert.strictEqual(r, 'password'); assert.ok(typeof r === 'string' && r.length > 0); }); test('NEGATIVE: a real selected value still overrides the stored one', () => { // Sanity: a genuine change (ldap -> oauth2) is not blocked by the guard. assert.strictEqual(resolveDefaultAuthenticationMethod('oauth2', 'ldap'), 'oauth2'); }); console.log(`\n${passed} passing`);