Files
reverse-engineering-anything/tests/acceptance/applications/adbErrorIdentity.test.ts
T
morluto cad578e74a fix(adb): refuse device directories before pulling (#15433)
* fix(adb): refuse device directories before pulling

adb pull copies a directory tree with no byte limit. pull_adb_file accepted
a directory device_path (for example /sdcard), and pull_adb_package accepted
a pm path line naming a directory; adb then pulled the whole tree under the
600 s timeout, the tool reported that the result could not be read back, and
the tree stayed on disk unrecorded.

Both pulls now run the existing test -d probe that push already uses.
pull_adb_file refuses a directory as invalid_request on device_path and
names list_adb_directory; pull_adb_package refuses a pm path directory with
reason directory_device_path before creating output. A probe that cannot
establish the answer fails the call rather than pulling.

Refs #15326

* fix(adb): keep the pm path answer when a directory probe fails

A failed directory probe now retains the completed pm path paths and the
entry being checked as a partial observation, and the pull_adb_file
directory refusal escapes the device path for display.
2026-12-01 01:42:08 -05:00

105 lines
3.6 KiB
TypeScript

import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect } from "vitest";
import {
expectAdapterErrorParity,
parseMcpToolError,
} from "../../fixtures/mcpToolError.js";
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
cliTest.skipIf(process.platform === "win32")(
"keeps device, remote file and host file refusals distinct through CLI and MCP",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-adb-error-identity-");
const binary = join(root, "adb");
const source = join(root, "source.bin");
await writeFile(source, "caller bytes");
await writeFile(
binary,
`#!${process.execPath}
const args = process.argv.slice(2);
if (args[0] === 'start-server') process.exit(0);
if (args[0] === 'version') {
console.log('Android Debug Bridge version 1.0.41\\nVersion 34.0.5-fixture\\nInstalled as ' + process.argv[1]);
process.exit(0);
}
if (args[0] !== '-s' || args[1] !== 'device') process.exit(91);
// The pull scenarios' device paths are files; the push scenario stays offline.
if (args[2] === 'shell' && args[3] === 'test' && args[5] !== '/sdcard/offline.bin') process.exit(1);
if (args[2] === 'shell') console.error('adb: error: connect failed: device offline');
else if (args[2] === 'pull' && args[3] === '/sdcard/host.bin')
console.error("adb: error: cannot write '" + args[4] + "': Permission denied");
else if (args[2] === 'pull')
console.error("adb: error: failed to stat remote object '" + args[3] + "': No such file or directory");
else process.exit(91);
process.exit(1);
`,
{ mode: 0o700 },
);
const environment = {
HOME: root,
USERPROFILE: root,
REA_ADB_PATH: binary,
REA_LOG_LEVEL: "silent",
};
const { client, call } = await connectLocalToolsMcp(environment);
for (const scenario of [
{
file: "missing.bin",
operation: "pull_adb_file",
path: "/sdcard/missing.bin",
},
{
file: `${"directory/".repeat(60)}long.bin`,
operation: "pull_adb_file",
path: `/sdcard/${"directory/".repeat(60)}long.bin`,
},
{
file: "host.bin",
operation: "pull_adb_file",
path: join(root, "host.bin"),
},
{ file: "offline.bin", operation: "push_adb_file", path: "device" },
] as const) {
const devicePath = `/sdcard/${scenario.file}`;
const transfer =
scenario.operation === "pull_adb_file"
? {
arguments: [devicePath, "--output-directory", root],
input: { output_directory: root },
}
: { arguments: [source, devicePath], input: { local_path: source } };
const output = await cli.run({
arguments: [
scenario.operation.replaceAll("_", "-"),
"device",
...transfer.arguments,
"--json",
],
environment,
});
expect(output.exitCode, output.stderr).toBe(1);
expect(output.json).toMatchObject({
code: "unsupported_target",
details: { operation: scenario.operation, path: scenario.path },
});
const reply = await call(scenario.operation, {
serial: "device",
device_path: devicePath,
...transfer.input,
});
expectAdapterErrorParity(
parseMcpToolError(reply).error,
output.json,
scenario.operation,
);
await client.ping();
}
expect(await readFile(source, "utf8")).toBe("caller bytes");
},
);