* chore: Add system wide rate limiting * Handle and convert HttpError to 429 * Make algo 32-bit to prevent <ES2020 error + fix sms manager unit test * Change core to common to go from 10 requests per minute to 200 * Remove redundant function * Fix integration tests * Make sure we allow all legal POST routes * Allow tRPC post calls * Add matcher tests on middleware * Add matcher tests on middleware * Fix matcher to not use regex * Fix missing POST allow rule for /api/auth/callback/credentials * Missed the api/book/event endpoints * Add missing pages/api routes * Remove POST middleware for now, very risky * Remove tests for POST protection --------- Co-authored-by: Volnei Munhoz <volnei.munhoz@gmail.com>
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { hashEmail, Md5PiiHasher } from "./PiiHasher";
|
|
|
|
describe("PII Hasher Test Suite", () => {
|
|
|
|
const hasher = new Md5PiiHasher("test-salt");
|
|
|
|
it("can hash email addresses deterministically and preserve domain", async () => {
|
|
const email = "sensitive_data@example.com";
|
|
const hashedEmail = hashEmail(email, hasher);
|
|
// Domain must be preserved
|
|
expect(hashedEmail.endsWith("@example.com")).toBe(true);
|
|
// Local part should change
|
|
expect(hashedEmail.split("@")[0]).not.toBe("sensitive_data");
|
|
// Deterministic
|
|
expect(hashEmail(email, hasher)).toBe(hashedEmail);
|
|
});
|
|
|
|
it("can hash PII deterministically to a 128-bit hex string", async () => {
|
|
const pii = "sensitive_data";
|
|
const hashedPii = hasher.hash(pii);
|
|
// 128-bit hex (32 hex chars)
|
|
expect(hashedPii).toMatch(/^[0-9a-f]{32}$/);
|
|
// Deterministic
|
|
expect(hasher.hash(pii)).toBe(hashedPii);
|
|
});
|
|
|
|
it("handles hashing with different salt", () => {
|
|
const differentHasher = new Md5PiiHasher("different-salt");
|
|
const pii = "sensitive_data";
|
|
const hashedPii = differentHasher.hash(pii);
|
|
expect(hashedPii).not.toBe(hasher.hash(pii));
|
|
});
|
|
});
|