From c0b2bc2d2e7e2b1ae4ad3b5dab07b23d49bbe2a5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 20 May 2026 13:28:42 +0000 Subject: [PATCH 1/4] Initial plan From 2be07645a0d69f1bf8582b7802c63eb7be0167b1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 20 May 2026 13:33:37 +0000 Subject: [PATCH 2/4] Relax DnsGetHostEntry_LocalhostSubdomain_RespectsAddressFamily on Android/AppleMobile Co-authored-by: kotlarmilos <11523312+kotlarmilos@users.noreply.github.com> --- .../tests/FunctionalTests/GetHostEntryTest.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs index d3d1676c9b110f..48d31c6ed339f5 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs @@ -434,21 +434,27 @@ public async Task DnsGetHostEntry_LocalhostSubdomain_RespectsAddressFamily(Addre string hostName = "test.localhost"; + // On Android and Apple mobile the OS resolver may return addresses of a different + // family than requested (e.g. link-local IPv6 results for an IPv4 query), so we + // only require the requested family to be represented in the results there. + bool strictAddressFamily = !PlatformDetection.IsAppleMobile && !PlatformDetection.IsAndroid; + // The subdomain goes to OS resolver first. If it fails, it falls back to // resolving plain "localhost" with the same address family filter. IPHostEntry entry = Dns.GetHostEntry(hostName, addressFamily); - if (addressFamily == AddressFamily.InterNetwork) - { - Assert.True(entry.AddressList.Length >= 1, "Expected at least one IPv4 address"); - } - Assert.All(entry.AddressList, addr => Assert.Equal(addressFamily, addr.AddressFamily)); + VerifyAddressFamily(entry, addressFamily, strictAddressFamily); entry = await Dns.GetHostEntryAsync(hostName, addressFamily); - if (addressFamily == AddressFamily.InterNetwork) + VerifyAddressFamily(entry, addressFamily, strictAddressFamily); + + static void VerifyAddressFamily(IPHostEntry entry, AddressFamily addressFamily, bool strictAddressFamily) { - Assert.True(entry.AddressList.Length >= 1, "Expected at least one IPv4 address"); + Assert.Contains(entry.AddressList, addr => addr.AddressFamily == addressFamily); + if (strictAddressFamily) + { + Assert.All(entry.AddressList, addr => Assert.Equal(addressFamily, addr.AddressFamily)); + } } - Assert.All(entry.AddressList, addr => Assert.Equal(addressFamily, addr.AddressFamily)); } // RFC 6761: Verify that localhost subdomains return loopback addresses. From 27909d98931bd193f5474b2dd563ff80e3adcba6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 12:17:35 +0000 Subject: [PATCH 3/4] Relax HostAddresses localhost subdomain family check on Android/AppleMobile Co-authored-by: rzikm <32671551+rzikm@users.noreply.github.com> --- .../FunctionalTests/GetHostAddressesTest.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs index 249aa22ef43c49..89e04381898df4 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs @@ -268,22 +268,28 @@ public async Task DnsGetHostAddresses_LocalhostSubdomain_RespectsAddressFamily(A } string hostName = "test.localhost"; + bool strictAddressFamily = !PlatformDetection.IsAppleMobile && !PlatformDetection.IsAndroid; // The subdomain goes to OS resolver first. If it fails, it falls back to // resolving plain "localhost" with the same address family filter. IPAddress[] addresses = Dns.GetHostAddresses(hostName, addressFamily); - if (addressFamily == AddressFamily.InterNetwork) - { - Assert.True(addresses.Length >= 1, "Expected at least one IPv4 address"); - } - Assert.All(addresses, addr => Assert.Equal(addressFamily, addr.AddressFamily)); + VerifyAddressFamily(addresses, addressFamily, strictAddressFamily); addresses = await Dns.GetHostAddressesAsync(hostName, addressFamily); - if (addressFamily == AddressFamily.InterNetwork) + VerifyAddressFamily(addresses, addressFamily, strictAddressFamily); + + static void VerifyAddressFamily(IPAddress[] addresses, AddressFamily addressFamily, bool strictAddressFamily) { - Assert.True(addresses.Length >= 1, "Expected at least one IPv4 address"); + if (addressFamily == AddressFamily.InterNetwork) + { + Assert.Contains(addresses, addr => addr.AddressFamily == addressFamily); + } + + if (strictAddressFamily) + { + Assert.All(addresses, addr => Assert.Equal(addressFamily, addr.AddressFamily)); + } } - Assert.All(addresses, addr => Assert.Equal(addressFamily, addr.AddressFamily)); } // RFC 6761: Verify that localhost subdomains return loopback addresses. From 033a9159fd50dc9f4df316d8f3d0e503b74dd708 Mon Sep 17 00:00:00 2001 From: kotlarmilos <11523312+kotlarmilos@users.noreply.github.com> Date: Thu, 28 May 2026 18:10:07 +0200 Subject: [PATCH 4/4] Preserve original IPv6-empty semantics in DnsGetHostEntry_LocalhostSubdomain_RespectsAddressFamily The previous unconditional Assert.Contains tightened semantics for IPv6 on non-mobile platforms: an empty AddressList used to pass via vacuous Assert.All but would fail Assert.Contains. Guard the contains check with addressFamily == AddressFamily.InterNetwork, matching the original "at least one IPv4 address" expectation and the structure already used in GetHostAddressesTest.cs. Addresses review feedback on #128404. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../tests/FunctionalTests/GetHostEntryTest.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs index 48d31c6ed339f5..63763dcd4dec24 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs @@ -449,7 +449,11 @@ public async Task DnsGetHostEntry_LocalhostSubdomain_RespectsAddressFamily(Addre static void VerifyAddressFamily(IPHostEntry entry, AddressFamily addressFamily, bool strictAddressFamily) { - Assert.Contains(entry.AddressList, addr => addr.AddressFamily == addressFamily); + if (addressFamily == AddressFamily.InterNetwork) + { + Assert.Contains(entry.AddressList, addr => addr.AddressFamily == addressFamily); + } + if (strictAddressFamily) { Assert.All(entry.AddressList, addr => Assert.Equal(addressFamily, addr.AddressFamily));