import { test, expect } from "bun:test"; import { validAge, allowedIdentity, requireTLSURL, } from "../scripts/security-guards"; test("age rejects future, invalid and stale receipts", () => { for (const age of [-1, NaN, Infinity, 61]) expect(() => validAge(age, 60)).toThrow(); expect(validAge(0, 60)).toBe(0); expect(validAge(60, 60)).toBe(60); }); test("client role requires exact allowlist membership", () => { expect(allowedIdentity("worker", ["api", "worker"])).toBe("worker"); for (const role of ["", "worker.admin", "Worker", "lb"]) expect(() => allowedIdentity(role, ["api", "worker"])).toThrow(); }); test("network endpoints require TLS and an exact intended hostname", () => { expect(requireTLSURL("https://openbao:8200", "openbao").hostname).toBe( "openbao", ); for (const url of [ "http://openbao:8200", "https://else:8200", "https://user:password@openbao:8200", ]) expect(() => requireTLSURL(url, "openbao")).toThrow(); });