Responses had no CSP, the 48-hour download token never changed, and short share slugs could be guessed without a miss limit.
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
RULE_EXPORT_TOKEN_TTL_MS,
|
|
ruleExportToken,
|
|
ruleExportTokenMatches,
|
|
} from "../../lib/server/ruleExportToken";
|
|
|
|
describe("ruleExportToken", () => {
|
|
const pepper = "test-pepper-16chars";
|
|
const now = new Date("2026-11-21T12:00:00.000Z");
|
|
|
|
it("accepts the matching token and rejects another rule, version, or token", () => {
|
|
const token = ruleExportToken("rule-1", pepper, 0, now);
|
|
expect(ruleExportTokenMatches("rule-1", token, pepper, 0, now)).toBe(true);
|
|
expect(ruleExportTokenMatches("rule-2", token, pepper, 0, now)).toBe(false);
|
|
expect(ruleExportTokenMatches("rule-1", token, pepper, 1, now)).toBe(false);
|
|
expect(ruleExportTokenMatches("rule-1", `${token}x`, pepper, 0, now)).toBe(
|
|
false,
|
|
);
|
|
expect(ruleExportTokenMatches("rule-1", "", pepper, 0, now)).toBe(false);
|
|
});
|
|
|
|
it("rejects a token after it expires", () => {
|
|
const token = ruleExportToken("rule-1", pepper, 0, now);
|
|
const afterExpiry = new Date(now.getTime() + RULE_EXPORT_TOKEN_TTL_MS + 1);
|
|
expect(
|
|
ruleExportTokenMatches("rule-1", token, pepper, 0, afterExpiry),
|
|
).toBe(false);
|
|
});
|
|
});
|