mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 13:00:48 +00:00
23 lines
1.0 KiB
TypeScript
23 lines
1.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { isSafeExecutableValue } from "./exec-safety.js";
|
|
|
|
describe("isSafeExecutableValue", () => {
|
|
it("accepts bare executable names and likely paths", () => {
|
|
expect(isSafeExecutableValue("node")).toBe(true);
|
|
expect(isSafeExecutableValue("/usr/bin/node")).toBe(true);
|
|
expect(isSafeExecutableValue("./bin/openclaw")).toBe(true);
|
|
expect(isSafeExecutableValue("C:\\Tools\\openclaw.exe")).toBe(true);
|
|
expect(isSafeExecutableValue(" tool ")).toBe(true);
|
|
});
|
|
|
|
it("rejects blanks, flags, shell metacharacters, quotes, and control chars", () => {
|
|
expect(isSafeExecutableValue(undefined)).toBe(false);
|
|
expect(isSafeExecutableValue(" ")).toBe(false);
|
|
expect(isSafeExecutableValue("-rf")).toBe(false);
|
|
expect(isSafeExecutableValue("node;rm -rf /")).toBe(false);
|
|
expect(isSafeExecutableValue('node "arg"')).toBe(false);
|
|
expect(isSafeExecutableValue("node\nnext")).toBe(false);
|
|
expect(isSafeExecutableValue("node\0")).toBe(false);
|
|
});
|
|
});
|