@@ -53,6 +53,59 @@ fn empty_dns_section_is_filled_by_game_proxy() {
5353 assert ! ( output. contains( "#Title = \" \" " ) ) ;
5454}
5555
56+ #[ test]
57+ fn dns_detects_loopback_targets_across_server_fields ( ) {
58+ // Given: 每个 DNS 服务器字段分别使用一种本机地址写法。
59+ for entry in [
60+ "Default = \" localhost\" " ,
61+ "Router = \" LOCALHOST.\" " ,
62+ "Startup = \" 127.8.9.10:8080\" " ,
63+ "Billing = \" http://127.0.0.1:8443\" " ,
64+ "Aimedb = \" [::1]:22345\" " ,
65+ "Title = \" ::1\" " ,
66+ "Title = \" service.localhost\" " ,
67+ ] {
68+ let source = format ! ( "ConfigVersion = 1\n [Dns]\n {entry}\n " ) ;
69+ let config = Config :: parse ( "." , & source) . expect ( "测试配置必须有效" ) ;
70+ let dns = config
71+ . section :: < crate :: amdaemon:: DnsConfig > ( )
72+ . expect ( "DNS 配置必须完成注入" ) ;
73+
74+ // When: AM Daemon 判断是否需要本机服务器补丁。
75+ let required = dns. enabled && dns. requires_localhost_patch ( ) ;
76+
77+ // Then: 任一字段指向回环目标都会自动启用补丁。
78+ assert ! ( required, "未识别本机 DNS 目标: {entry}" ) ;
79+ }
80+ }
81+
82+ #[ test]
83+ fn dns_does_not_enable_localhost_patch_for_remote_or_disabled_mapping ( ) {
84+ // Given: 一个远程 DNS 映射,以及一个明确禁用的本机映射。
85+ let remote = Config :: parse (
86+ "." ,
87+ "ConfigVersion = 1\n [Dns]\n Default = \" server.example.com\" \n " ,
88+ )
89+ . expect ( "远程 DNS 配置必须有效" ) ;
90+ let disabled = Config :: parse (
91+ "." ,
92+ "ConfigVersion = 1\n [Dns]\n Enable = false\n Default = \" 127.0.0.1\" \n " ,
93+ )
94+ . expect ( "禁用 DNS 配置必须有效" ) ;
95+
96+ // When: AM Daemon 计算 localhost 补丁状态。
97+ let remote = remote
98+ . section :: < crate :: amdaemon:: DnsConfig > ( )
99+ . expect ( "DNS 配置必须完成注入" ) ;
100+ let disabled = disabled
101+ . section :: < crate :: amdaemon:: DnsConfig > ( )
102+ . expect ( "DNS 配置必须完成注入" ) ;
103+
104+ // Then: 远程目标和禁用的 DNS 均不启用补丁。
105+ assert ! ( !remote. requires_localhost_patch( ) ) ;
106+ assert ! ( !( disabled. enabled && disabled. requires_localhost_patch( ) ) ) ;
107+ }
108+
56109#[ test]
57110fn required_internal_sections_are_not_emitted ( ) {
58111 let source = concat ! (
0 commit comments