import { describe, expect, it } from "vitest"; import { hashToken, isRequestTimestampFresh, verifyHashedToken } from "../src/index"; describe("plugin request authentication", () => { it("compares an opaque token with its stored hash", () => { const storedHash = hashToken("correct-high-entropy-token"); expect(verifyHashedToken("correct-high-entropy-token", storedHash)).toBe(true); expect(verifyHashedToken("wrong-token", storedHash)).toBe(false); expect(verifyHashedToken("correct-high-entropy-token", "malformed")).toBe(false); }); it("rejects stale and excessively future-dated requests", () => { const now = new Date("2026-08-01T12:00:00.000Z"); expect(isRequestTimestampFresh(new Date("2026-08-01T11:59:30.000Z"), now, 45_000)).toBe(true); expect(isRequestTimestampFresh(new Date("2026-08-01T11:59:14.000Z"), now, 45_000)).toBe(false); expect(isRequestTimestampFresh(new Date("2026-08-01T12:00:46.000Z"), now, 45_000)).toBe(false); }); });