Skip to content

Commit 4c892a6

Browse files
committed
also check at login
1 parent 48c893c commit 4c892a6

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Coder Desktop/Coder Desktop/Views/LoginForm.swift

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import CoderSDK
22
import SwiftUI
3+
import VPNLib
34

45
struct LoginForm: View {
56
@EnvironmentObject var state: AppState
@@ -78,6 +79,22 @@ struct LoginForm: View {
7879
loginError = .failedAuth(error)
7980
return
8081
}
82+
let buildInfo: BuildInfoResponse
83+
do {
84+
buildInfo = try await client.buildInfo()
85+
} catch {
86+
loginError = .failedAuth(error)
87+
return
88+
}
89+
guard let semver = buildInfo.semver else {
90+
loginError = .missingServerVersion
91+
return
92+
}
93+
// x.compare(y) is .orderedDescending if x > y
94+
guard SignatureValidator.minimumCoderVersion.compare(semver, options: .numeric) != .orderedDescending else {
95+
loginError = .outdatedCoderVersion
96+
return
97+
}
8198
state.login(baseAccessURL: url, sessionToken: sessionToken)
8299
dismiss()
83100
}
@@ -190,6 +207,8 @@ enum LoginError: Error {
190207
case httpsRequired
191208
case noHost
192209
case invalidURL
210+
case outdatedCoderVersion
211+
case missingServerVersion
193212
case failedAuth(ClientError)
194213

195214
var description: String {
@@ -200,8 +219,15 @@ enum LoginError: Error {
200219
"URL must have a host"
201220
case .invalidURL:
202221
"Invalid URL"
222+
case .outdatedCoderVersion:
223+
"""
224+
The Coder deployment must be version \(SignatureValidator.minimumCoderVersion)
225+
or higher to use Coder Desktop.
226+
"""
203227
case let .failedAuth(err):
204228
"Could not authenticate with Coder deployment:\n\(err.localizedDescription)"
229+
case .missingServerVersion:
230+
"Coder deployment did not provide a server version"
205231
}
206232
}
207233

Coder Desktop/VPNLib/Download.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public enum ValidationError: Error {
4343

4444
public class SignatureValidator {
4545
// Whilst older dylibs exist, this app assumes v2.20 or later.
46-
static let minimumCoderVersion = "2.20.0"
46+
public static let minimumCoderVersion = "2.20.0"
4747

4848
private static let expectedName = "CoderVPN"
4949
private static let expectedIdentifier = "com.coder.Coder-Desktop.VPN.dylib"

0 commit comments

Comments
 (0)