fix(plist): decode formatted XML dictionary keys
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import {
|
||||
expectKeyedArchivePrototypeKeys,
|
||||
keyedArchivePrototypeKeyFixture,
|
||||
} from "../../fixtures/keyedArchivePrototypeKeys.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
cliTest(
|
||||
"compiled CLI decodes formatted XML prototype keys",
|
||||
async ({ cli }) => {
|
||||
const fixture = await keyedArchivePrototypeKeyFixture();
|
||||
const output = await cli.run({
|
||||
arguments: ["inspect-keyed-archive", fixture.path, "--json"],
|
||||
environment: { REA_LOG_LEVEL: "silent", REA_ANALYSIS_PROVIDER: "auto" },
|
||||
});
|
||||
expect(output.exitCode, output.stderr).toBe(0);
|
||||
expectKeyedArchivePrototypeKeys(
|
||||
parseEvidence(output.json).normalized_result,
|
||||
fixture.digest,
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,49 @@
|
||||
import { expect } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createBinarySession } from "../../../src/composition/binary.js";
|
||||
import { parseConfig } from "../../../src/config/parseConfig.js";
|
||||
import { keyedArchiveResultSchema } from "../../../src/domain/apple/keyedArchive.js";
|
||||
import { silentLogger } from "../../../src/logger.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import {
|
||||
expectKeyedArchivePrototypeKeys,
|
||||
keyedArchivePrototypeKeyFixture,
|
||||
} from "../../fixtures/keyedArchivePrototypeKeys.js";
|
||||
import { mcpTest } from "../../support/mcp/mcpFixture.js";
|
||||
|
||||
mcpTest(
|
||||
"MCP retains ordinary evidence with formatted XML prototype keys",
|
||||
async ({ mcp, onTestFinished }) => {
|
||||
const fixture = await keyedArchivePrototypeKeyFixture();
|
||||
const configured = parseConfig({ REA_ANALYSIS_PROVIDER: "auto" });
|
||||
if (!configured.ok) throw configured.error;
|
||||
const session = createBinarySession(
|
||||
configured.value,
|
||||
silentLogger,
|
||||
process.env,
|
||||
);
|
||||
onTestFinished(async () => {
|
||||
await session.close();
|
||||
});
|
||||
const client = await mcp.connect(
|
||||
createServer({ kind: "session", session }),
|
||||
);
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: fixture.path },
|
||||
});
|
||||
expect(opened.isError, JSON.stringify(opened.content)).not.toBe(true);
|
||||
const result = await client.callTool({
|
||||
name: "inspect_keyed_archive",
|
||||
arguments: {},
|
||||
});
|
||||
expect(result.isError, JSON.stringify(result.content)).not.toBe(true);
|
||||
expectKeyedArchivePrototypeKeys(
|
||||
z
|
||||
.object({ normalized_result: keyedArchiveResultSchema })
|
||||
.parse(result.structuredContent).normalized_result,
|
||||
fixture.digest,
|
||||
);
|
||||
},
|
||||
);
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { keyedArchiveResultSchema } from "../../src/domain/apple/keyedArchive.js";
|
||||
import { createTestTempDirectory } from "./temporaryDirectory.js";
|
||||
|
||||
/** Inert XML with producer-equivalent key spellings and unchanged ordinary data. */
|
||||
export const keyedArchivePrototypeKeyFixture = async () => {
|
||||
const directory = await createTestTempDirectory("rea-keyed-xml-keys-");
|
||||
const path = join(directory, "archive.plist");
|
||||
const bytes = Buffer.from(`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plist version="1.0"><dict>
|
||||
<key>$archiver</key><string>NSKeyedArchiver</string>
|
||||
<key>$version</key><integer>100000</integer>
|
||||
<key>$objects</key><array><string>$null</string><dict>
|
||||
<key >__proto__</key ><string>omitted outer value</string>
|
||||
<key>kept</key><string>a b…c
d</string>
|
||||
<key>__rea_prototype_key__</key><string>ordinary key</string>
|
||||
<key>nested</key><dict>
|
||||
<key><![CDATA[__proto__]]><!-- trailing comment --></key>
|
||||
<string>omitted nested value</string>
|
||||
<key>value</key><integer>7</integer>
|
||||
</dict>
|
||||
</dict></array>
|
||||
<key>$top</key><dict><key>root</key><dict>
|
||||
<key>CF$UID</key><integer>1</integer>
|
||||
</dict></dict>
|
||||
</dict></plist>`);
|
||||
await writeFile(path, bytes);
|
||||
return { path, digest: createHash("sha256").update(bytes).digest("hex") };
|
||||
};
|
||||
|
||||
/** Require original source identity, ordinary values and the exact omission count. */
|
||||
export const expectKeyedArchivePrototypeKeys = (
|
||||
value: unknown,
|
||||
digest: string,
|
||||
) => {
|
||||
const result = keyedArchiveResultSchema.parse(value);
|
||||
expect(result.archive_sha256).toBe(digest);
|
||||
expect(result.roots).toEqual({ root: { CF$UID: 1 } });
|
||||
expect(result.objects).toHaveLength(2);
|
||||
expect(result.objects[1]).toMatchObject({
|
||||
id: 1,
|
||||
kind: "dictionary",
|
||||
value: {
|
||||
kept: "a\rb\u0085c\u2028d",
|
||||
__rea_prototype_key__: "ordinary key",
|
||||
nested: { value: 7 },
|
||||
},
|
||||
});
|
||||
expect(result.limitations).toContain(
|
||||
"2 dictionary entries keyed __proto__ were omitted because REA results cannot represent that key.",
|
||||
);
|
||||
expect(JSON.stringify(result)).not.toContain("omitted outer value");
|
||||
expect(JSON.stringify(result)).not.toContain("omitted nested value");
|
||||
};
|
||||
Reference in New Issue
Block a user