Publish reviewed history-free open-source snapshot (2026-10-12)
This commit is contained in:
@@ -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