Skip to content

Commit

Permalink
[Android] Fix some System.Net tests (dotnet#71385)
Browse files Browse the repository at this point in the history
* Implement IncludeNetworkSecurityConfig

* Use IncludeNetworkSecurityConfig

* Fix tests

* Remove active issue attributes

* Rename certificate file

* Revert unnecessary changes

* TMP: re-throw caught exception to reveal more information in logs

* Revert "TMP: re-throw caught exception to reveal more information in logs"

This reverts commit 039d051.

* TMP: add and update res folders until they are merged into runtime-assets

* Fix System.Net.Requests tests

* Re-enable System.Net.Http functional tests

* Try fixing failing test

* Skip failing test

* Add missing using

* Remove temporary test data

* Relax exception type assertion for Android

* Code cleanup

* Fix test failures in System.Net.WebSockets.Client.Tests

* Remove active issue attribute

* Remove most explicit usages of the server certificate custom validation callback in tests

* Fix several tests

* Remove weird condition

* Code clean-up

* Remove unrelated active issue attributes

* Turn ActiveIssue attributes into permanent SkipOnPlatform

* Update explanation for SkipOnPlatform

* Revert partial fix and keep active issue

* Keep active issue for android x64 and x86

* Remove invalid attribute

* Fix test on Browser

* Allow all certificates by default

* Fix build

* Fix http client handler factory on Browser

* Skip failing test

* Fix net48 build

* Revert unintentional change in WinHttpHandler tests

* Avoid using unsupported property on Browser

* Remove unnecessary default value

* Avoid using unsupported property on Browser
  • Loading branch information
simonrozsival committed Jul 20, 2022
1 parent 47974ff commit e9b40f5
Show file tree
Hide file tree
Showing 55 changed files with 207 additions and 447 deletions.
1 change: 1 addition & 0 deletions eng/testing/tests.mobile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
MonoRuntimeHeaders="$(MicrosoftNetCoreAppRuntimePackNativeDir)include\mono-2.0"
Assemblies="@(BundleAssemblies)"
MainLibraryFileName="$(MainLibraryFileName)"
IncludeNetworkSecurityConfig="$(IncludeNetworkSecurityConfig)"
EnvironmentVariables="@(_AndroidEnv)"
ForceAOT="$(RunAOTCompilation)"
ForceInterpreter="$(MonoForceInterpreter)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public void SingletonReturnsTrue()
#pragma warning restore SYSLIB0039
[InlineData(SslProtocols.None, false)]
[InlineData(SslProtocols.None, true)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task SetDelegate_ConnectionSucceeds(SslProtocols acceptedProtocol, bool requestOnlyThisProtocol)
{
#pragma warning disable SYSLIB0039 // TLS 1.0 and 1.1 are obsolete
Expand All @@ -55,11 +54,9 @@ public async Task SetDelegate_ConnectionSucceeds(SslProtocols acceptedProtocol,
requestOnlyThisProtocol |= PlatformDetection.IsOSX && acceptedProtocol == SslProtocols.Tls;
#pragma warning restore SYSLIB0039

using (HttpClientHandler handler = CreateHttpClientHandler())
using (HttpClientHandler handler = CreateHttpClientHandler(allowAllCertificates: true))
using (HttpClient client = CreateHttpClient(handler))
{
handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

if (requestOnlyThisProtocol)
{
handler.SslProtocols = acceptedProtocol;
Expand Down Expand Up @@ -99,13 +96,12 @@ await TestHelper.WhenAllCompletedOrAnyFailed(
[OuterLoop]
[ConditionalTheory(nameof(ClientSupportsDHECipherSuites))]
[MemberData(nameof(InvalidCertificateServers))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
[SkipOnPlatform(TestPlatforms.Android, "Android rejects the certificate, the custom validation callback in .NET cannot override OS behavior in the current implementation")]
public async Task InvalidCertificateServers_CertificateValidationDisabled_Succeeds(string url)
{
using (HttpClientHandler handler = CreateHttpClientHandler())
using (HttpClientHandler handler = CreateHttpClientHandler(allowAllCertificates: true))
using (HttpClient client = CreateHttpClient(handler))
{
handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
(await client.GetAsync(url)).Dispose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public HttpClientHandler_Cancellation_Test(ITestOutputHelper output) : base(outp
[InlineData(false, CancellationMode.Token)]
[InlineData(true, CancellationMode.Token)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/36634", TestPlatforms.Browser)] // out of memory
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task PostAsync_CancelDuringRequestContentSend_TaskCanceledQuickly(bool chunkedTransfer, CancellationMode mode)
{
if (LoopbackServerFactory.Version >= HttpVersion20.Value && chunkedTransfer)
Expand Down Expand Up @@ -88,7 +87,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>

[Theory]
[MemberData(nameof(OneBoolAndCancellationMode))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_CancelDuringResponseHeadersReceived_TaskCanceledQuickly(bool connectionClose, CancellationMode mode)
{
if (LoopbackServerFactory.Version >= HttpVersion20.Value && connectionClose)
Expand Down Expand Up @@ -209,7 +207,6 @@ await ValidateClientCancellationAsync(async () =>
[Theory]
[MemberData(nameof(ThreeBools))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/65429", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_CancelDuringResponseBodyReceived_Unbuffered_TaskCanceledQuickly(bool chunkedTransfer, bool connectionClose, bool readOrCopyToAsync)
{
if (LoopbackServerFactory.Version >= HttpVersion20.Value && (chunkedTransfer || connectionClose))
Expand Down Expand Up @@ -293,7 +290,6 @@ await ValidateClientCancellationAsync(async () =>
[InlineData(CancellationMode.CancelPendingRequests, true)]
[InlineData(CancellationMode.DisposeHttpClient, true)]
[SkipOnPlatform(TestPlatforms.Browser, "Browser doesn't have blocking synchronous Stream.ReadByte and so it waits for whole body")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_CancelPendingRequests_DoesntCancelReadAsyncOnResponseStream(CancellationMode mode, bool copyToAsync)
{
if (IsWinHttpHandler && UseVersion >= HttpVersion20.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public void ClientCertificates_ClientCertificateOptionsAutomatic_ThrowsException

private HttpClient CreateHttpClientWithCert(X509Certificate2 cert)
{
HttpClientHandler handler = CreateHttpClientHandler();
handler.ServerCertificateCustomValidationCallback = TestHelper.AllowAllCertificates;
HttpClientHandler handler = CreateHttpClientHandler(allowAllCertificates: true);
Assert.NotNull(cert);
handler.ClientCertificates.Add(cert);
Assert.True(handler.ClientCertificates.Contains(cert));
Expand All @@ -81,7 +80,6 @@ private HttpClient CreateHttpClientWithCert(X509Certificate2 cert)
[InlineData(1, true)]
[InlineData(2, true)]
[InlineData(3, false)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task Manual_CertificateOnlySentWhenValid_Success(int certIndex, bool serverExpectsClientCertificate)
{
var options = new LoopbackServer.Options { UseSsl = true };
Expand Down Expand Up @@ -130,7 +128,6 @@ await TestHelper.WhenAllCompletedOrAnyFailed(
[Theory]
[InlineData(6, false)]
[InlineData(3, true)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task Manual_CertificateSentMatchesCertificateReceived_Success(
int numberOfRequests,
bool reuseClient) // validate behavior with and without connection pooling, which impacts client cert usage
Expand Down Expand Up @@ -190,10 +187,9 @@ await LoopbackServer.CreateServerAsync(async (server, url) =>
[InlineData(ClientCertificateOption.Automatic)]
public async Task AutomaticOrManual_DoesntFailRegardlessOfWhetherClientCertsAreAvailable(ClientCertificateOption mode)
{
using (HttpClientHandler handler = CreateHttpClientHandler())
using (HttpClientHandler handler = CreateHttpClientHandler(allowAllCertificates: true))
using (HttpClient client = CreateHttpClient(handler))
{
handler.ServerCertificateCustomValidationCallback = TestHelper.AllowAllCertificates;
handler.ClientCertificateOptions = mode;

await LoopbackServer.CreateServerAsync(async server =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ private static CookieContainer CreateSingleCookieContainer(Uri uri, string cooki
private static string GetCookieHeaderValue(string cookieName, string cookieValue) => $"{cookieName}={cookieValue}";

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_DefaultCoookieContainer_NoCookieSent()
{
await LoopbackServerFactory.CreateClientAndServerAsync(
Expand All @@ -65,7 +64,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(
[Theory]
[MemberData(nameof(CookieNamesValuesAndUseCookies))]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_SetCookieContainer_CookieSent(string cookieName, string cookieValue, bool useCookies)
{
await LoopbackServerFactory.CreateClientAndServerAsync(
Expand Down Expand Up @@ -96,7 +94,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_SetCookieContainerMultipleCookies_CookiesSent()
{
var cookies = new Cookie[]
Expand Down Expand Up @@ -131,7 +128,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_AddCookieHeader_CookieHeaderSent()
{
await LoopbackServerFactory.CreateClientAndServerAsync(
Expand All @@ -153,7 +149,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_AddMultipleCookieHeaders_CookiesSent()
{
await LoopbackServerFactory.CreateClientAndServerAsync(
Expand Down Expand Up @@ -223,7 +218,6 @@ private string GetCookieValue(HttpRequestData request)

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_SetCookieContainerAndCookieHeader_BothCookiesSent()
{
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
Expand Down Expand Up @@ -252,7 +246,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_SetCookieContainerAndMultipleCookieHeaders_BothCookiesSent()
{
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
Expand Down Expand Up @@ -293,7 +286,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsyncWithRedirect_SetCookieContainer_CorrectCookiesSent()
{
if (UseVersion == HttpVersion30)
Expand Down Expand Up @@ -341,7 +333,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async url =>
[Theory]
[MemberData(nameof(CookieNamesValuesAndUseCookies))]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_ReceiveSetCookieHeader_CookieAdded(string cookieName, string cookieValue, bool useCookies)
{
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
Expand Down Expand Up @@ -374,7 +365,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_ReceiveMultipleSetCookieHeaders_CookieAdded()
{
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
Expand Down Expand Up @@ -415,7 +405,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
// ConditionalFact: CookieContainer does not follow RFC6265 on .NET Framework, therefore the (WinHttpHandler) test is expected to fail
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetFramework))]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_NoPathDefined_CookieAddedWithDefaultPath()
{
await LoopbackServerFactory.CreateServerAsync(async (server, serverUrl) =>
Expand Down Expand Up @@ -446,7 +435,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, serverUrl) =>
// ConditionalFact: CookieContainer does not follow RFC6265 on .NET Framework, therefore the (WinHttpHandler) test is expected to fail
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetFramework))]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_CookiePathDoesNotMatchRequestPath_CookieAccepted()
{
await LoopbackServerFactory.CreateServerAsync(async (server, serverUrl) =>
Expand Down Expand Up @@ -479,7 +467,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, serverUrl) =>
// ConditionalFact: CookieContainer does not follow RFC6265 on .NET Framework, therefore the (WinHttpHandler) test is expected to fail
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetFramework))]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_Redirect_CookiesArePreserved()
{
if (UseVersion == HttpVersion30)
Expand Down Expand Up @@ -529,7 +516,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async serverUrl =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_ReceiveSetCookieHeader_CookieUpdated()
{
const string newCookieValue = "789";
Expand Down Expand Up @@ -558,7 +544,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_ReceiveSetCookieHeader_CookieRemoved()
{
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
Expand All @@ -583,7 +568,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsync_ReceiveInvalidSetCookieHeader_ValidCookiesAdded()
{
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
Expand Down Expand Up @@ -619,7 +603,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsyncWithRedirect_ReceiveSetCookie_CookieSent()
{
if (UseVersion == HttpVersion30)
Expand Down Expand Up @@ -680,7 +663,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async url =>

[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
public async Task GetAsyncWithBasicAuth_ReceiveSetCookie_CookieSent()
{
if (UseVersion == HttpVersion30)
Expand Down
Loading

0 comments on commit e9b40f5

Please sign in to comment.