* refactor: apply biome formatting to small packages + packages/lib Format packages/sms, packages/prisma, packages/platform/libraries, packages/platform/examples, packages/platform/types, packages/emails, and packages/lib. Excludes packages/platform/examples/base/src/pages/[bookingUid].tsx due to pre-existing lint errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * revert: remove packages/platform formatting changes Revert biome formatting for packages/platform as requested. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
34 lines
1.2 KiB
TypeScript
34 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));
|
|
});
|
|
});
|