mirror of https://github.com/openclaw/openclaw.git
test: tighten scp host coverage
This commit is contained in:
parent
9c343fb3db
commit
84a2a289e6
|
|
@ -2,18 +2,34 @@ import { describe, expect, it } from "vitest";
|
||||||
import { isSafeScpRemoteHost, normalizeScpRemoteHost } from "./scp-host.js";
|
import { isSafeScpRemoteHost, normalizeScpRemoteHost } from "./scp-host.js";
|
||||||
|
|
||||||
describe("scp remote host", () => {
|
describe("scp remote host", () => {
|
||||||
it("accepts host and user@host forms", () => {
|
it.each([
|
||||||
expect(normalizeScpRemoteHost("gateway-host")).toBe("gateway-host");
|
{ value: "gateway-host", expected: "gateway-host" },
|
||||||
expect(normalizeScpRemoteHost("bot@gateway-host")).toBe("bot@gateway-host");
|
{ value: " bot@gateway-host ", expected: "bot@gateway-host" },
|
||||||
expect(normalizeScpRemoteHost("bot@192.168.64.3")).toBe("bot@192.168.64.3");
|
{ value: "bot@192.168.64.3", expected: "bot@192.168.64.3" },
|
||||||
expect(normalizeScpRemoteHost("bot@[fe80::1]")).toBe("bot@[fe80::1]");
|
{ value: "bot@[fe80::1]", expected: "bot@[fe80::1]" },
|
||||||
|
])("normalizes safe hosts for %j", ({ value, expected }) => {
|
||||||
|
expect(normalizeScpRemoteHost(value)).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects unsafe host tokens", () => {
|
it.each([
|
||||||
expect(isSafeScpRemoteHost("-oProxyCommand=whoami")).toBe(false);
|
null,
|
||||||
expect(isSafeScpRemoteHost("bot@gateway-host -oStrictHostKeyChecking=no")).toBe(false);
|
undefined,
|
||||||
expect(isSafeScpRemoteHost("bot@host:22")).toBe(false);
|
"",
|
||||||
expect(isSafeScpRemoteHost("bot@/tmp/host")).toBe(false);
|
" ",
|
||||||
expect(isSafeScpRemoteHost("bot@@host")).toBe(false);
|
"-oProxyCommand=whoami",
|
||||||
|
"bot@gateway-host -oStrictHostKeyChecking=no",
|
||||||
|
"bot@host:22",
|
||||||
|
"bot@/tmp/host",
|
||||||
|
"bot@@host",
|
||||||
|
"@host",
|
||||||
|
"bot@",
|
||||||
|
"bot@host\\name",
|
||||||
|
"bot@-gateway-host",
|
||||||
|
"bot@fe80::1",
|
||||||
|
"bot@[fe80::1%en0]",
|
||||||
|
"bot name@gateway-host",
|
||||||
|
])("rejects unsafe host tokens: %j", (value) => {
|
||||||
|
expect(normalizeScpRemoteHost(value)).toBeUndefined();
|
||||||
|
expect(isSafeScpRemoteHost(value)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue