mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-23 14:24:12 +00:00
launchd 对 ProgramArguments[0] 的相对路径按 _PATH_STDPATH(PATH)解析而非 bundle:系统域 daemon 的 job 因此永远 spawn 失败(EX_CONFIG 节流循环, launchctl print 显示 job state = spawn failed、runs 持续累加),客户端 XPC 调用只能等到超时。agent 之所以正常,是 GUI 域导入时被解析成绝对路径,system 域 submitted job 没有这一步。SMAppService 清单的正确键是 BundleProgram (bundle 相对,launchd.plist(5)),改用之。 launchd 同时沿用注册提交时的定义快照:app 更新改动 LaunchDaemon 清单后旧 定义不会自动刷新(register() 对已注册服务返回 alreadyRegistered),必须注销 重注。门禁在已批准分支按清单内容 SHA-256 指纹(UserDefaults)检测漂移,漂移 才注销重注——审批与 bundle 签名绑定,重注不重新弹授权;首次注册成功即记指 纹,失败不记(下次启动重试),指纹一致为一次哈希比对的 no-op。
108 lines
3.1 KiB
Swift
108 lines
3.1 KiB
Swift
@testable import ShadowsocksX_NG2
|
|
|
|
/// 系统代理相关替身(issue #60/#71):从 ProxyRuntimeFixture 主文件分出,
|
|
/// 保持 `ProxyRuntimeFixture.` 限定名不变。
|
|
extension ProxyRuntimeFixture {
|
|
@MainActor
|
|
final class FakeSystemProxy: SystemProxyControlling {
|
|
private(set) var applied: [SystemProxyConfiguration] = []
|
|
private(set) var clearCount = 0
|
|
var applyError: Error?
|
|
var clearError: Error?
|
|
var onClear: (@MainActor () -> Void)?
|
|
/// 注入返回值:模拟系统值已与期望等价的免授权跳过路径(issue #70)。
|
|
var applyOutcome: SystemProxyWriteOutcome = .written
|
|
/// 可选共享事件日志(次序断言用)。
|
|
weak var eventLog: ProxyRuntimeEventLog?
|
|
|
|
func apply(
|
|
_ configuration: SystemProxyConfiguration
|
|
) async throws -> SystemProxyWriteOutcome {
|
|
eventLog?.record("apply")
|
|
if let applyError { throw applyError }
|
|
applied.append(configuration)
|
|
return applyOutcome
|
|
}
|
|
|
|
func clear() async throws {
|
|
clearCount += 1
|
|
eventLog?.record("clear")
|
|
onClear?()
|
|
if let clearError { throw clearError }
|
|
}
|
|
}
|
|
|
|
/// 特权 helper 注册/审批状态可编程替身(issue #71)。
|
|
@MainActor
|
|
final class FakeSystemProxyHelperService: SystemProxyHelperServicing {
|
|
private(set) var currentStatus: SystemProxyHelperStatus
|
|
private(set) var registerCount = 0
|
|
private(set) var unregisterCount = 0
|
|
private(set) var registerError: Error?
|
|
private(set) var unregisterError: Error?
|
|
private(set) var openApprovalPathCount = 0
|
|
/// register() 成功后迁移到的状态(模拟 BTM 批准立即达成)。
|
|
var statusAfterRegister: SystemProxyHelperStatus = .approved
|
|
|
|
init(initialStatus: SystemProxyHelperStatus = .approved) {
|
|
currentStatus = initialStatus
|
|
}
|
|
|
|
var status: SystemProxyHelperStatus { currentStatus }
|
|
|
|
func setStatus(_ status: SystemProxyHelperStatus) {
|
|
currentStatus = status
|
|
}
|
|
|
|
func setRegisterError(_ error: Error?) {
|
|
registerError = error
|
|
}
|
|
|
|
func setUnregisterError(_ error: Error?) {
|
|
unregisterError = error
|
|
}
|
|
|
|
func register() throws {
|
|
registerCount += 1
|
|
if let registerError { throw registerError }
|
|
currentStatus = statusAfterRegister
|
|
}
|
|
|
|
func unregister() throws {
|
|
unregisterCount += 1
|
|
if let unregisterError { throw unregisterError }
|
|
currentStatus = .notRegistered
|
|
}
|
|
|
|
func openApprovalPath() {
|
|
openApprovalPathCount += 1
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
final class FakeSystemProxyNetworkChangeMonitor: SystemProxyNetworkChangeMonitoring {
|
|
private(set) var startCount = 0
|
|
private(set) var stopCount = 0
|
|
private(set) var isObserving = false
|
|
private var handler: (@MainActor @Sendable (SystemProxyNetworkChange) -> Void)?
|
|
|
|
func start(
|
|
handler: @escaping @MainActor @Sendable (SystemProxyNetworkChange) -> Void
|
|
) {
|
|
startCount += 1
|
|
isObserving = true
|
|
self.handler = handler
|
|
}
|
|
|
|
func stop() {
|
|
stopCount += 1
|
|
isObserving = false
|
|
handler = nil
|
|
}
|
|
|
|
func emit(_ change: SystemProxyNetworkChange) {
|
|
handler?(change)
|
|
}
|
|
}
|
|
}
|