feat(auth): add optional authentication boundary
- Add account, JWT session, revocation, cookie and bearer handling. - Protect server surfaces while preserving public health, manifest and disabled mode. - Add SQLite migration and focused server regression coverage.
This commit is contained in:
1 parent
d4bb274982
commit
de41571b5c
33 files changed
+1083
-20
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import "reflect-metadata";
|
||||
import {
|
||||
authDurationSeconds,
|
||||
validateAppConfig,
|
||||
} from "../src/config/app.config";
|
||||
|
||||
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_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(authDurationSeconds("30m")).toBe(1800);
|
||||
expect(authDurationSeconds("24h")).toBe(86400);
|
||||
expect(authDurationSeconds("2d")).toBe(172800);
|
||||
expect(authDurationSeconds("0s")).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user