use configuration for invalid host name (dotnet/corefx#41083)
authorTomas Weinfurt <tweinfurt@yahoo.com>
Fri, 13 Sep 2019 13:40:36 +0000 (06:40 -0700)
committerStephen Toub <stoub@microsoft.com>
Fri, 13 Sep 2019 13:40:36 +0000 (09:40 -0400)
Commit migrated from https://github.com/dotnet/corefx/commit/19ea63fee517327e1f6fbfa730300ddef5ef8a3b

src/libraries/Common/tests/System/Net/Configuration.Sockets.cs
src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs
src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj
src/libraries/System.Net.Sockets/tests/FunctionalTests/DnsEndPointTest.cs

index 52b0190..8f5cb34 100644 (file)
@@ -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");
         }
     }
 }
index 8c8a3c6..d10679e 100644 (file)
@@ -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())
             {
index 7d4d43f..bf572f8 100644 (file)
@@ -58,6 +58,9 @@
     <Compile Include="$(CommonTestPath)\System\Net\Configuration.Security.cs">
       <Link>Common\System\Net\Configuration.Security.cs</Link>
     </Compile>
+    <Compile Include="$(CommonTestPath)\System\Net\Configuration.Sockets.cs">
+      <Link>Common\System\Net\Configuration.Sockets.cs</Link>
+    </Compile>
     <Compile Include="$(CommonTestPath)\System\Net\TestWebProxies.cs">
       <Link>Common\System\Net\TestWebProxies.cs</Link>
     </Compile>
index 607a7ad..81f40bd 100644 (file)
@@ -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<SocketException>(() =>
                 {
-                    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<SocketException>(() =>
                 {
-                    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);