Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Re-enable failing httplistener tests on osx. (#19955)
Browse files Browse the repository at this point in the history
* Re-enable failing httplistener tests on osx.

* Fix edge cases in httplistener prefixes.

* Throw exception for all unresolved hostnames.
  • Loading branch information
Priya91 authored and stephentoub committed May 29, 2017
1 parent 167bccd commit a4fe5cc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
3 changes: 3 additions & 0 deletions src/System.Net.HttpListener/src/Resources/Strings.resx
Expand Up @@ -85,6 +85,9 @@
<data name="net_listener_host" xml:space="preserve">
<value>Only Uri prefixes with a valid hostname are supported.</value>
</data>
<data name="net_listener_not_supported" xml:space="preserve">
<value>The request is not supported.</value>
</data>
<data name="net_listener_mustcall" xml:space="preserve">
<value>Please call the {0} method before calling this method.</value>
</data>
Expand Down
Expand Up @@ -111,21 +111,24 @@ private static HttpEndPointListener GetEPListener(string host, int port, HttpLis
IPAddress addr;
if (host == "*")
addr = IPAddress.Any;
else if (IPAddress.TryParse(host, out addr) == false)
else
{
try
{
IPHostEntry iphost = Dns.GetHostEntry(host);
if (iphost != null)
addr = iphost.AddressList[0];
else
addr = IPAddress.Any;
addr = Dns.GetHostAddresses(host)[0];
if (IPAddress.Any.Equals(addr))
{
// Don't support listening to 0.0.0.0, match windows behavior.
throw new HttpListenerException(50, SR.net_listener_not_supported);
}
}
catch
{
addr = IPAddress.Any;
// Throw same error code as windows, request is not supported.
throw new HttpListenerException(50, SR.net_listener_not_supported);
}
}

Dictionary<int, HttpEndPointListener> p = null;
if (s_ipEndPoints.ContainsKey(addr))
{
Expand Down
Expand Up @@ -345,11 +345,8 @@ public void Add_SamePortDifferentPathMultipleStarted_Success(string host)

public static IEnumerable<object[]> InvalidPrefix_TestData()
{
// [ActiveIssue(19593, TestPlatforms.OSX)]
if (!PlatformDetection.IsOSX)
{
yield return new object[] { $"http://{Guid.NewGuid().ToString("N")}/" };
}
yield return new object[] { "http://0.0.0.0/" };
yield return new object[] { "http://192./" };
yield return new object[] { "http://[]/" };
yield return new object[] { "http://[::1%2]/" };
yield return new object[] { "http://[::]/" };
Expand All @@ -362,7 +359,7 @@ public static IEnumerable<object[]> InvalidPrefix_TestData()
yield return new object[] { "http://\\/" };
}

[ActiveIssue(19619)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)] // Issue #19619
[Theory]
[MemberData(nameof(InvalidPrefix_TestData))]
public void Add_InvalidPrefixNotStarted_ThrowsHttpListenerExceptionOnStart(string uriPrefix)
Expand All @@ -375,7 +372,7 @@ public void Add_InvalidPrefixNotStarted_ThrowsHttpListenerExceptionOnStart(strin
Assert.Throws<HttpListenerException>(() => listener.Start());
}

[ActiveIssue(19619)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)] // Issue #19619
[Theory]
[MemberData(nameof(InvalidPrefix_TestData))]
public void Add_InvalidPrefixAlreadyStarted_ThrowsHttpListenerExceptionOnAdd(string uriPrefix)
Expand All @@ -389,16 +386,6 @@ public void Add_InvalidPrefixAlreadyStarted_ThrowsHttpListenerExceptionOnAdd(str
}
}

[ActiveIssue(19619)]
[Theory]
[ActiveIssue(18128, TestPlatforms.AnyUnix)] // Fails by design on Windows but is allowed by the managed implementation
[InlineData("http://192./")]
public void Add_InvalidPrefix_ThrowsHttpListenerException_Windows(string uriPrefix)
{
Add_InvalidPrefixNotStarted_ThrowsHttpListenerExceptionOnStart(uriPrefix);
Add_InvalidPrefixAlreadyStarted_ThrowsHttpListenerExceptionOnAdd(uriPrefix);
}

[Theory]
[InlineData("")]
[InlineData("http")]
Expand Down

0 comments on commit a4fe5cc

Please sign in to comment.