Modul server/fork/auth (Config, Session-Cookie, OIDC-Flow, Kontozuordnung), Einhängen in server/app.js, Client-Helfer für Login/Logout, PUT /api/user/rename für OIDC-Sessions gesperrt (A01). Tests gegen Mock-IdP. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
56 lines
2.3 KiB
JavaScript
56 lines
2.3 KiB
JavaScript
import { readAuthConfig, parseTtl, clientConfig } from './config.js';
|
|
|
|
const base = {
|
|
HB_PUBLIC_URL : 'https://brew.example.org/', HB_OIDC_ISSUER : 'https://idp.example/realms/x',
|
|
HB_OIDC_CLIENT_ID : 'id', HB_OIDC_CLIENT_SECRET : 's', HB_SESSION_SECRET : 'x'.repeat(32)
|
|
};
|
|
|
|
describe('Auth-Konfiguration', ()=>{
|
|
test('Standard ohne Angaben: nur naturalcrit (Upstream-Verhalten)', ()=>{
|
|
const c = readAuthConfig({});
|
|
expect(c.providers).toEqual(['naturalcrit']);
|
|
expect(clientConfig(c).loginUrl).toBeNull();
|
|
});
|
|
|
|
test('Issuer gesetzt, Provider leer: oidc,naturalcrit mit Auswahlseite', ()=>{
|
|
const c = readAuthConfig(base);
|
|
expect(c.providers).toEqual(['oidc', 'naturalcrit']);
|
|
expect(c.publicUrl).toBe('https://brew.example.org');
|
|
expect(c.secureCookies).toBe(true);
|
|
expect(clientConfig(c).loginUrl).toBe('/auth/login');
|
|
expect(c.oidc).toMatchObject({ scopes: 'openid profile email', usernameClaim: 'preferred_username', linkByEmail: false, endSession: false, label: 'Anmelden' });
|
|
});
|
|
|
|
test('nur oidc: direkter Login-Link', ()=>{
|
|
const c = readAuthConfig({ ...base, HB_AUTH_PROVIDERS: 'oidc' });
|
|
expect(c.providers).toEqual(['oidc']);
|
|
expect(clientConfig(c).loginUrl).toBe('/auth/oidc/login');
|
|
});
|
|
|
|
test('Startprüfung nennt fehlende Variablen', ()=>{
|
|
expect(()=>readAuthConfig({ HB_AUTH_PROVIDERS: 'oidc' })).toThrow(/HB_OIDC_ISSUER.*HB_OIDC_CLIENT_ID.*HB_OIDC_CLIENT_SECRET.*HB_PUBLIC_URL.*HB_SESSION_SECRET/);
|
|
});
|
|
|
|
test('zu kurzes Session-Secret und unbekannter Provider brechen ab', ()=>{
|
|
expect(()=>readAuthConfig({ ...base, HB_SESSION_SECRET: 'kurz' })).toThrow(/32 Byte/);
|
|
expect(()=>readAuthConfig({ HB_AUTH_PROVIDERS: 'ldap' })).toThrow(/unbekannte/);
|
|
});
|
|
|
|
test('http-URL: Cookies nicht Secure', ()=>{
|
|
expect(readAuthConfig({ ...base, HB_PUBLIC_URL: 'http://localhost:8000' }).secureCookies).toBe(false);
|
|
});
|
|
|
|
test('TTL-Formate', ()=>{
|
|
expect(parseTtl('7d')).toBe(604800);
|
|
expect(parseTtl('12h')).toBe(43200);
|
|
expect(parseTtl('3600')).toBe(3600);
|
|
expect(parseTtl(undefined)).toBe(604800);
|
|
expect(()=>parseTtl('bald')).toThrow();
|
|
expect(()=>parseTtl('0')).toThrow();
|
|
});
|
|
|
|
test('Secret taucht nicht in der Client-Konfiguration auf', ()=>{
|
|
expect(JSON.stringify(clientConfig(readAuthConfig(base)))).not.toMatch(/secret|"s"/i);
|
|
});
|
|
});
|