@@ -0,0 +1,46 @@
|
||||
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",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user