mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-22 05:25:41 +00:00
Implements issue #71 with ADR-0020 (supersedes ADR-0019's endpoint-signature cleanup, startup cleanup, and health-gate cleanup). - New ShadowsocksX-NG2SystemProxyHelper target: app-bundled root LaunchDaemon (SMAppService.daemon, on-demand via MachServices) that mechanically applies a closed typed configuration or executes an unconditional clear. Clients are accepted by code-signing bundle identifier only; requests run serially on a shared queue (last-writer-wins). - SystemProxyConfiguration is now the closed typed apply payload (Codable over JSON XPC): explicit SOCKS/HTTP/HTTPS enable + endpoints, PAC and auto-discovery disabled with URL/JS removed, explicit simple-hostname exclusion, complete ExceptionsList. Unmodeled Proxies keys are preserved and equivalent values skip the commit. - Cleanup is a side effect of a persisted system-proxy intent on-to-off transition only: the switch itself, or the agent-off cascade (persist both intents off, clear, then stop listeners; failed cascade persistence records no transition and clears nothing). Launch with the switch off, health-gate closure, invalid targets, and passive events never clear. Failed clears are surfaced without deferred retry. - Endpoint-signature store, ownership migration, and direct Authorization Services writes are removed; old signature files stay inert. Helper unavailability or pending approval keeps an enabled intent pending and surfaces the Login Items approval path (HomeView button + menu label).
62 lines
2.3 KiB
Swift
62 lines
2.3 KiB
Swift
import Foundation
|
|
import XCTest
|
|
|
|
@testable import ShadowsocksX_NG2
|
|
|
|
/// Domain mode availability is the single policy shared by the menu and
|
|
/// runtime mode entry points.
|
|
final class ProxyModeAvailabilityTests: XCTestCase {
|
|
func testBuiltInModesAreAlwaysAvailableInProductOrder() {
|
|
XCTAssertEqual(
|
|
ProxyMode.availableModes.map(\.kind),
|
|
[.rule, .global, .direct])
|
|
}
|
|
|
|
func testDirectModeUsesLocalSOCKSAndIncludesFixedBypasses() throws {
|
|
let document = SslocalRuntimeDocument(servers: [], listen: SslocalListenSettings())
|
|
|
|
let configuration = try ProxyMode.direct.systemProxyConfiguration(for: document)
|
|
|
|
XCTAssertEqual(
|
|
configuration.socks,
|
|
.init(host: "127.0.0.1", port: SslocalListenSettings.defaultSocksPort))
|
|
XCTAssertEqual(
|
|
configuration.http,
|
|
.init(host: "127.0.0.1", port: SslocalListenSettings.defaultHTTPPort))
|
|
XCTAssertEqual(
|
|
configuration.exceptions,
|
|
FixedLocalProxyRanges.systemProxyExceptions)
|
|
}
|
|
|
|
func testIPv6OnlyModeUsesIPv6LoopbackForSystemProxyEndpoints() throws {
|
|
let listen = SslocalListenSettings(listenerMode: .allIPv6Interfaces)
|
|
let document = SslocalRuntimeDocument(servers: [], listen: listen)
|
|
|
|
let configuration = try ProxyMode.direct.systemProxyConfiguration(for: document)
|
|
|
|
XCTAssertEqual(configuration.socks, .init(host: "::1", port: listen.socksPort))
|
|
XCTAssertEqual(configuration.http, .init(host: "::1", port: listen.httpPort))
|
|
}
|
|
|
|
/// 全局模式(issue #62):系统 SOCKS/HTTP 投影 + 固定本地例外,与直连共用
|
|
/// 同一安全范围;公网路由由 ACL 决定,不由系统例外决定。
|
|
func testGlobalModeUsesLocalSOCKSAndIncludesFixedBypasses() throws {
|
|
let document = SslocalRuntimeDocument(servers: [], listen: SslocalListenSettings())
|
|
|
|
let configuration = try ProxyMode.global.systemProxyConfiguration(for: document)
|
|
|
|
XCTAssertEqual(
|
|
configuration.socks,
|
|
.init(host: "127.0.0.1", port: SslocalListenSettings.defaultSocksPort))
|
|
XCTAssertEqual(
|
|
configuration.http,
|
|
.init(host: "127.0.0.1", port: SslocalListenSettings.defaultHTTPPort))
|
|
XCTAssertEqual(
|
|
configuration.exceptions,
|
|
FixedLocalProxyRanges.systemProxyExceptions)
|
|
XCTAssertFalse(
|
|
configuration.exceptions.contains("100.64.0.0/10"),
|
|
"不加入 CGNAT")
|
|
}
|
|
}
|