mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 05:07:49 +00:00
With the working directory removed and PATH starting with "." or an empty entry, the lookup stopped at that entry with no-working-directory. A spawned search finds nothing under a removed directory and moves on, so the command still ran a later match by its bare name, while Evidence reported an assumed identity without path, digest or version. The lookup now skips such an entry and reports the unread working directory only when no later entry matches; an explicit relative command still reports it at once.
118 lines
4.0 KiB
TypeScript
118 lines
4.0 KiB
TypeScript
import { delimiter, dirname } from "node:path";
|
|
|
|
import { expect, it, vi } from "vitest";
|
|
|
|
import { lookupExecutable } from "../../src/process/ExecutableLookup.js";
|
|
import { TestReverseEngineeringService } from "../support/reverseEngineeringService.js";
|
|
import {
|
|
rizinExecutableFixture,
|
|
versionProbeCount,
|
|
versionProbeRunner,
|
|
} from "../support/rizinToolIdentity.js";
|
|
|
|
// The selected executable is a POSIX mode-0755 file; Windows resolves
|
|
// REA_RIZIN_COMMAND separately and is not covered here.
|
|
const posix = it.skipIf(process.platform === "win32");
|
|
|
|
/** As when the server's working directory has been removed. */
|
|
const unreadableWorkingDirectory = () =>
|
|
vi.spyOn(process, "cwd").mockImplementation(() => {
|
|
throw Object.assign(new Error("uv_cwd"), { code: "ENOENT" });
|
|
});
|
|
|
|
posix(
|
|
"identifies and runs an absolute command and target without reading the working directory",
|
|
async () => {
|
|
const { executable, path } = await rizinExecutableFixture();
|
|
const run = versionProbeRunner(() => "rizin 0.9.1 @ linux-x86-64");
|
|
const service = new TestReverseEngineeringService({
|
|
run,
|
|
lookup: lookupExecutable,
|
|
// A relative PATH entry is not searched for an explicit command.
|
|
environment: { REA_RIZIN_COMMAND: executable, PATH: "bin" },
|
|
});
|
|
const cwd = unreadableWorkingDirectory();
|
|
try {
|
|
const result = await service.executeRizinCommand({ path, command: "iI" });
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.provider.version).toBe("0.9.1");
|
|
expect(result.value.parameters).toMatchObject({
|
|
provider_executable_path: executable,
|
|
provider_identity: "banner",
|
|
});
|
|
expect(cwd).not.toHaveBeenCalled();
|
|
} finally {
|
|
cwd.mockRestore();
|
|
}
|
|
},
|
|
);
|
|
|
|
posix.each([
|
|
["before", false],
|
|
["after", true],
|
|
] as const)(
|
|
"identifies a PATH match %s a relative entry whose working directory cannot be read",
|
|
async (_order, relativeFirst) => {
|
|
const { executable, path } = await rizinExecutableFixture();
|
|
const run = versionProbeRunner(() => "rizin 0.9.1 @ linux-x86-64");
|
|
const service = new TestReverseEngineeringService({
|
|
run,
|
|
lookup: lookupExecutable,
|
|
environment: {
|
|
REA_RIZIN_COMMAND: "rizin",
|
|
PATH: relativeFirst
|
|
? `.${delimiter}${dirname(executable)}`
|
|
: `${dirname(executable)}${delimiter}.`,
|
|
},
|
|
});
|
|
const cwd = unreadableWorkingDirectory();
|
|
try {
|
|
const result = await service.executeRizinCommand({ path, command: "iI" });
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.provider.version).toBe("0.9.1");
|
|
expect(result.value.parameters).toMatchObject({
|
|
provider_executable_path: executable,
|
|
provider_identity: "banner",
|
|
});
|
|
// A relative entry before the match is reached and skipped.
|
|
expect(cwd).toHaveBeenCalledTimes(relativeFirst ? 1 : 0);
|
|
} finally {
|
|
cwd.mockRestore();
|
|
}
|
|
},
|
|
);
|
|
|
|
posix.each([
|
|
["a relative command", { REA_RIZIN_COMMAND: "bin/rizin" }],
|
|
["a relative PATH entry", { REA_RIZIN_COMMAND: "rizin", PATH: "bin" }],
|
|
] as const)(
|
|
"returns a result when %s needs a working directory that cannot be read",
|
|
async (_case, environment) => {
|
|
const { path } = await rizinExecutableFixture();
|
|
const run = versionProbeRunner(() => "rizin 0.9.1 @ linux-x86-64");
|
|
const service = new TestReverseEngineeringService({
|
|
run,
|
|
lookup: lookupExecutable,
|
|
environment,
|
|
});
|
|
const cwd = unreadableWorkingDirectory();
|
|
try {
|
|
const result = await service.executeRizinCommand({ path, command: "iI" });
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.provider).toEqual({
|
|
id: "rizin",
|
|
name: "Rizin",
|
|
version: null,
|
|
});
|
|
expect(result.value.parameters.provider_identity).toBe("assumed");
|
|
expect(result.value.parameters).not.toHaveProperty(
|
|
"provider_executable_path",
|
|
);
|
|
expect(versionProbeCount(run)).toBe(0);
|
|
expect(cwd).toHaveBeenCalled();
|
|
} finally {
|
|
cwd.mockRestore();
|
|
}
|
|
},
|
|
);
|