Repository navigation
Expand file tree
/
Copy pathcommand.test.ts
More file actions
73 lines (69 loc) · 2.7 KB
/
Copy pathcommand.test.ts
File metadata and controls
73 lines (69 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { describe, expect, test } from "bun:test"
import { PlatformError } from "effect"
import { parseTarget, quote, sshArgs, tunnelArgs, commandFailureDetail, SshFailure } from "./command"
describe("SSH connection commands", () => {
test("classifies a missing SSH executable from the platform error", () => {
const error = PlatformError.systemError({
_tag: "NotFound",
module: "ChildProcessSpawner",
method: "spawn",
pathOrDescriptor: "ssh",
})
expect(SshFailure.from(error).code).toBe("ssh-missing")
})
test("forwarding overrides bootstrap persistence before reusing the control socket", () => {
const args = tunnelArgs(
{
host: "devbox",
args: ["-o", "ControlMaster=auto", "-o", "ControlPersist=60", "-o", "ControlPath=/test/socket"],
},
1234,
{ host: "127.0.0.1", port: 5678 },
)
expect(args.slice(0, 4)).toEqual(["-o", "ControlMaster=no", "-o", "ControlPersist=no"])
expect(args).toContain("ControlPath=/test/socket")
expect(args.slice(-4)).toEqual(["-L", "127.0.0.1:1234:127.0.0.1:5678", "devbox", "sh -c 'exec cat >/dev/null'"])
})
test("retains CLI stdout failures without exposing private connection details", () => {
expect(
commandFailureDetail(1, {
stdout:
'OPENCODE_SSH_REGISTRATION_BEGIN\n{"password":"secret"}\nOPENCODE_SSH_REGISTRATION_END\nFailed to read next file',
stderr: "",
}),
).toBe("Failed to read next file")
expect(
commandFailureDetail(1, {
stdout: 'OPENCODE_SSH_REGISTRATION_BEGIN\n{"password":"secret"}',
stderr: "read interrupted",
}),
).toBe("read interrupted")
expect(commandFailureDetail(255, { stdout: "", stderr: "" })).toBe('{"exitCode":255}')
})
test("preserves aliases and connection options without invoking a shell", () => {
expect(parseTarget('ssh -p 2222 -i "~/.ssh/work key" -J gateway user@devbox')).toEqual({
host: "user@devbox",
args: ["-p", "2222", "-i", "~/.ssh/work key", "-J", "gateway"],
})
expect(parseTarget("devbox")).toEqual({ host: "devbox", args: [] })
expect(parseTarget("ssh user@[::1]").host).toBe("user@[::1]")
expect(sshArgs(parseTarget("devbox"))).toContain("PermitLocalCommand=no")
})
test("rejects remote commands, shell syntax, and transport overrides", () => {
for (const input of [
"",
"ssh host whoami",
"host;whoami",
"ssh user:password@host",
"ssh -t host",
"ssh -o RemoteCommand=whoami host",
"ssh -L 1234:x:80 host",
"ssh -p 70000 host",
'ssh -i "key host',
"host\nwhoami",
]) {
expect(() => parseTarget(input)).toThrow()
}
expect(quote("a'b")).toBe("'a'\\''b'")
})
})