From 2a08c6f951f20a4abbb4a55d092e31500b55ca22 Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Tue, 25 Jan 2022 21:09:19 -0700 Subject: [PATCH 1/3] Disable ipv6 lookup tests when needed --- .../tests/PalTests/NameResolutionPalTests.cs | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs b/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs index 5ae74af0bd538c..66f3ec9d5a6ada 100644 --- a/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs +++ b/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs @@ -1,7 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.Win32; using System.IO; +using System.Linq; using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; @@ -15,6 +17,34 @@ public class NameResolutionPalTests { private readonly ITestOutputHelper _output; + private static Lazy s_ipv6LocalHostNameLookupBrokenByNrpRule = new Lazy(() => + { + // On some machines using Microsoft corporate VPN, group policy installs an DNS Name Resolution Policy rule + // that breaks reverse lookup of ipv6 localhost names. + if (PlatformDetection.IsWindows) + { + // Equivalent of `Get-DnsClientNrptRule -Name .ip6.arpa` + using RegistryKey? key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DnsPolicyConfig"); + + if (key != null) + { + // Also filtering out anything not written by MSFTVPN + foreach (string name in key.GetSubKeyNames().Where(name => name.Contains("MSFTVPN"))) + { + using RegistryKey? key2 = key.OpenSubKey(name); + if (key2 != null && key2.GetValue("Name") is string[] values && values.Length == 1 && values[0] == ".ip6.arpa") + { + return true; + } + } + } + } + + return false; + }); + + private static bool Ipv6LocalHostNameLookupNotBrokenByNrpRule => !s_ipv6LocalHostNameLookupBrokenByNrpRule.Value; + public NameResolutionPalTests(ITestOutputHelper output) { _output = output; @@ -131,7 +161,7 @@ public void TryGetNameInfo_LocalHost_IPv4() Assert.NotNull(name); } - [Fact] + [ConditionalFact(nameof(Ipv6LocalHostNameLookupNotBrokenByNrpRule))] public void TryGetNameInfo_LocalHost_IPv6() { SocketError error; @@ -230,7 +260,7 @@ public void TryGetNameInfo_LocalHost_IPv4_TryGetAddrInfo(bool justAddresses) Assert.NotNull(addresses); } - [Theory] + [ConditionalTheory(nameof(Ipv6LocalHostNameLookupNotBrokenByNrpRule))] [InlineData(false)] [InlineData(true)] public void TryGetNameInfo_LocalHost_IPv6_TryGetAddrInfo(bool justAddresses) From faf481e9261b41588d7f1341a8047c0bd8ebc1e9 Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Tue, 25 Jan 2022 21:11:34 -0700 Subject: [PATCH 2/3] comment --- .../tests/PalTests/NameResolutionPalTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs b/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs index 66f3ec9d5a6ada..072ff2391f1975 100644 --- a/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs +++ b/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs @@ -19,7 +19,7 @@ public class NameResolutionPalTests private static Lazy s_ipv6LocalHostNameLookupBrokenByNrpRule = new Lazy(() => { - // On some machines using Microsoft corporate VPN, group policy installs an DNS Name Resolution Policy rule + // On some machines using Microsoft corporate VPN, something sometimes installs an DNS Name Resolution Policy rule // that breaks reverse lookup of ipv6 localhost names. if (PlatformDetection.IsWindows) { From ca57f070a0624eff890289d7d348333af698a04b Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Tue, 25 Jan 2022 21:12:29 -0700 Subject: [PATCH 3/3] nit --- .../tests/PalTests/NameResolutionPalTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs b/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs index 072ff2391f1975..d2c0b1fc229c65 100644 --- a/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs +++ b/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs @@ -25,7 +25,6 @@ public class NameResolutionPalTests { // Equivalent of `Get-DnsClientNrptRule -Name .ip6.arpa` using RegistryKey? key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DnsPolicyConfig"); - if (key != null) { // Also filtering out anything not written by MSFTVPN