feat(0pt): record legitimate-interest stance — B2B contacts, company-linked only
Recorded decision (Simon 2026-08-31): personal data may be stored under legitimate interest ONLY as business contacts bound to a company/org entity. Gate enforces it: legitimate_interest requires purpose=business_contact and entity_linked_only=true; recordStored() requires entity_id (orgnr/rgs/LEI, hashed) and refuses person-only rows. +1 test; suite 167 pass | 1 skip; typecheck clean.
This commit is contained in:
@@ -53,6 +53,34 @@ describe("PiiGateService — GDPR guardrail (fail-closed)", () => {
|
||||
).rejects.toThrow(/data minimisation/);
|
||||
});
|
||||
|
||||
it("enforces the recorded decision: legitimate_interest = B2B business contact, company-linked only", async () => {
|
||||
const gate = new PiiGateService();
|
||||
await expect(
|
||||
gate.createPiiPolicy({ source_id: "s_li_wrong", tenant_id: "t1", project_id: "p1", legal_basis: "legitimate_interest", basis_ref: "lia-2026-001", retention_days: 90, field_allowlist: ["email"], purpose: "consent_marketing" }),
|
||||
).rejects.toThrowError(/only accepted with purpose=business_contact/);
|
||||
await expect(
|
||||
gate.createPiiPolicy({ source_id: "s_li_wrong2", tenant_id: "t1", project_id: "p1", legal_basis: "legitimate_interest", basis_ref: "lia-2026-001", retention_days: 90, field_allowlist: ["email"], entity_linked_only: false }),
|
||||
).rejects.toThrowError(/entity_linked_only=true/);
|
||||
|
||||
await gate.createPiiPolicy({
|
||||
source_id: "s_li_ok", tenant_id: "t1", project_id: "p1",
|
||||
legal_basis: "legitimate_interest", basis_ref: "lia-2026-b2b-01",
|
||||
retention_days: 365, field_allowlist: ["email", "phone"],
|
||||
});
|
||||
const p = await gate.getPiiPolicy("s_li_ok");
|
||||
expect(p?.purpose).toBe("business_contact");
|
||||
expect(p?.entity_linked_only).toBe(true);
|
||||
|
||||
// Business contact must be bound to a company — stray person-only rows are refused.
|
||||
const liSource = { ...company, source_id: "s_li_ok" };
|
||||
await expect(
|
||||
gate.recordStored({ source: liSource, tenantId: "t1", identityKey: "k", subjectId: "s", field: "email" }),
|
||||
).rejects.toThrowError(/entity linkage/);
|
||||
const linked = await gate.recordStored({ source: liSource, tenantId: "t1", identityKey: "k", subjectId: "s", field: "email", entityId: "556677-8899" });
|
||||
expect(linked.entity_hash).toMatch(/^[0-9a-f]{64}$/);
|
||||
expect(linked.entity_hash).not.toContain("556677");
|
||||
});
|
||||
|
||||
it("blocks out-of-allowlist fields (minimisation) and unconfirmed web sources", async () => {
|
||||
const gate = new PiiGateService();
|
||||
await gate.createPiiPolicy({
|
||||
@@ -117,7 +145,7 @@ describe("PiiGateService — GDPR guardrail (fail-closed)", () => {
|
||||
legal_basis: "legitimate_interest", basis_ref: "lia-2026-002",
|
||||
retention_days: 30, field_allowlist: ["street_address"], robots_and_rate_confirmed: true,
|
||||
});
|
||||
await gate.recordStored({ source: ratsit, tenantId: "t1", identityKey: "k-1", subjectId: "s-1", field: "street_address" });
|
||||
await gate.recordStored({ source: ratsit, tenantId: "t1", identityKey: "k-1", subjectId: "s-1", field: "street_address", entityId: "5566778899" });
|
||||
|
||||
vi.setSystemTime(new Date("2026-09-15T00:00:00Z"));
|
||||
const { purged } = await gate.enforceRetention(new Date("2026-09-15T00:00:00Z"));
|
||||
|
||||
Reference in New Issue
Block a user