iOS 1.0.3 source candidate only; no Apple build or installation acceptance
This commit is contained in:
@@ -2,13 +2,20 @@ import XCTest
|
||||
@testable import UCVLZonghengjia
|
||||
|
||||
final class ClientConfigResponseTests: XCTestCase {
|
||||
func testActualBackendConfigNodeDoesNotRequireProfileOnlyStatus() throws {
|
||||
let data = Data(#"{"config_contract":2,"node":{"slug":"n1","name":"VPN001","region":"东京"},"route_mode":"smart","config":{}}"#.utf8)
|
||||
let response = try JSONDecoder().decode(ClientConfigResponse.self, from: data)
|
||||
XCTAssertEqual(response.node.slug, "n1")
|
||||
XCTAssertEqual(response.node.status, "unknown")
|
||||
}
|
||||
|
||||
func testDecodesVersionedGatewayContract() throws {
|
||||
let data = Data(#"{"config_contract":2,"gateway":{"host":"vpn.toplc.cn","ipv4":"192.0.2.1"},"node":{"slug":"n1","name":"VPN001","region":"东京","status":"online"},"route_mode":"smart","config":{}}"#.utf8)
|
||||
let data = Data(#"{"config_contract":2,"gateway":{"host":"vpn.example.invalid","ipv4":"203.0.113.17"},"node":{"slug":"n1","name":"VPN001","region":"东京","status":"online"},"route_mode":"smart","config":{}}"#.utf8)
|
||||
let response = try JSONDecoder().decode(ClientConfigResponse.self, from: data)
|
||||
|
||||
XCTAssertEqual(response.configContract, 2)
|
||||
XCTAssertEqual(response.gateway?.host, "vpn.toplc.cn")
|
||||
XCTAssertEqual(response.gateway?.ipv4, "192.0.2.1")
|
||||
XCTAssertEqual(response.gateway?.host, "vpn.example.invalid")
|
||||
XCTAssertEqual(response.gateway?.ipv4, "203.0.113.17")
|
||||
}
|
||||
|
||||
func testOldBackendPayloadRemainsCompatible() throws {
|
||||
@@ -17,5 +24,42 @@ final class ClientConfigResponseTests: XCTestCase {
|
||||
|
||||
XCTAssertNil(response.configContract)
|
||||
XCTAssertNil(response.gateway)
|
||||
XCTAssertNil(response.tailscaleEndpoint)
|
||||
XCTAssertNil(response.connectionScope)
|
||||
}
|
||||
|
||||
func testDecodesOptionalInternalEndpointWithoutChangingPublicConfiguration() throws {
|
||||
let data = Data(#"{"config_contract":2,"connection_scope":"public","tailscale_endpoint":{"contract":1,"node_slug":"n1","address":"100.70.1.2","port":12001},"node":{"slug":"n1","name":"VPN001","region":"东京","status":"online"},"route_mode":"smart","config":{"public":"preserved"}}"#.utf8)
|
||||
let response = try JSONDecoder().decode(ClientConfigResponse.self, from: data)
|
||||
|
||||
XCTAssertEqual(response.connectionScope, "public")
|
||||
XCTAssertEqual(response.tailscaleEndpoint?.nodeSlug, "n1")
|
||||
XCTAssertEqual(response.tailscaleEndpoint?.address, "100.70.1.2")
|
||||
XCTAssertEqual(response.tailscaleEndpoint?.port, 12001)
|
||||
XCTAssertEqual(response.config["public"], .string("preserved"))
|
||||
}
|
||||
|
||||
func testMalformedOptionalEndpointDoesNotBreakPublicPayload() throws {
|
||||
for optionalValue in ["null", "true", "[]", "{}", #"{"contract":1,"node_slug":"n1","address":"100.70.1.2","port":"12001"}"#] {
|
||||
let data = Data("""
|
||||
{"tailscale_endpoint":\(optionalValue),"node":{"slug":"n1","name":"VPN001","region":"东京","status":"online"},"route_mode":"smart","config":{"public":"preserved"}}
|
||||
""".utf8)
|
||||
let response = try JSONDecoder().decode(ClientConfigResponse.self, from: data)
|
||||
|
||||
XCTAssertNil(response.tailscaleEndpoint)
|
||||
XCTAssertEqual(response.config["public"], .string("preserved"))
|
||||
}
|
||||
}
|
||||
|
||||
func testMalformedOptionalScopeDisablesInternalEndpointAndPreservesPublicPayload() throws {
|
||||
for scope in ["true", "1", "[]", "{}"] {
|
||||
let data = Data("""
|
||||
{"config_contract":2,"connection_scope":\(scope),"tailscale_endpoint":{"contract":1,"node_slug":"n1","address":"100.70.1.2","port":12001},"node":{"slug":"n1","name":"VPN001","region":"东京","status":"online"},"route_mode":"smart","config":{"public":"preserved"}}
|
||||
""".utf8)
|
||||
let response = try JSONDecoder().decode(ClientConfigResponse.self, from: data)
|
||||
|
||||
XCTAssertNil(response.tailscaleEndpoint)
|
||||
XCTAssertEqual(response.config["public"], .string("preserved"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user