Files
reverse-engineering-anything/src/adb/AdbConfiguration.test.ts
T
RRFZ 23adfc610f fix(process): require a drive or UNC root for selected Windows tools (#11786)
* fix(process): require a drive or UNC root for selected Windows tools

REA_ADB_PATH, REA_APKTOOL_COMMAND, REA_TSHARK_COMMAND and
REA_CAPINFOS_COMMAND must be absolute. On Windows the check used
win32.isAbsolute, which also accepts \tools\adb.exe: a path rooted on
the current drive. Such a setting names a different file depending on
REA's working drive, and the owned Windows launcher refuses it.

Add isQualifiedCallerPath to the caller-path owner, which on Windows
requires a drive root or a UNC or device root, and use it for all four
settings. POSIX keeps posix.isAbsolute.

* fix(filesystem): require a complete UNC root for a qualified Windows path

Two leading separators were treated as a UNC root, so ///tools/adb.exe,
\\\tools\adb.exe and a bare \\server passed, though win32 parses them
with a single-separator root on the current drive. Use win32's own root:
qualified only when the path is absolute and its root is longer than one
separator.

* test(process): use qualified paths for simulated Windows tools
2026-11-18 10:09:30 -05:00

87 lines
2.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
ADB_BINARY_ENV,
parseAdbVersionOutput,
resolveAdbBinary,
} from "./AdbConfiguration.js";
describe("resolveAdbBinary", () => {
it("prefers an absolute REA_ADB_PATH", async () => {
expect(
await resolveAdbBinary({ [ADB_BINARY_ENV]: "/opt/tools/adb" }, "linux"),
).toEqual({
binary: "/opt/tools/adb",
pathSource: "environment",
environment: { [ADB_BINARY_ENV]: "/opt/tools/adb" },
});
});
it.skipIf(process.platform === "win32")(
"falls back to POSIX PATH resolution without the environment key",
async () => {
expect(await resolveAdbBinary({}, "linux")).toEqual({
binary: "adb",
pathSource: "path",
environment: {},
});
expect(
await resolveAdbBinary({ [ADB_BINARY_ENV]: " " }, "linux"),
).toEqual({
binary: "adb",
pathSource: "path",
environment: { [ADB_BINARY_ENV]: " " },
});
},
);
it("does not defer a missing Windows PATH selection to process creation", async () => {
await expect(
resolveAdbBinary({ Path: "", PathExt: ".EXE" }, "win32"),
).rejects.toMatchObject({ code: "binary_missing" });
});
it("rejects a relative environment path explicitly", async () => {
await expect(
resolveAdbBinary({ [ADB_BINARY_ENV]: "tools/adb" }, "linux"),
).rejects.toThrow(/must be an absolute path/u);
// Rooted on the current drive, so it names a different file per drive.
await expect(
resolveAdbBinary({ [ADB_BINARY_ENV]: "\\tools\\adb.exe" }, "win32"),
).rejects.toThrow(/must be an absolute path/u);
});
});
describe("parseAdbVersionOutput", () => {
it("reads the build version and install path from real output", () => {
expect(
parseAdbVersionOutput(
[
"Android Debug Bridge version 1.0.41",
"Version 34.0.5-debian",
"Installed as /usr/lib/android-sdk/platform-tools/adb",
"",
].join("\n"),
),
).toEqual({
version: "34.0.5-debian",
installedPath: "/usr/lib/android-sdk/platform-tools/adb",
});
});
it("reports null identity fields when the named lines are absent", () => {
expect(parseAdbVersionOutput("unexpected output")).toEqual({
version: null,
installedPath: null,
});
});
it("does not accept arbitrary successful output as an adb version", () => {
expect(
parseAdbVersionOutput(
"Android Debug Bridge version tomorrow\nVersion unknown\n",
),
).toMatchObject({ version: null });
});
});