47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { deepRedactMessage } from "../../src/core/export";
|
|
import { parseMessage } from "../../src/core/mime";
|
|
|
|
describe("deep redaction", () => {
|
|
it("redacts nested headers, text bodies, and attachment payloads", () => {
|
|
const message = parseMessage(`From: root@example.test
|
|
Received: private-root
|
|
Content-Type: multipart/mixed; boundary=x
|
|
|
|
--x
|
|
Content-Type: message/rfc822
|
|
|
|
From: nested@example.test
|
|
Received: private-nested
|
|
Content-Type: text/plain
|
|
|
|
Nested secret
|
|
--x
|
|
Content-Type: application/octet-stream; name="secret.bin"
|
|
Content-Disposition: attachment; filename="secret.bin"
|
|
Content-Transfer-Encoding: base64
|
|
|
|
AQIDBA==
|
|
--x--
|
|
`);
|
|
const result = deepRedactMessage(message, {
|
|
redactTextBodies: true,
|
|
removeAttachmentPayloads: true,
|
|
});
|
|
expect(result.output).not.toMatch(
|
|
/private-root|private-nested|Nested secret|AQIDBA/iu,
|
|
);
|
|
expect(result.output).toContain(
|
|
"W0F0dGFjaG1lbnQgcGF5bG9hZCByZW1vdmVkIGxvY2FsbHkuXQ",
|
|
);
|
|
expect(result.removedHeaders).toHaveLength(2);
|
|
expect(result.redactedTextParts).toEqual(["1.1"]);
|
|
expect(result.removedAttachments).toMatchObject([
|
|
{ part: "2", filename: "secret.bin", bytes: 4 },
|
|
]);
|
|
expect(JSON.parse(result.report)).toMatchObject({
|
|
operation: "mail-deep-redaction",
|
|
});
|
|
});
|
|
});
|