-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathssh-tunnel.test.ts
More file actions
84 lines (75 loc) · 2.94 KB
/
ssh-tunnel.test.ts
File metadata and controls
84 lines (75 loc) · 2.94 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
74
75
76
77
78
79
80
81
82
83
84
// altimate_change start — unit tests for SSH tunnel config extraction and lifecycle
import { describe, test, expect } from "bun:test"
import { extractSshConfig, closeTunnel, getActiveTunnel } from "../../src/altimate/native/connections/ssh-tunnel"
// ---------------------------------------------------------------------------
// extractSshConfig — pure function that extracts SSH tunnel config
// ---------------------------------------------------------------------------
describe("extractSshConfig", () => {
test("returns null when no ssh_host is present", () => {
const result = extractSshConfig({ type: "postgres", host: "db.example.com", port: 5432 })
expect(result).toBeNull()
})
test("extracts full SSH config with all fields", () => {
const result = extractSshConfig({
type: "postgres",
host: "db.internal",
port: 5433,
ssh_host: "bastion.example.com",
ssh_port: 2222,
ssh_user: "deployer",
ssh_password: "secret",
})
expect(result).toEqual({
ssh_host: "bastion.example.com",
ssh_port: 2222,
ssh_user: "deployer",
ssh_password: "secret",
ssh_private_key: undefined,
host: "db.internal",
port: 5433,
})
})
test("applies defaults for ssh_port, ssh_user, host, port", () => {
const result = extractSshConfig({
type: "postgres",
ssh_host: "bastion.example.com",
})
expect(result).not.toBeNull()
expect(result!.ssh_port).toBe(22)
expect(result!.ssh_user).toBe("root")
expect(result!.host).toBe("127.0.0.1")
expect(result!.port).toBe(5432)
})
test("throws when connection_string is used with SSH tunnel", () => {
expect(() => extractSshConfig({
type: "postgres",
ssh_host: "bastion.example.com",
connection_string: "postgresql://user:pass@host:5432/db",
})).toThrow("Cannot use SSH tunnel with connection_string")
})
test("supports private key authentication", () => {
const result = extractSshConfig({
type: "snowflake",
host: "db.internal",
port: 443,
ssh_host: "bastion.example.com",
ssh_private_key: "-----BEGIN OPENSSH PRIVATE KEY-----\nAAA...",
})
expect(result).not.toBeNull()
expect(result!.ssh_private_key).toBe("-----BEGIN OPENSSH PRIVATE KEY-----\nAAA...")
expect(result!.ssh_password).toBeUndefined()
})
})
// ---------------------------------------------------------------------------
// closeTunnel / getActiveTunnel — idempotent operations on empty state
// ---------------------------------------------------------------------------
describe("SSH tunnel state management", () => {
test("closeTunnel is a no-op for non-existent tunnel", () => {
closeTunnel("nonexistent-tunnel-name")
expect(getActiveTunnel("nonexistent-tunnel-name")).toBeUndefined()
})
test("getActiveTunnel returns undefined for non-existent tunnel", () => {
expect(getActiveTunnel("nonexistent")).toBeUndefined()
})
})
// altimate_change end