Publish reviewed history-free open-source snapshot (2026-10-12)
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import XCTest
|
||||
@testable import UCVLZonghengjia
|
||||
|
||||
final class ClientConfigResponseTests: XCTestCase {
|
||||
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 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")
|
||||
}
|
||||
|
||||
func testOldBackendPayloadRemainsCompatible() throws {
|
||||
let data = Data(#"{"node":{"slug":"n1","name":"VPN001","region":"东京","status":"online"},"route_mode":"smart","config":{}}"#.utf8)
|
||||
let response = try JSONDecoder().decode(ClientConfigResponse.self, from: data)
|
||||
|
||||
XCTAssertNil(response.configContract)
|
||||
XCTAssertNil(response.gateway)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import XCTest
|
||||
@testable import UCVLZonghengjia
|
||||
|
||||
final class ConnectionAttemptPolicyTests: XCTestCase {
|
||||
func testControlPlaneTimeoutDoesNotBlacklistUnassignedNode() {
|
||||
XCTAssertEqual(ConnectionAttemptPolicy.decide(error: URLError(.timedOut), hasAssignedNode: false), .stop)
|
||||
}
|
||||
|
||||
func testAuthorizationFailureDoesNotCycleNodes() {
|
||||
for status in [401, 403] {
|
||||
XCTAssertEqual(ConnectionAttemptPolicy.decide(
|
||||
error: UCVLError.api(status: status, message: "fixture"), hasAssignedNode: true), .revokeAuthorization)
|
||||
}
|
||||
XCTAssertEqual(ConnectionAttemptPolicy.decide(
|
||||
error: UCVLError.api(status: 503, message: "fixture"), hasAssignedNode: false), .stop)
|
||||
}
|
||||
|
||||
func testPermissionAndConfigurationFailuresAreLocal() {
|
||||
XCTAssertEqual(ConnectionAttemptPolicy.decide(error: UCVLError.vpnPermission("fixture"), hasAssignedNode: true), .stop)
|
||||
XCTAssertEqual(ConnectionAttemptPolicy.decide(error: UCVLError.invalidConfiguration("fixture"), hasAssignedNode: true), .stop)
|
||||
XCTAssertEqual(ConnectionAttemptPolicy.decide(error: CancellationError(), hasAssignedNode: true), .stop)
|
||||
}
|
||||
|
||||
func testAssignedNodeTransportFailureCanFailOver() {
|
||||
XCTAssertEqual(ConnectionAttemptPolicy.decide(error: UCVLError.connection("fixture"), hasAssignedNode: true), .retryNode)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import XCTest
|
||||
@testable import UCVLZonghengjia
|
||||
|
||||
final class NetworkAddressTests: XCTestCase {
|
||||
func testAcceptsPublicIPv4() {
|
||||
XCTAssertTrue(NetworkAddress.isPublicIPv4("192.0.2.1"))
|
||||
XCTAssertTrue(NetworkAddress.isPublicIPv4("8.216.53.107"))
|
||||
}
|
||||
|
||||
func testRejectsPrivateTailscaleAndFakeIPv4() {
|
||||
XCTAssertFalse(NetworkAddress.isPublicIPv4("127.0.0.1"))
|
||||
XCTAssertFalse(NetworkAddress.isPublicIPv4("192.168.50.1"))
|
||||
XCTAssertFalse(NetworkAddress.isPublicIPv4("100.64.0.2"))
|
||||
XCTAssertFalse(NetworkAddress.isPublicIPv4("198.18.0.119"))
|
||||
XCTAssertFalse(NetworkAddress.isPublicIPv4("001.vpn.toplc.cn"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import XCTest
|
||||
@testable import UCVLZonghengjia
|
||||
|
||||
final class TunnelConfigurationBuilderTests: XCTestCase {
|
||||
func testReplacesDesktopInboundsWithAppleTunnelAndPreservesRealityOutbound() throws {
|
||||
let raw = #"""
|
||||
{
|
||||
"log":{"loglevel":"warning"},
|
||||
"inbounds":[{"tag":"socks-in","protocol":"socks","port":10808}],
|
||||
"outbounds":[
|
||||
{"tag":"proxy","protocol":"vless","settings":{"vnext":[{"address":"001.vpn.toplc.cn","port":11081,"users":[{"id":"11111111-2222-3333-4444-555555555555"}]}]},"streamSettings":{"security":"reality","realitySettings":{"serverName":"www.microsoft.com"}}},
|
||||
{"tag":"direct","protocol":"freedom"}
|
||||
],
|
||||
"routing":{"rules":[]}
|
||||
}
|
||||
"""#
|
||||
|
||||
let output = try TunnelConfigurationBuilder.makeConfiguration(
|
||||
rawJSON: raw,
|
||||
tunnelFileDescriptor: 42,
|
||||
assetDirectory: "/app/assets",
|
||||
resolvedRemoteAddress: "192.0.2.1"
|
||||
)
|
||||
let data = try XCTUnwrap(output.data(using: .utf8))
|
||||
let root = try XCTUnwrap(JSONSerialization.jsonObject(with: data) as? [String: Any])
|
||||
let environment = try XCTUnwrap(root["env"] as? [String: String])
|
||||
XCTAssertEqual(environment["xray.tun.fd"], "42")
|
||||
XCTAssertEqual(environment["xray.location.asset"], "/app/assets")
|
||||
|
||||
let inbounds = try XCTUnwrap(root["inbounds"] as? [[String: Any]])
|
||||
XCTAssertEqual(inbounds.count, 1)
|
||||
XCTAssertEqual(inbounds[0]["protocol"] as? String, "tun")
|
||||
|
||||
let outbounds = try XCTUnwrap(root["outbounds"] as? [[String: Any]])
|
||||
XCTAssertEqual(outbounds.first?["protocol"] as? String, "vless")
|
||||
let settings = try XCTUnwrap(outbounds.first?["settings"] as? [String: Any])
|
||||
let vnext = try XCTUnwrap(settings["vnext"] as? [[String: Any]])
|
||||
XCTAssertEqual(vnext.first?["address"] as? String, "192.0.2.1")
|
||||
let stream = try XCTUnwrap(outbounds.first?["streamSettings"] as? [String: Any])
|
||||
let reality = try XCTUnwrap(stream["realitySettings"] as? [String: Any])
|
||||
XCTAssertEqual(reality["serverName"] as? String, "www.microsoft.com")
|
||||
XCTAssertEqual(TunnelConfigurationBuilder.remoteAddress(from: raw), "001.vpn.toplc.cn")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user