/** * DTP-05 step 3 / DTP-07 — issuance window enforcement. */ import { describe, expect, it } from "@suaveplan/testing/runner"; import { type DriveTemplateError, DTP_CODES, ISSUANCE_WINDOW_MS, TemplateNonceLru, validateTemplate, } from "../src/index.js"; import { makeKeys, signed } from "./_helpers.js"; describe("DTP-07 — 24-hour issuance window", () => { it("ISSUANCE_WINDOW_MS pinned at 24h", { timeout: 5000 }, () => { expect(ISSUANCE_WINDOW_MS).toBe(24 * 60 * 60 * 1000); }); it("template issued 24h+1s ago rejected as STALE", { timeout: 5000, }, () => { const keys = makeKeys(); const NOW = 5_000_000_000; const issuedAt = NOW - ISSUANCE_WINDOW_MS - 1_000; const tpl = signed( { issuer: keys.publicHex, issuedAt, expiresAt: NOW + 60_000, }, keys ); const ctx = { clock: () => NOW, nonceLru: new TemplateNonceLru(), }; try { validateTemplate(tpl, ctx); throw new Error("expected STALE"); } catch (err) { expect((err as DriveTemplateError).code).toBe( DTP_CODES.TEMPLATE_STALE ); } }); it("template issued just under 24h ago accepted", { timeout: 5000, }, () => { const keys = makeKeys(); const NOW = 5_000_000_000; const issuedAt = NOW - ISSUANCE_WINDOW_MS + 1_000; const tpl = signed( { issuer: keys.publicHex, issuedAt, expiresAt: NOW + 60_000, }, keys ); const ctx = { clock: () => NOW, nonceLru: new TemplateNonceLru(), }; expect(() => validateTemplate(tpl, ctx)).not.toThrow(); }); });