Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM: Fix System.Net.Primitives and tests #39748

Merged
merged 1 commit into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this needs to be changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wfurt See the PR description:

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part I don't understand is why that would impact cookies. We don't do any networking here AFAIK, right?

Copy link
Member Author

@akoeplinger akoeplinger Jul 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wfurt we don't do networking but we still read the domain name (which on netcore on Unix generally means the machine name) here:

private static string CreateFqdnMyDomain()
{
string domain = HostInformation.DomainName;
return domain != null && domain.Length > 1 ?
'.' + domain :
string.Empty;
}

That is later on used for this check:

// First quick check is for pushing a cookie into the local domain.
if (isLocalDomain && string.Equals(localDomain, domain, StringComparison.OrdinalIgnoreCase))
{
valid = true;
}

Since localDomain and domain are both localhost we're going into that branch, which doesn't happen when the machine/domain name is set to any other value.

The result is that instead of getting this cookie once in the tests I'm getting it twice which fails the test:

Cookie:
    name = value1
    Domain: localhost
    Path: /path
    Port: "80 110,1050, 1090 ,1100"
    Secure: False
    When issued: 07/22/2020 17:46:32
    Expires: 01/01/0001 00:00:00 (expired? False)
    Don't save: False
    Comment:
    Uri for comments:
    Version: RFC 2109

Do you think it could be a product bug?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for explanation. This is not my primary are and I'll ask around.

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 @@ -33,8 +33,6 @@
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Linq.Expressions\tests\System.Linq.Expressions.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