Files
ShadowsocksX-NG/ShadowsocksX-NG2/Tests/ProxyModeAvailabilityTests.swift
T
Qiu Yuzhou f2e9cff69d feat(proxy): add ACL-backed global mode with local bypass
Global mode now deploys a minimal proxy_all ACL carrying only the fixed
local safety rules, so public targets default through Shadowsocks while
loopback/RFC1918/link-local/ULA/localhost/*.local/no-dot hosts stay
direct for SOCKS, HTTP, and LAN-sharing clients. System proxy exceptions
include that fixed scope; IPv6 system-exception limits are documented
with the ACL as the routing guarantee. Mode switches keep the
full-restart and rollback path.

Closes #62
2026-09-26 12:33:35 +08:00

46 lines
1.6 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),
[.pac, .global, .direct])
}
func testDirectModeUsesLocalSOCKSAndIncludesFixedBypasses() throws {
let document = SslocalRuntimeDocument(servers: [], listen: SslocalListenSettings())
let configuration = try ProxyMode.direct.systemProxyConfiguration(for: document)
XCTAssertEqual(
configuration.target,
.socks(host: "127.0.0.1", port: SslocalListenSettings.defaultSocksPort))
XCTAssertEqual(
configuration.exceptions,
FixedLocalProxyRanges.systemProxyExceptions)
}
/// 全局模式(issue #62):系统 SOCKS 投影 + 固定本地例外,与直连共用同一
/// 安全范围;公网路由由 ACL 决定,不由系统例外决定。
func testGlobalModeUsesLocalSOCKSAndIncludesFixedBypasses() throws {
let document = SslocalRuntimeDocument(servers: [], listen: SslocalListenSettings())
let configuration = try ProxyMode.global.systemProxyConfiguration(for: document)
XCTAssertEqual(
configuration.target,
.socks(host: "127.0.0.1", port: SslocalListenSettings.defaultSocksPort))
XCTAssertEqual(
configuration.exceptions,
FixedLocalProxyRanges.systemProxyExceptions)
XCTAssertFalse(
configuration.exceptions?.contains("100.64.0.0/10") ?? true,
"不加入 CGNAT")
}
}