mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 04:11:22 +00:00
test(exec): add regressions for safe-bin metadata and chain semantics
This commit is contained in:
@@ -680,6 +680,71 @@ describe("exec approvals allowlist evaluation", () => {
|
||||
expect(result.allowlistSatisfied).toBe(false);
|
||||
expect(result.segmentSatisfiedBy).toEqual([null]);
|
||||
});
|
||||
|
||||
it("returns empty segment details for chain misses", () => {
|
||||
const segment = {
|
||||
raw: "tool",
|
||||
argv: ["tool"],
|
||||
resolution: {
|
||||
rawExecutable: "tool",
|
||||
resolvedPath: "/usr/bin/tool",
|
||||
executableName: "tool",
|
||||
},
|
||||
};
|
||||
const analysis = {
|
||||
ok: true,
|
||||
segments: [segment],
|
||||
chains: [[segment]],
|
||||
};
|
||||
const result = evaluateExecAllowlist({
|
||||
analysis,
|
||||
allowlist: [{ pattern: "/usr/bin/other" }],
|
||||
safeBins: new Set(),
|
||||
cwd: "/tmp",
|
||||
});
|
||||
expect(result.allowlistSatisfied).toBe(false);
|
||||
expect(result.allowlistMatches).toEqual([]);
|
||||
expect(result.segmentSatisfiedBy).toEqual([]);
|
||||
});
|
||||
|
||||
it("aggregates segment satisfaction across chains", () => {
|
||||
const allowlistSegment = {
|
||||
raw: "tool",
|
||||
argv: ["tool"],
|
||||
resolution: {
|
||||
rawExecutable: "tool",
|
||||
resolvedPath: "/usr/bin/tool",
|
||||
executableName: "tool",
|
||||
},
|
||||
};
|
||||
const safeBinSegment = {
|
||||
raw: "jq .foo",
|
||||
argv: ["jq", ".foo"],
|
||||
resolution: {
|
||||
rawExecutable: "jq",
|
||||
resolvedPath: "/usr/bin/jq",
|
||||
executableName: "jq",
|
||||
},
|
||||
};
|
||||
const analysis = {
|
||||
ok: true,
|
||||
segments: [allowlistSegment, safeBinSegment],
|
||||
chains: [[allowlistSegment], [safeBinSegment]],
|
||||
};
|
||||
const result = evaluateExecAllowlist({
|
||||
analysis,
|
||||
allowlist: [{ pattern: "/usr/bin/tool" }],
|
||||
safeBins: normalizeSafeBins(["jq"]),
|
||||
cwd: "/tmp",
|
||||
});
|
||||
if (process.platform === "win32") {
|
||||
expect(result.allowlistSatisfied).toBe(false);
|
||||
return;
|
||||
}
|
||||
expect(result.allowlistSatisfied).toBe(true);
|
||||
expect(result.allowlistMatches.map((entry) => entry.pattern)).toEqual(["/usr/bin/tool"]);
|
||||
expect(result.segmentSatisfiedBy).toEqual(["allowlist", "safeBins"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("exec approvals policy helpers", () => {
|
||||
|
||||
Reference in New Issue
Block a user