Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { serveCli } from "./cliServeHarness.js";
|
||||
import { expectConfigurationRefusal, serveCli } from "./cliServeHarness.js";
|
||||
|
||||
it.each(["inspect-pcap-client", "inspect-pcap-capture"])(
|
||||
"%s advertises a schema through the public CLI",
|
||||
@@ -11,13 +11,27 @@ it.each(["inspect-pcap-client", "inspect-pcap-capture"])(
|
||||
},
|
||||
);
|
||||
|
||||
it("reports missing tools with a capability refusal", async () => {
|
||||
const result = await serveCli(
|
||||
["inspect-pcap-capture", "/nonexistent/capture.pcap", "--json"],
|
||||
{
|
||||
REA_TSHARK_COMMAND: "/nonexistent/tshark",
|
||||
REA_CAPINFOS_COMMAND: "/nonexistent/capinfos",
|
||||
},
|
||||
it.each([
|
||||
["inspect-pcap-client"],
|
||||
["inspect-pcap-capture", "/nonexistent/capture.pcap"],
|
||||
])("%s names the missing Wireshark tool to configure", async (...argv) => {
|
||||
const result = await serveCli([...argv, "--json"], {
|
||||
REA_TSHARK_COMMAND: "/nonexistent/tshark",
|
||||
REA_CAPINFOS_COMMAND: "/nonexistent/capinfos",
|
||||
});
|
||||
expectConfigurationRefusal(
|
||||
result,
|
||||
"Cannot run selected tool /nonexistent/tshark",
|
||||
);
|
||||
expectConfigurationRefusal(result, "through absolute REA_TSHARK_COMMAND");
|
||||
});
|
||||
|
||||
it("names a relative tool selection as configuration to fix", async () => {
|
||||
const result = await serveCli(["inspect-pcap-client", "--json"], {
|
||||
REA_TSHARK_COMMAND: "tshark",
|
||||
});
|
||||
expectConfigurationRefusal(
|
||||
result,
|
||||
"REA_TSHARK_COMMAND must be an absolute path to the tshark binary",
|
||||
);
|
||||
expect(result.stdout).toContain("capability_unavailable");
|
||||
});
|
||||
|
||||
@@ -246,12 +246,37 @@ it("reports relative configuration and missing capinfos as capability gaps", asy
|
||||
input: {},
|
||||
});
|
||||
if (result.ok) throw new Error("expected unavailable tools");
|
||||
expect(projectAnalysisError(result.error).code).toBe(
|
||||
"capability_unavailable",
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected.code).toBe("capability_unavailable");
|
||||
expect(projected.message).toContain(
|
||||
"Supply Wireshark 4.x tshark and capinfos",
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("names the prlimit selection when the Linux limiter is unusable", async () => {
|
||||
const root = await createTestTempDirectory("rea-pcap-prlimit-");
|
||||
const tools = await writeStubTools(root);
|
||||
const provider = new PcapProvider({
|
||||
environment: {
|
||||
REA_TSHARK_COMMAND: tools.tshark,
|
||||
REA_CAPINFOS_COMMAND: tools.capinfos,
|
||||
REA_TSHARK_PRLIMIT_COMMAND: "relative/prlimit",
|
||||
},
|
||||
});
|
||||
onTestFinished(() => provider.close());
|
||||
const result = await provider.execute({
|
||||
operation: "inspect_pcap_capture",
|
||||
input: { path: "/not-opened/capture.pcap" },
|
||||
});
|
||||
if (result.ok) throw new Error("expected an unusable limiter");
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected.code).toBe("capability_unavailable");
|
||||
expect(projected.message).toContain(
|
||||
"(REA_TSHARK_PRLIMIT_COMMAND must be absolute.) Check that REA_TSHARK_PRLIMIT_COMMAND",
|
||||
);
|
||||
});
|
||||
|
||||
const nodeTool = async (
|
||||
root: string,
|
||||
name: string,
|
||||
|
||||
@@ -87,17 +87,22 @@ it.runIf(hasNativeBound)(
|
||||
},
|
||||
);
|
||||
|
||||
it("rejects a path that is not a readable file", async () => {
|
||||
const result = await providerOver().execute({
|
||||
operation: "inspect_pcap_capture",
|
||||
input: { path: "/nonexistent/definitely-missing.pcap" },
|
||||
});
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) return;
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "invalid_request",
|
||||
});
|
||||
});
|
||||
// Hosts without a native bound refuse before touching the path; that order
|
||||
// is pinned by the unsupported-boundary test below.
|
||||
it.runIf(hasNativeBound)(
|
||||
"rejects a path that is not a readable file",
|
||||
async () => {
|
||||
const result = await providerOver().execute({
|
||||
operation: "inspect_pcap_capture",
|
||||
input: { path: "/nonexistent/definitely-missing.pcap" },
|
||||
});
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) return;
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "invalid_request",
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("reports a missing binary as a capability gap", async () => {
|
||||
const provider = new PcapProvider({
|
||||
@@ -136,9 +141,13 @@ it.runIf(!hasNativeBound)(
|
||||
input: { path: "/not-opened/capture.pcap" },
|
||||
});
|
||||
expect(result.ok).toBe(false);
|
||||
if (!result.ok)
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "capability_unavailable",
|
||||
});
|
||||
if (result.ok) return;
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected.code).toBe("capability_unavailable");
|
||||
// The refusal concerns this host, so it must not suggest another target.
|
||||
expect(projected.message).toContain(
|
||||
"Linux with util-linux prlimit, or Windows with owned Job Objects",
|
||||
);
|
||||
expect(projected.remediation.action).toBe(projected.message);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user