Skip to content

Commit 595285b

Browse files
asachs01claude
andcommitted
test(security): compute now fresh per-test in s2s-verify tests
Avoids clock-drift flakiness on the exact-skew-boundary assertions when vitest's transform/import phase is slow under concurrent load (the describe-block-level `now` could go stale by the time the test body ran). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 56421e0 commit 595285b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/__tests__/s2s-verify.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,25 @@ describe("verifyS2sHeader", () => {
1515
const MASTER = "test-master-secret-do-not-use-in-prod";
1616
const ownSubkey = deriveRecipientSubkey(MASTER, "ncentral");
1717
const siblingSubkey = deriveRecipientSubkey(MASTER, "saas-alerts");
18-
const now = Math.floor(Date.now() / 1000);
1918

2019
it("accepts a header minted with this vendor's own derived subkey", () => {
20+
const now = Math.floor(Date.now() / 1000);
2121
expect(verifyS2sHeader(mintHeader(ownSubkey, now), ownSubkey)).toBe(true);
2222
});
2323
it("REJECTS a header minted for a different vendor's derived subkey (recipient-binding proof)", () => {
24+
const now = Math.floor(Date.now() / 1000);
2425
expect(verifyS2sHeader(mintHeader(siblingSubkey, now), ownSubkey)).toBe(false);
2526
});
2627
it("rejects a stale timestamp outside the skew window", () => {
28+
const now = Math.floor(Date.now() / 1000);
2729
expect(verifyS2sHeader(mintHeader(ownSubkey, now - 301), ownSubkey)).toBe(false);
2830
});
2931
it("rejects a future timestamp outside the skew window", () => {
32+
const now = Math.floor(Date.now() / 1000);
3033
expect(verifyS2sHeader(mintHeader(ownSubkey, now + 301), ownSubkey)).toBe(false);
3134
});
3235
it("accepts a timestamp at the edge of the skew window", () => {
36+
const now = Math.floor(Date.now() / 1000);
3337
expect(verifyS2sHeader(mintHeader(ownSubkey, now - 300), ownSubkey)).toBe(true);
3438
});
3539
it("rejects a malformed header value", () => {
@@ -39,9 +43,11 @@ describe("verifyS2sHeader", () => {
3943
expect(verifyS2sHeader(undefined, ownSubkey)).toBe(false);
4044
});
4145
it("rejects when the secret is empty (dark-by-default guarantee)", () => {
46+
const now = Math.floor(Date.now() / 1000);
4247
expect(verifyS2sHeader(mintHeader(ownSubkey, now), "")).toBe(false);
4348
});
4449
it("rejects a tampered signature", () => {
50+
const now = Math.floor(Date.now() / 1000);
4551
const header = mintHeader(ownSubkey, now);
4652
const tampered = header.slice(0, -1) + (header.endsWith("0") ? "1" : "0");
4753
expect(verifyS2sHeader(tampered, ownSubkey)).toBe(false);

0 commit comments

Comments
 (0)