Skip to content

Commit

Permalink
use configuration for invalid host name (dotnet/corefx#41083)
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/corefx@19ea63f
  • Loading branch information
wfurt authored and stephentoub committed Sep 13, 2019
1 parent e3f67d1 commit 4b7edb6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public static partial class Configuration
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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, rootUrl) =>
[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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace System.Net.Sockets.Tests
{
using Configuration = System.Net.Test.Common.Configuration;

public class DnsEndPointTest : DualModeBase
{
private void OnConnectAsyncCompleted(object sender, SocketAsyncEventArgs args)
Expand Down Expand Up @@ -60,7 +62,7 @@ public void Socket_ConnectDnsEndPoint_Failure()
{
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;
Expand Down Expand Up @@ -150,7 +152,7 @@ public void Socket_BeginConnectDnsEndPoint_Failure()
{
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);
});

Expand Down Expand Up @@ -256,7 +258,7 @@ public void Socket_ConnectAsyncDnsEndPoint_HostNotFound()
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))
Expand Down Expand Up @@ -356,7 +358,7 @@ public void Socket_StaticConnectAsync_Success(SocketImplementationType type)
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);
Expand Down

0 comments on commit 4b7edb6

Please sign in to comment.