From 4b7edb600369156ae7108980727890611ba8b33a Mon Sep 17 00:00:00 2001 From: Tomas Weinfurt Date: Fri, 13 Sep 2019 06:40:36 -0700 Subject: [PATCH] use configuration for invalid host name (dotnet/corefx#41083) Commit migrated from https://github.com/dotnet/corefx/commit/19ea63fee517327e1f6fbfa730300ddef5ef8a3b --- src/libraries/Common/tests/System/Net/Configuration.Sockets.cs | 2 ++ .../tests/FunctionalTests/HttpClientHandlerTest.cs | 2 +- .../FunctionalTests/System.Net.Http.Functional.Tests.csproj | 3 +++ .../tests/FunctionalTests/DnsEndPointTest.cs | 10 ++++++---- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Configuration.Sockets.cs b/src/libraries/Common/tests/System/Net/Configuration.Sockets.cs index 52b0190..8f5cb34 100644 --- a/src/libraries/Common/tests/System/Net/Configuration.Sockets.cs +++ b/src/libraries/Common/tests/System/Net/Configuration.Sockets.cs @@ -9,6 +9,8 @@ namespace System.Net.Test.Common public static partial class Sockets { public static Uri SocketServer => GetUriValue("COREFX_NET_SOCKETS_SERVERURI", new Uri("http://" + DefaultAzureServer)); + + public static string InvalidHost => GetValue("COREFX_NET_SOCKETS_INVALIDSERVER", "notahostname.invalid.corp.microsoft.com"); } } } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs index 8c8a3c6..d10679e 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs @@ -2681,7 +2681,7 @@ namespace System.Net.Http.Functional.Tests [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // [ActiveIssue(11057)] public async Task GetAsync_InvalidUrl_ExpectedExceptionThrown() { - string invalidUri = $"http://_{Guid.NewGuid().ToString("N")}"; + string invalidUri = $"http://{Configuration.Sockets.InvalidHost}"; _output.WriteLine($"{DateTime.Now} connecting to {invalidUri}"); using (HttpClient client = CreateHttpClient()) { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj index 7d4d43f..bf572f8 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj @@ -58,6 +58,9 @@ Common\System\Net\Configuration.Security.cs + + Common\System\Net\Configuration.Sockets.cs + Common\System\Net\TestWebProxies.cs diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/DnsEndPointTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/DnsEndPointTest.cs index 607a7ad..81f40bd 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/DnsEndPointTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/DnsEndPointTest.cs @@ -10,6 +10,8 @@ using Xunit.Abstractions; namespace System.Net.Sockets.Tests { + using Configuration = System.Net.Test.Common.Configuration; + public class DnsEndPointTest : DualModeBase { private void OnConnectAsyncCompleted(object sender, SocketAsyncEventArgs args) @@ -60,7 +62,7 @@ namespace System.Net.Sockets.Tests { SocketException ex = Assert.ThrowsAny(() => { - sock.Connect(new DnsEndPoint("notahostname.invalid.corp.microsoft.com", UnusedPort)); + sock.Connect(new DnsEndPoint(Configuration.Sockets.InvalidHost, UnusedPort)); }); SocketError errorCode = ex.SocketErrorCode; @@ -150,7 +152,7 @@ namespace System.Net.Sockets.Tests { SocketException ex = Assert.ThrowsAny(() => { - IAsyncResult result = sock.BeginConnect(new DnsEndPoint("notahostname.invalid.corp.microsoft.com", UnusedPort), null, null); + IAsyncResult result = sock.BeginConnect(new DnsEndPoint(Configuration.Sockets.InvalidHost, UnusedPort), null, null); sock.EndConnect(result); }); @@ -256,7 +258,7 @@ namespace System.Net.Sockets.Tests Assert.True(Capability.IPv4Support()); SocketAsyncEventArgs args = new SocketAsyncEventArgs(); - args.RemoteEndPoint = new DnsEndPoint("notahostname.invalid.corp.microsoft.com", UnusedPort); + args.RemoteEndPoint = new DnsEndPoint(Configuration.Sockets.InvalidHost, UnusedPort); args.Completed += OnConnectAsyncCompleted; using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) @@ -356,7 +358,7 @@ namespace System.Net.Sockets.Tests public void Socket_StaticConnectAsync_HostNotFound() { SocketAsyncEventArgs args = new SocketAsyncEventArgs(); - args.RemoteEndPoint = new DnsEndPoint("notahostname.invalid.corp.microsoft.com", UnusedPort); + args.RemoteEndPoint = new DnsEndPoint(Configuration.Sockets.InvalidHost, UnusedPort); args.Completed += OnConnectAsyncCompleted; ManualResetEvent complete = new ManualResetEvent(false); -- 2.7.4