mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:20:43 +00:00
* fix(daemon): avoid inline dotenv secrets in systemd unit during service repair * fix(daemon): sanitize systemd envfile and dedupe state-dir resolution * fix(daemon): fail on multiline dotenv values for systemd envfile * test(daemon): cover systemd envfile staging * fix: keep systemd envfile overrides intact (#66249) (thanks @tmimmanuel) --------- Co-authored-by: Ayaan Zaidi <hi@obviy.us>
58 lines
2.1 KiB
TypeScript
58 lines
2.1 KiB
TypeScript
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("renders control-group kill mode for child-process cleanup", () => {
|
|
const unit = buildSystemdUnit({
|
|
description: "OpenClaw Gateway",
|
|
programArguments: ["/usr/bin/openclaw", "gateway", "run"],
|
|
environment: {},
|
|
});
|
|
expect(unit).toContain("KillMode=control-group");
|
|
expect(unit).toContain("TimeoutStopSec=30");
|
|
expect(unit).toContain("TimeoutStartSec=30");
|
|
expect(unit).toContain("SuccessExitStatus=0 143");
|
|
expect(unit).toContain("StartLimitBurst=5");
|
|
expect(unit).toContain("StartLimitIntervalSec=60");
|
|
expect(unit).toContain("RestartPreventExitStatus=78");
|
|
});
|
|
|
|
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/);
|
|
});
|
|
|
|
it("renders EnvironmentFile entries before inline Environment values", () => {
|
|
const unit = buildSystemdUnit({
|
|
description: "OpenClaw Gateway",
|
|
programArguments: ["/usr/bin/openclaw", "gateway", "run"],
|
|
environmentFiles: ["/home/test/.openclaw/.env"],
|
|
environment: {
|
|
OPENCLAW_GATEWAY_PORT: "18789",
|
|
},
|
|
});
|
|
expect(unit).toContain("EnvironmentFile=-/home/test/.openclaw/.env");
|
|
expect(unit).toContain("Environment=OPENCLAW_GATEWAY_PORT=18789");
|
|
expect(unit.indexOf("EnvironmentFile=-/home/test/.openclaw/.env")).toBeLessThan(
|
|
unit.indexOf("Environment=OPENCLAW_GATEWAY_PORT=18789"),
|
|
);
|
|
});
|
|
});
|