mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 11:04:59 +00:00
Daemon: harden systemd unit env rendering
This commit is contained in:
26
src/daemon/systemd-unit.test.ts
Normal file
26
src/daemon/systemd-unit.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildSystemdUnit } from "./systemd-unit.js";
|
||||
|
||||
describe("buildSystemdUnit", () => {
|
||||
it("quotes arguments with whitespace", () => {
|
||||
const unit = buildSystemdUnit({
|
||||
description: "OpenClaw Gateway",
|
||||
programArguments: ["/usr/bin/openclaw", "gateway", "--name", "My Bot"],
|
||||
environment: {},
|
||||
});
|
||||
const execStart = unit.split("\n").find((line) => line.startsWith("ExecStart="));
|
||||
expect(execStart).toBe('ExecStart=/usr/bin/openclaw gateway --name "My Bot"');
|
||||
});
|
||||
|
||||
it("rejects environment values with line breaks", () => {
|
||||
expect(() =>
|
||||
buildSystemdUnit({
|
||||
description: "OpenClaw Gateway",
|
||||
programArguments: ["/usr/bin/openclaw", "gateway", "start"],
|
||||
environment: {
|
||||
INJECT: "ok\nExecStartPre=/bin/touch /tmp/oc15789_rce",
|
||||
},
|
||||
}),
|
||||
).toThrow(/CR or LF/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user