Files
reverse-engineering-anything/src/native/NativePlistResourceRoot.test.ts
T
8c7977f174 fix(native)!: require separate inspection for plists outside bundles (#9754)
* fix(native): record inspected plist bytes and refuse files outside the bundle

An open app session keeps the executable as the Evidence subject for
inspect_plist, same as the other bundle-resource tools, but the result had
no digest of the plist bytes and any absolute path was sealed under that
subject. Record source_sha256 for the bytes read, and refuse a selection
that resolves outside the opened bundle.

Fixes #9479

* fix(native)!: scope plist selection to the opened bundle

BREAKING CHANGE: To inspect a plist outside an opened app bundle or resource root, open the plist as a separate target.

* fix(native): report plist snapshot filesystem effects

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-11-19 21:35:17 -05:00

83 lines
3.0 KiB
TypeScript

import { join } from "node:path";
import { expect, it, onTestFinished } from "vitest";
import { NativeMacOSProvider } from "./NativeMacOSProvider.js";
import { resolveBundleResourcePlistSelection } from "./NativePlistSource.js";
import { NativeFixtureRunner } from "../../tests/fixtures/nativeCommands.js";
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
import { mkdir, readFile, symlink, writeFile } from "node:fs/promises";
it("inspects a resolved app plist without executable identity", async () => {
const bundle = await createTestTempDirectory("rea-plist-resource-root-");
const infoPlist = join(bundle, "Info.plist");
await writeFile(infoPlist, '<?xml version="1.0"?><plist><dict/></plist>');
const root = {
callerPath: bundle,
canonicalPath: bundle,
infoPlistPath: infoPlist,
layout: "root" as const,
executableSha256: null,
};
expect(resolveBundleResourcePlistSelection(root, undefined)).toEqual({
ok: true,
value: { path: infoPlist, origin: "default", bundleRoot: bundle },
});
expect(resolveBundleResourcePlistSelection(root, "Info.plist")).toEqual({
ok: true,
value: { path: infoPlist, origin: "selected", bundleRoot: bundle },
});
const client = new NativeMacOSProvider(
{},
new NativeFixtureRunner(),
"darwin",
).createBundleResourceClient(root);
onTestFinished(async () => {
await client.close();
});
const inspected = await client.execute("inspect_plist", {});
expect(inspected.ok).toBe(true);
if (inspected.ok)
expect(inspected.value.result).toMatchObject({
source_path: infoPlist,
resource_root: {
canonical_path: bundle,
executable_sha256: null,
},
});
});
it.skipIf(process.platform === "win32")(
"preserves physical selected plist paths in resource-only roots",
async () => {
const bundle = await createTestTempDirectory("rea-plist-resource-path-");
const physical = join(bundle, "physical");
await mkdir(join(physical, "child"), { recursive: true });
await writeFile(join(bundle, "Info.plist"), "lexical decoy");
await writeFile(join(physical, "Info.plist"), "selected source");
await symlink(join(physical, "child"), join(bundle, "alias"));
const root = {
callerPath: bundle,
canonicalPath: bundle,
infoPlistPath: join(bundle, "Info.plist"),
layout: "root" as const,
executableSha256: null,
};
for (const requested of [
"alias/../Info.plist",
`${bundle}/alias/../Info.plist`,
"physical/Info.plist",
]) {
const selected = resolveBundleResourcePlistSelection(root, requested);
if (!selected.ok) throw selected.error;
expect(selected.value.origin).toBe("selected");
expect(await readFile(selected.value.path, "utf8")).toBe(
"selected source",
);
}
const directory = resolveBundleResourcePlistSelection(root, "Info.plist/");
if (!directory.ok) throw directory.error;
await expect(readFile(directory.value.path)).rejects.toMatchObject({
code: "ENOTDIR",
});
},
);