mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:28:27 +00:00
refactor(core): dedupe gateway runtime and config tests
This commit is contained in:
@@ -7,6 +7,16 @@ import {
|
||||
} from "./system-run-command.js";
|
||||
|
||||
describe("system run command helpers", () => {
|
||||
function expectRawCommandMismatch(params: { argv: string[]; rawCommand: string }) {
|
||||
const res = validateSystemRunCommandConsistency(params);
|
||||
expect(res.ok).toBe(false);
|
||||
if (res.ok) {
|
||||
throw new Error("unreachable");
|
||||
}
|
||||
expect(res.message).toContain("rawCommand does not match command");
|
||||
expect(res.details?.code).toBe("RAW_COMMAND_MISMATCH");
|
||||
}
|
||||
|
||||
test("formatExecCommand quotes args with spaces", () => {
|
||||
expect(formatExecCommand(["echo", "hi there"])).toBe('echo "hi there"');
|
||||
});
|
||||
@@ -39,16 +49,10 @@ describe("system run command helpers", () => {
|
||||
});
|
||||
|
||||
test("validateSystemRunCommandConsistency rejects mismatched rawCommand vs direct argv", () => {
|
||||
const res = validateSystemRunCommandConsistency({
|
||||
expectRawCommandMismatch({
|
||||
argv: ["uname", "-a"],
|
||||
rawCommand: "echo hi",
|
||||
});
|
||||
expect(res.ok).toBe(false);
|
||||
if (res.ok) {
|
||||
throw new Error("unreachable");
|
||||
}
|
||||
expect(res.message).toContain("rawCommand does not match command");
|
||||
expect(res.details?.code).toBe("RAW_COMMAND_MISMATCH");
|
||||
});
|
||||
|
||||
test("validateSystemRunCommandConsistency accepts rawCommand matching sh wrapper argv", () => {
|
||||
@@ -60,16 +64,17 @@ describe("system run command helpers", () => {
|
||||
});
|
||||
|
||||
test("validateSystemRunCommandConsistency rejects cmd.exe /c trailing-arg smuggling", () => {
|
||||
const res = validateSystemRunCommandConsistency({
|
||||
expectRawCommandMismatch({
|
||||
argv: ["cmd.exe", "/d", "/s", "/c", "echo", "SAFE&&whoami"],
|
||||
rawCommand: "echo",
|
||||
});
|
||||
expect(res.ok).toBe(false);
|
||||
if (res.ok) {
|
||||
throw new Error("unreachable");
|
||||
}
|
||||
expect(res.message).toContain("rawCommand does not match command");
|
||||
expect(res.details?.code).toBe("RAW_COMMAND_MISMATCH");
|
||||
});
|
||||
|
||||
test("validateSystemRunCommandConsistency rejects mismatched rawCommand vs sh wrapper argv", () => {
|
||||
expectRawCommandMismatch({
|
||||
argv: ["/bin/sh", "-lc", "echo hi"],
|
||||
rawCommand: "echo bye",
|
||||
});
|
||||
});
|
||||
|
||||
test("resolveSystemRunCommand requires command when rawCommand is present", () => {
|
||||
|
||||
Reference in New Issue
Block a user