Files
suaveplan/packages/networking/drive/drive-template/tests/template-expired.test.ts
2026-05-27 23:47:53 +01:00

67 lines
1.8 KiB
TypeScript

/**
* DTP-05 step 2 — TEMPLATE_EXPIRED rejection.
*/
import { describe, expect, it } from "@suaveplan/testing/runner";
import {
type DriveTemplateError,
DTP_CODES,
TemplateNonceLru,
validateTemplate,
} from "../src/index.js";
import { makeKeys, signed } from "./_helpers.js";
describe("DTP-05 step 2 — expired templates", () => {
it("template past expiresAt rejected with TEMPLATE_EXPIRED", {
timeout: 5000,
}, () => {
const keys = makeKeys();
const NOW = 2_000_000_000;
const tpl = signed(
{
issuer: keys.publicHex,
issuedAt: NOW - 1_000,
expiresAt: NOW - 1, // already expired
},
keys
);
const ctx = {
clock: () => NOW,
nonceLru: new TemplateNonceLru(),
};
try {
validateTemplate(tpl, ctx);
throw new Error("expected EXPIRED");
} catch (err) {
expect((err as DriveTemplateError).code).toBe(
DTP_CODES.TEMPLATE_EXPIRED
);
}
});
it("template at exactly expiresAt rejected (>=)", { timeout: 5000 }, () => {
const keys = makeKeys();
const NOW = 2_000_000_000;
const tpl = signed(
{
issuer: keys.publicHex,
issuedAt: NOW - 1_000,
expiresAt: NOW,
},
keys
);
const ctx = {
clock: () => NOW,
nonceLru: new TemplateNonceLru(),
};
try {
validateTemplate(tpl, ctx);
throw new Error("expected EXPIRED");
} catch (err) {
expect((err as DriveTemplateError).code).toBe(
DTP_CODES.TEMPLATE_EXPIRED
);
}
});
});