openclaw/src/infra/ssh-tunnel.test.ts
Peter Steinberger 06289b36da fix(security): harden SSH target handling (#4001)
Thanks @YLChen-007.

Co-authored-by: Edward-x <YLChen-007@users.noreply.github.com>
2026-01-29 16:33:36 +00:00

28 lines
735 B
TypeScript

import { describe, expect, it } from "vitest";
import { parseSshTarget } from "./ssh-tunnel.js";
describe("parseSshTarget", () => {
it("parses user@host:port targets", () => {
expect(parseSshTarget("me@example.com:2222")).toEqual({
user: "me",
host: "example.com",
port: 2222,
});
});
it("parses host-only targets with default port", () => {
expect(parseSshTarget("example.com")).toEqual({
user: undefined,
host: "example.com",
port: 22,
});
});
it("rejects hostnames that start with '-'", () => {
expect(parseSshTarget("-V")).toBeNull();
expect(parseSshTarget("me@-badhost")).toBeNull();
expect(parseSshTarget("-oProxyCommand=echo")).toBeNull();
});
});