Files
reverse-engineering-anything/tests/boundary/filesystem/keyedArchiveXmlSyntax.test.ts
T
morluto c7e9e096d3 fix(plist): reject malformed XML before value decoding
Reuse the shared validated XML document for depth and prototype-key preflight, preventing recovery-only values from being projected as observations. Preserve OpenStep and valid XML source semantics.

Validation: 46 focused checks; 5 final syntax controls; 10 encoding and public CLI/MCP overlap checks; check:fast. Public malformed-entity CLI changed from success to typed format failure. Generated inert artifacts only; no real Apple application or native engine execution.

Refs #4714
2026-10-17 15:24:57 +08:00

69 lines
2.2 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { build } from "plist";
import { expect, it } from "vitest";
import { inspectBundleKeyedArchive } from "../../../src/artifacts/apple/KeyedArchiveReader.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const archive = build({
$archiver: "NSKeyedArchiver",
$version: 100000,
$objects: ["$null", "value"],
$top: { root: { UID: 1 } },
});
it.each([
{
name: "unquoted attribute",
xml: archive.replace('version="1.0">', "version=1.0>"),
},
{
name: "undeclared entity",
xml: archive.replace(
"<string>value</string>",
"<string>&unknown;</string>",
),
},
{
name: "forbidden character reference",
xml: archive.replace("<string>value</string>", "<string>&#0;</string>"),
},
{
name: "forbidden literal character",
xml: archive.replace("<string>value</string>", "<string>\u0000</string>"),
},
])("refuses $name before registering archive observations", async ({ xml }) => {
const root = await createTestTempDirectory("rea-keyed-xml-syntax-");
await writeFile(join(root, "Archive.plist"), xml);
await expect(
inspectBundleKeyedArchive({
bundlePath: root,
targetSha256: "a".repeat(64),
parameters: { path: "Archive.plist" },
}),
).rejects.toMatchObject({
reason: "format",
cause: { _tag: "XmlDocumentParseError", reason: "malformed" },
});
});
it("preserves valid Unicode, entity values and original archive identities", async () => {
const root = await createTestTempDirectory("rea-keyed-xml-valid-");
await writeFile(
join(root, "Archive.plist"),
archive.replace("<string>value</string>", "<string>� &amp; &#13;</string>"),
);
const result = await inspectBundleKeyedArchive({
bundlePath: root,
targetSha256: "a".repeat(64),
parameters: { path: "Archive.plist", offset: 1, limit: 1 },
});
expect(result.roots).toEqual({ root: { UID: 1 } });
expect(result.objects).toEqual([
expect.objectContaining({ id: 1, status: "observed", value: "� & \r" }),
]);
expect(result.total_objects).toBe(2);
expect(result.next_offset).toBeNull();
expect(result.truncated).toBe(true);
});