Skip to content

Commit e9b40f5

Browse files
[Android] Fix some System.Net tests (#71385)
* 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
1 parent 47974ff commit e9b40f5

File tree

55 files changed

+207
-447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+207
-447
lines changed

eng/testing/tests.mobile.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
MonoRuntimeHeaders="$(MicrosoftNetCoreAppRuntimePackNativeDir)include\mono-2.0"
154154
Assemblies="@(BundleAssemblies)"
155155
MainLibraryFileName="$(MainLibraryFileName)"
156+
IncludeNetworkSecurityConfig="$(IncludeNetworkSecurityConfig)"
156157
EnvironmentVariables="@(_AndroidEnv)"
157158
ForceAOT="$(RunAOTCompilation)"
158159
ForceInterpreter="$(MonoForceInterpreter)"

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.AcceptAllCerts.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public void SingletonReturnsTrue()
4646
#pragma warning restore SYSLIB0039
4747
[InlineData(SslProtocols.None, false)]
4848
[InlineData(SslProtocols.None, true)]
49-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
5049
public async Task SetDelegate_ConnectionSucceeds(SslProtocols acceptedProtocol, bool requestOnlyThisProtocol)
5150
{
5251
#pragma warning disable SYSLIB0039 // TLS 1.0 and 1.1 are obsolete
@@ -55,11 +54,9 @@ public async Task SetDelegate_ConnectionSucceeds(SslProtocols acceptedProtocol,
5554
requestOnlyThisProtocol |= PlatformDetection.IsOSX && acceptedProtocol == SslProtocols.Tls;
5655
#pragma warning restore SYSLIB0039
5756

58-
using (HttpClientHandler handler = CreateHttpClientHandler())
57+
using (HttpClientHandler handler = CreateHttpClientHandler(allowAllCertificates: true))
5958
using (HttpClient client = CreateHttpClient(handler))
6059
{
61-
handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
62-
6360
if (requestOnlyThisProtocol)
6461
{
6562
handler.SslProtocols = acceptedProtocol;
@@ -99,13 +96,12 @@ await TestHelper.WhenAllCompletedOrAnyFailed(
9996
[OuterLoop]
10097
[ConditionalTheory(nameof(ClientSupportsDHECipherSuites))]
10198
[MemberData(nameof(InvalidCertificateServers))]
102-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
99+
[SkipOnPlatform(TestPlatforms.Android, "Android rejects the certificate, the custom validation callback in .NET cannot override OS behavior in the current implementation")]
103100
public async Task InvalidCertificateServers_CertificateValidationDisabled_Succeeds(string url)
104101
{
105-
using (HttpClientHandler handler = CreateHttpClientHandler())
102+
using (HttpClientHandler handler = CreateHttpClientHandler(allowAllCertificates: true))
106103
using (HttpClient client = CreateHttpClient(handler))
107104
{
108-
handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
109105
(await client.GetAsync(url)).Dispose();
110106
}
111107
}

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Cancellation.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public HttpClientHandler_Cancellation_Test(ITestOutputHelper output) : base(outp
2929
[InlineData(false, CancellationMode.Token)]
3030
[InlineData(true, CancellationMode.Token)]
3131
[ActiveIssue("https://github.com/dotnet/runtime/issues/36634", TestPlatforms.Browser)] // out of memory
32-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
3332
public async Task PostAsync_CancelDuringRequestContentSend_TaskCanceledQuickly(bool chunkedTransfer, CancellationMode mode)
3433
{
3534
if (LoopbackServerFactory.Version >= HttpVersion20.Value && chunkedTransfer)
@@ -88,7 +87,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
8887

8988
[Theory]
9089
[MemberData(nameof(OneBoolAndCancellationMode))]
91-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
9290
public async Task GetAsync_CancelDuringResponseHeadersReceived_TaskCanceledQuickly(bool connectionClose, CancellationMode mode)
9391
{
9492
if (LoopbackServerFactory.Version >= HttpVersion20.Value && connectionClose)
@@ -209,7 +207,6 @@ await ValidateClientCancellationAsync(async () =>
209207
[Theory]
210208
[MemberData(nameof(ThreeBools))]
211209
[ActiveIssue("https://github.com/dotnet/runtime/issues/65429", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
212-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
213210
public async Task GetAsync_CancelDuringResponseBodyReceived_Unbuffered_TaskCanceledQuickly(bool chunkedTransfer, bool connectionClose, bool readOrCopyToAsync)
214211
{
215212
if (LoopbackServerFactory.Version >= HttpVersion20.Value && (chunkedTransfer || connectionClose))
@@ -293,7 +290,6 @@ await ValidateClientCancellationAsync(async () =>
293290
[InlineData(CancellationMode.CancelPendingRequests, true)]
294291
[InlineData(CancellationMode.DisposeHttpClient, true)]
295292
[SkipOnPlatform(TestPlatforms.Browser, "Browser doesn't have blocking synchronous Stream.ReadByte and so it waits for whole body")]
296-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
297293
public async Task GetAsync_CancelPendingRequests_DoesntCancelReadAsyncOnResponseStream(CancellationMode mode, bool copyToAsync)
298294
{
299295
if (IsWinHttpHandler && UseVersion >= HttpVersion20.Value)

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.ClientCertificates.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ public void ClientCertificates_ClientCertificateOptionsAutomatic_ThrowsException
6868

6969
private HttpClient CreateHttpClientWithCert(X509Certificate2 cert)
7070
{
71-
HttpClientHandler handler = CreateHttpClientHandler();
72-
handler.ServerCertificateCustomValidationCallback = TestHelper.AllowAllCertificates;
71+
HttpClientHandler handler = CreateHttpClientHandler(allowAllCertificates: true);
7372
Assert.NotNull(cert);
7473
handler.ClientCertificates.Add(cert);
7574
Assert.True(handler.ClientCertificates.Contains(cert));
@@ -81,7 +80,6 @@ private HttpClient CreateHttpClientWithCert(X509Certificate2 cert)
8180
[InlineData(1, true)]
8281
[InlineData(2, true)]
8382
[InlineData(3, false)]
84-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
8583
public async Task Manual_CertificateOnlySentWhenValid_Success(int certIndex, bool serverExpectsClientCertificate)
8684
{
8785
var options = new LoopbackServer.Options { UseSsl = true };
@@ -130,7 +128,6 @@ await TestHelper.WhenAllCompletedOrAnyFailed(
130128
[Theory]
131129
[InlineData(6, false)]
132130
[InlineData(3, true)]
133-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
134131
public async Task Manual_CertificateSentMatchesCertificateReceived_Success(
135132
int numberOfRequests,
136133
bool reuseClient) // validate behavior with and without connection pooling, which impacts client cert usage
@@ -190,10 +187,9 @@ await LoopbackServer.CreateServerAsync(async (server, url) =>
190187
[InlineData(ClientCertificateOption.Automatic)]
191188
public async Task AutomaticOrManual_DoesntFailRegardlessOfWhetherClientCertsAreAvailable(ClientCertificateOption mode)
192189
{
193-
using (HttpClientHandler handler = CreateHttpClientHandler())
190+
using (HttpClientHandler handler = CreateHttpClientHandler(allowAllCertificates: true))
194191
using (HttpClient client = CreateHttpClient(handler))
195192
{
196-
handler.ServerCertificateCustomValidationCallback = TestHelper.AllowAllCertificates;
197193
handler.ClientCertificateOptions = mode;
198194

199195
await LoopbackServer.CreateServerAsync(async server =>

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Cookies.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ private static CookieContainer CreateSingleCookieContainer(Uri uri, string cooki
4444
private static string GetCookieHeaderValue(string cookieName, string cookieValue) => $"{cookieName}={cookieValue}";
4545

4646
[Fact]
47-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
4847
public async Task GetAsync_DefaultCoookieContainer_NoCookieSent()
4948
{
5049
await LoopbackServerFactory.CreateClientAndServerAsync(
@@ -65,7 +64,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(
6564
[Theory]
6665
[MemberData(nameof(CookieNamesValuesAndUseCookies))]
6766
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
68-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
6967
public async Task GetAsync_SetCookieContainer_CookieSent(string cookieName, string cookieValue, bool useCookies)
7068
{
7169
await LoopbackServerFactory.CreateClientAndServerAsync(
@@ -96,7 +94,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(
9694

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

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

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

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

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

294287
[Fact]
295288
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
296-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
297289
public async Task GetAsyncWithRedirect_SetCookieContainer_CorrectCookiesSent()
298290
{
299291
if (UseVersion == HttpVersion30)
@@ -341,7 +333,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async url =>
341333
[Theory]
342334
[MemberData(nameof(CookieNamesValuesAndUseCookies))]
343335
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
344-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
345336
public async Task GetAsync_ReceiveSetCookieHeader_CookieAdded(string cookieName, string cookieValue, bool useCookies)
346337
{
347338
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
@@ -374,7 +365,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
374365

375366
[Fact]
376367
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
377-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
378368
public async Task GetAsync_ReceiveMultipleSetCookieHeaders_CookieAdded()
379369
{
380370
await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
@@ -415,7 +405,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
415405
// ConditionalFact: CookieContainer does not follow RFC6265 on .NET Framework, therefore the (WinHttpHandler) test is expected to fail
416406
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetFramework))]
417407
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
418-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
419408
public async Task GetAsync_NoPathDefined_CookieAddedWithDefaultPath()
420409
{
421410
await LoopbackServerFactory.CreateServerAsync(async (server, serverUrl) =>
@@ -446,7 +435,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, serverUrl) =>
446435
// ConditionalFact: CookieContainer does not follow RFC6265 on .NET Framework, therefore the (WinHttpHandler) test is expected to fail
447436
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetFramework))]
448437
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
449-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
450438
public async Task GetAsync_CookiePathDoesNotMatchRequestPath_CookieAccepted()
451439
{
452440
await LoopbackServerFactory.CreateServerAsync(async (server, serverUrl) =>
@@ -479,7 +467,6 @@ await LoopbackServerFactory.CreateServerAsync(async (server, serverUrl) =>
479467
// ConditionalFact: CookieContainer does not follow RFC6265 on .NET Framework, therefore the (WinHttpHandler) test is expected to fail
480468
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetFramework))]
481469
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
482-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
483470
public async Task GetAsync_Redirect_CookiesArePreserved()
484471
{
485472
if (UseVersion == HttpVersion30)
@@ -529,7 +516,6 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async serverUrl =>
529516

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

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

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

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

681664
[Fact]
682665
[SkipOnPlatform(TestPlatforms.Browser, "CookieContainer is not supported on Browser")]
683-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69870", TestPlatforms.Android)]
684666
public async Task GetAsyncWithBasicAuth_ReceiveSetCookie_CookieSent()
685667
{
686668
if (UseVersion == HttpVersion30)

0 commit comments

Comments
 (0)