Skip to content

Commit

Permalink
WASM: Fix System.Net.Primitives and tests (dotnet#39748)
Browse files Browse the repository at this point in the history
Add HostInformationPal and InterfaceInfoPal implementations for Browser.

In CookiePortTest.cs use example.com instead of localhost for the tests since Browser uses `localhost` as the `Environment.MachineName` and that changes the test values.

Allows the tests to run on WebAssembly:
```
System.Net.Primitives.Pal.Tests: Tests run: 60, Errors: 0, Failures: 0, Skipped: 0. Time: 0.15872s
System.Net.Primitives.Functional.Tests: Tests run: 2620, Errors: 0, Failures: 0, Skipped: 1. Time: 3.145804s
```
  • Loading branch information
akoeplinger authored Jul 23, 2020
1 parent 30e6b79 commit 7de187a
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Net.NetworkInformation
{
internal static class HostInformationPal
{
public static string GetHostName()
{
return Environment.MachineName;
}

public static string GetDomainName()
{
return Environment.UserDomainName;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Net.NetworkInformation
{
internal static class InterfaceInfoPal
{
public static uint InterfaceNameToIndex(string interfaceName)
{
// zero means "unknown"
return 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,22 @@
<Compile Include="System\Net\SocketException.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\SocketAddressPal.Unix.cs"
Link="Common\System\Net\SocketAddressPal.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\NetworkInformation\HostInformationPal.Unix.cs"
Link="Common\System\Net\NetworkInformation\HostInformationPal.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\Sockets\SocketErrorPal.Unix.cs"
Link="Common\System\Net\Sockets\SocketErrorPal.Unix.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Errors.cs"
Link="Common\Interop\Unix\Interop.Errors.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs"
Link="Common\Interop\Unix\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.IPAddress.cs"
Link="Common\Interop\Unix\System.Native\Interop.IPAddress.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.SocketAddress.cs"
Link="Common\Interop\Unix\System.Native\Interop.SocketAddress.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
<Compile Include="$(CommonPath)System\Net\NetworkInformation\HostInformationPal.Unix.cs"
Link="Common\System\Net\NetworkInformation\HostInformationPal.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\NetworkInformation\InterfaceInfoPal.Unix.cs"
Link="Common\System\Net\NetworkInformation\InterfaceInfoPal.Unix.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetDomainName.cs"
Link="Common\Interop\Unix\System.Native\Interop.GetDomainName.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetHostName.cs"
Expand All @@ -133,14 +141,14 @@
Link="Common\Interop\Unix\System.Native\Interop.GetNameInfo.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.HostEntry.cs"
Link="Common\Interop\Unix\System.Native\Interop.HostEntry.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.IPAddress.cs"
Link="Common\Interop\Unix\System.Native\Interop.IPAddress.cs" />
<Compile Include="$(CommonPath)System\Net\NetworkInformation\InterfaceInfoPal.Unix.cs"
Link="Common\System\Net\NetworkInformation\InterfaceInfoPal.Unix.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.InterfaceNameToIndex.cs"
Link="Common\Interop\Unix\System.Native\Interop.InterfaceNameToIndex.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.SocketAddress.cs"
Link="Common\Interop\Unix\System.Native\Interop.SocketAddress.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsBrowser)' == 'true'">
<Compile Include="$(CommonPath)System\Net\NetworkInformation\HostInformationPal.Browser.cs"
Link="Common\System\Net\NetworkInformation\HostInformationPal.Browser.cs" />
<Compile Include="$(CommonPath)System\Net\NetworkInformation\InterfaceInfoPal.Browser.cs"
Link="Common\System\Net\NetworkInformation\InterfaceInfoPal.Browser.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Win32.Primitives" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,65 +13,65 @@ public class CookiePortTest
public CookiePortTest()
{
_cc = new CookieContainer();
_cookie = new Cookie("name", "value1", "/path", "localhost");
_cookie = new Cookie("name", "value1", "/path", "example.com");
// use both space and comma as delimiter
_cookie.Port = "\"80 110,1050, 1090 ,1100\"";
_cc.Add(new Uri("http://localhost/path"), _cookie);
_cc.Add(new Uri("http://example.com/path"), _cookie);
}

[Fact]
public void Port_SetMultiplePorts_Port1Set()
{
CookieCollection cookies = _cc.GetCookies(new Uri("http://localhost:80/path"));
CookieCollection cookies = _cc.GetCookies(new Uri("http://example.com:80/path"));
Assert.Equal(1, cookies.Count);
}

[Fact]
public void Port_SpaceDelimiter_PortSet()
{
CookieCollection cookies = _cc.GetCookies(new Uri("http://localhost:110/path"));
CookieCollection cookies = _cc.GetCookies(new Uri("http://example.com:110/path"));
Assert.Equal(1, cookies.Count);
}

[Fact]
public void Port_CommaDelimiter_PortSet()
{
CookieCollection cookies = _cc.GetCookies(new Uri("http://localhost:1050/path"));
CookieCollection cookies = _cc.GetCookies(new Uri("http://example.com:1050/path"));
Assert.Equal(1, cookies.Count);
}

[Fact]
public void Port_CommaSpaceDelimiter_PortSet()
{
CookieCollection cookies = _cc.GetCookies(new Uri("http://localhost:1090/path"));
CookieCollection cookies = _cc.GetCookies(new Uri("http://example.com:1090/path"));
Assert.Equal(1, cookies.Count);
}

[Fact]
public void Port_SpaceCommaDelimiter_PortSet()
{
CookieCollection cookies = _cc.GetCookies(new Uri("http://localhost:1100/path"));
CookieCollection cookies = _cc.GetCookies(new Uri("http://example.com:1100/path"));
Assert.Equal(1, cookies.Count);
}

[Fact]
public void Port_SetMultiplePorts_NoPortMatch()
{
CookieCollection cookies = _cc.GetCookies(new Uri("http://localhost:1000/path"));
CookieCollection cookies = _cc.GetCookies(new Uri("http://example.com:1000/path"));
Assert.Equal(0, cookies.Count);
}

[Fact]
public void Port_SetMultiplePorts_NoPathMatch()
{
CookieCollection cookies = _cc.GetCookies(new Uri("http://localhost:1050"));
CookieCollection cookies = _cc.GetCookies(new Uri("http://example.com:1050"));
Assert.Equal(0, cookies.Count);
}

[Fact]
public void Port_NoPortSpecified_ReturnsCookies()
{
CookieCollection cookies = _cc.GetCookies(new Uri("http://localhost/path"));
CookieCollection cookies = _cc.GetCookies(new Uri("http://example.com/path"));
Assert.Equal(1, cookies.Count);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static void ToString_LegacyUnknownFamily_Success(AddressFamily family)
[Theory]
[InlineData(AddressFamily.Packet)]
[InlineData(AddressFamily.ControllerAreaNetwork)]
[PlatformSpecific(~TestPlatforms.Linux)]
[PlatformSpecific(~(TestPlatforms.Linux | TestPlatforms.Browser))]
public static void ToString_UnsupportedFamily_Throws(AddressFamily family)
{
Assert.Throws<PlatformNotSupportedException>(() => new SocketAddress(family));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@
<ItemGroup Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true'">
<Compile Include="..\..\src\System\Net\SocketException.Unix.cs"
Link="ProductionCode\System\Net\SocketException.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\NetworkInformation\HostInformationPal.Unix.cs"
Link="Common\System\Net\NetworkInformation\HostInformationPal.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\SocketAddressPal.Unix.cs"
Link="Common\System\Net\SocketAddressPal.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\Sockets\SocketErrorPal.Unix.cs"
Expand All @@ -97,21 +95,31 @@
Link="ProductionCode\Interop\Unix\Interop.Errors.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs"
Link="ProductionCode\Common\Interop\Unix\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetDomainName.cs"
Link="ProductionCode\Common\Interop\Unix\System.Native\Interop.GetDomainName.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetHostName.cs"
Link="ProductionCode\Common\Interop\Unix\System.Native\Interop.GetHostName.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetNameInfo.cs"
Link="ProductionCode\Common\Interop\Unix\System.Native\Interop.GetNameInfo.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.HostEntry.cs"
Link="ProductionCode\Common\Interop\Unix\System.Native\Interop.HostEntry.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.IPAddress.cs"
Link="ProductionCode\Common\Interop\Unix\System.Native\Interop.IPAddress.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.SocketAddress.cs"
Link="ProductionCode\Common\Interop\Unix\System.Native\Interop.SocketAddress.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
<Compile Include="$(CommonPath)System\Net\NetworkInformation\HostInformationPal.Unix.cs"
Link="Common\System\Net\NetworkInformation\HostInformationPal.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\NetworkInformation\InterfaceInfoPal.Unix.cs"
Link="ProductionCode\Common\System\Net\NetworkInformation\InterfaceInfoPal.Unix.cs" />
Link="Common\System\Net\NetworkInformation\InterfaceInfoPal.Unix.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetDomainName.cs"
Link="Common\Interop\Unix\System.Native\Interop.GetDomainName.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetHostName.cs"
Link="Common\Interop\Unix\System.Native\Interop.GetHostName.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetNameInfo.cs"
Link="Common\Interop\Unix\System.Native\Interop.GetNameInfo.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.HostEntry.cs"
Link="Common\Interop\Unix\System.Native\Interop.HostEntry.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.InterfaceNameToIndex.cs"
Link="ProductionCode\Common\Interop\Unix\System.Native\Interop.InterfaceNameToIndex.cs" />
Link="Common\Interop\Unix\System.Native\Interop.InterfaceNameToIndex.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsBrowser)' == 'true'">
<Compile Include="$(CommonPath)System\Net\NetworkInformation\HostInformationPal.Browser.cs"
Link="Common\System\Net\NetworkInformation\HostInformationPal.Browser.cs" />
<Compile Include="$(CommonPath)System\Net\NetworkInformation\InterfaceInfoPal.Browser.cs"
Link="ProductionCode\Common\System\Net\NetworkInformation\InterfaceInfoPal.Browser.cs" />
</ItemGroup>
</Project>
2 changes: 0 additions & 2 deletions src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.IO.FileSystem\tests\System.IO.FileSystem.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Linq.Parallel\tests\System.Linq.Parallel.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.Http\tests\FunctionalTests\System.Net.Http.Functional.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.Primitives\tests\FunctionalTests\System.Net.Primitives.Functional.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.Primitives\tests\PalTests\System.Net.Primitives.Pal.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.WebSockets.Client\tests\System.Net.WebSockets.Client.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.ObjectModel\tests\System.ObjectModel.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Private.Uri\tests\FunctionalTests\System.Private.Uri.Functional.Tests.csproj" />
Expand Down

0 comments on commit 7de187a

Please sign in to comment.