import "reflect-metadata"; import { validateAppConfig } from "../src/config/app.config"; import { durationSeconds } from "../src/common/interval"; describe("Authentication configuration", () => { it("defaults authentication off with a 24-hour token lifetime and cleanup schedule", () => { const config = validateAppConfig({}); expect(config.AUTH_ENABLED).toBe(false); expect(config.AUTH_JWT_EXPIRES_IN).toBe("24h"); expect(config.AUTH_COOKIE_NAME).toBe("liqa_auth"); expect(config.AUTH_REVOKED_TOKEN_CLEANUP_CRON).toBe("0 3 * * *"); }); it("parses explicit true and false values without JavaScript truthiness", () => { expect(validateAppConfig({ AUTH_ENABLED: "false" }).AUTH_ENABLED).toBe( false, ); expect( validateAppConfig({ AUTH_ENABLED: "true", AUTH_JWT_SECRET: "test" }) .AUTH_ENABLED, ).toBe(true); }); it("requires a signing secret and usable token lifetime only when enabled", () => { expect(() => validateAppConfig({ AUTH_ENABLED: "true" })).toThrow( "AUTH_JWT_SECRET must be set when AUTH_ENABLED=true", ); expect(() => validateAppConfig({ AUTH_ENABLED: "true", AUTH_JWT_SECRET: "test", AUTH_JWT_EXPIRES_IN: "0h", }), ).toThrow("AUTH_JWT_EXPIRES_IN must be a positive duration"); expect( validateAppConfig({ AUTH_ENABLED: "false", AUTH_JWT_EXPIRES_IN: "invalid", }).AUTH_ENABLED, ).toBe(false); }); it("rejects non-boolean auth settings and parses common positive durations", () => { expect(() => validateAppConfig({ AUTH_ENABLED: "yes" })).toThrow( "AUTH_ENABLED must be either true or false", ); expect(durationSeconds("30m")).toBe(1800); expect(durationSeconds("24h")).toBe(86400); expect(durationSeconds("2d")).toBe(172800); expect(durationSeconds("0s")).toBeNull(); }); });