-
-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathDatabaseConnectionSSHTests.swift
More file actions
111 lines (93 loc) · 3.63 KB
/
DatabaseConnectionSSHTests.swift
File metadata and controls
111 lines (93 loc) · 3.63 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// DatabaseConnectionSSHTests.swift
// TableProTests
//
import Foundation
import Testing
@testable import TablePro
@Suite("DatabaseConnection effectiveSSHConfig")
struct DatabaseConnectionSSHTests {
@Test("No profile and no sshProfileId returns inline sshConfig")
func inlineSSHConfigWithoutProfile() {
var conn = TestFixtures.makeConnection()
conn.sshConfig = SSHConfiguration()
conn.sshConfig.enabled = true
conn.sshConfig.host = "inline-host.example.com"
conn.sshConfig.port = 2_222
conn.sshConfig.username = "inline-user"
conn.sshProfileId = nil
let result = conn.effectiveSSHConfig(profile: nil)
#expect(result.host == "inline-host.example.com")
#expect(result.port == 2_222)
#expect(result.username == "inline-user")
#expect(result.enabled == true)
}
@Test("Profile provided and sshProfileId set returns profile config")
func profileOverridesInlineConfig() {
let profileId = UUID()
var conn = TestFixtures.makeConnection()
conn.sshConfig = SSHConfiguration()
conn.sshConfig.enabled = true
conn.sshConfig.host = "inline-host.example.com"
conn.sshConfig.username = "inline-user"
conn.sshProfileId = profileId
let profile = SSHProfile(
id: profileId,
name: "Production SSH",
host: "profile-host.example.com",
port: 2_200,
username: "profile-user",
authMethod: .privateKey,
privateKeyPath: "~/.ssh/id_ed25519"
)
let result = conn.effectiveSSHConfig(profile: profile)
#expect(result.host == "profile-host.example.com")
#expect(result.port == 2_200)
#expect(result.username == "profile-user")
#expect(result.authMethod == .privateKey)
#expect(result.privateKeyPath == "~/.ssh/id_ed25519")
}
@Test("sshProfileId set but profile nil falls back to inline config")
func deletedProfileFallsBackToInline() {
var conn = TestFixtures.makeConnection()
conn.sshConfig = SSHConfiguration()
conn.sshConfig.enabled = true
conn.sshConfig.host = "fallback-host.example.com"
conn.sshConfig.username = "fallback-user"
conn.sshProfileId = UUID()
let result = conn.effectiveSSHConfig(profile: nil)
#expect(result.host == "fallback-host.example.com")
#expect(result.username == "fallback-user")
}
@Test("sshProfileId nil ignores provided profile and returns inline config")
func noProfileIdIgnoresProfile() {
var conn = TestFixtures.makeConnection()
conn.sshConfig = SSHConfiguration()
conn.sshConfig.enabled = true
conn.sshConfig.host = "inline-host.example.com"
conn.sshConfig.username = "inline-user"
conn.sshProfileId = nil
let profile = SSHProfile(
id: UUID(),
name: "Ignored Profile",
host: "profile-host.example.com",
username: "profile-user"
)
let result = conn.effectiveSSHConfig(profile: profile)
#expect(result.host == "inline-host.example.com")
#expect(result.username == "inline-user")
}
@Test("toSSHConfiguration sets enabled to true")
func profileConfigHasEnabledTrue() {
let profile = SSHProfile(
name: "Test Profile",
host: "ssh.example.com",
port: 22,
username: "testuser"
)
let config = profile.toSSHConfiguration()
#expect(config.enabled == true)
#expect(config.host == "ssh.example.com")
#expect(config.username == "testuser")
}
}