From 234cf2c022e772189bbfae8392b058fde714013f Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Thu, 27 Jan 2022 19:43:11 -0500 Subject: [PATCH] [Mono.Android-Tests] Stop using tls-test.internalx.com (#6678) The TLS certificate on `tls-test*.internalx.com` has expired recently. Since then, the unit test `AndroidHandlerTestBase.Sanity_Tls_1_2_Url_WithMonoClientHandlerFails()` has been failing: SHOULD NOT BE REACHED: BTLS is present, TLS 1.2 should work. Network error? System.AggregateException: One or more errors occurred. (The SSL connection could not be established, see inner exception.) ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> Mono.Btls.MonoBtlsException: Ssl error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED at /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/boringssl/ssl/handshake_client.c:1132 at Mono.Btls.MonoBtlsContext.ProcessHandshake () at Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake (Mono.Net.Security.AsyncOperationStatus status, System.Boolean renegotiate) at (wrapper remoting-invoke-with-check) Mono.Net.Security.MobileAuthenticatedStream.ProcessHandshake(Mono.Net.Security.AsyncOperationStatus,bool) at Mono.Net.Security.AsyncHandshakeRequest.Run (Mono.Net.Security.AsyncOperationStatus status) at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation (System.Threading.CancellationToken cancellationToken) --- End of inner exception stack trace --- at Mono.Net.Security.MobileAuthenticatedStream.ProcessAuthentication (System.Boolean runSynchronously, Mono.Net.Security.MonoSslAuthenticationOptions options, System.Threading.CancellationToken cancellationToken) at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore (System.IO.Stream stream, System.Net.Security.SslClientAuthenticationOptions sslOptions, System.Threading.CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore (System.IO.Stream stream, System.Net.Security.SslClientAuthenticationOptions sslOptions, System.Threading.CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.CreateConnectionAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync (System.Threading.Tasks.ValueTask1[TResult] creationTask) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in <74d9125dbed14683af25cb9fe4197e48>:0 at System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait () at Xamarin.Android.NetTests.AndroidHandlerTestBase+<>c__DisplayClass5_1.b__1 () Remove the `Sanity_Tls_1_2_Url_WithMonoClientHandlerFails()` and `Tls_1_2_Url_Works()` unit tests, as we feel less need to verify BTLS behavior (mono/2020-02 is rarely updated), and removing these tests removes usage of `tls-test.internalx.com`. Remove or update other unit tests to entirely remove all usage of `tls-test*.internalx.com`, as maintaining these VMs is a headache. This impacts: * `AndroidHandlerTestBase.Redirect_POST_With_Content_Works()` * `AndroidHandlerTestBase.Redirect_Without_Protocol_Works()` * `AndroidHandlerTestBase.Sanity_Tls_1_2_Url_WithMonoClientHandlerFails()` * `AndroidHandlerTestBase.Tls_1_2_Url_Works()` Tests that attempted to run against a particular TLS version have been removed; others have been updated to use `httpbingo.org`. Finally, add a new `RunTestApp` target to `build-tools/scripts/TestApks.targets`; this simplifies the YAML invocation of some unit tests, and means that the `yaml-templates/apk-instrumentation.yaml` template no longer needs a `packageType:` parameter, as the `RunTestApp` target handles the distinction. --- build-tools/automation/azure-pipelines.yaml | 2 - .../yaml-templates/apk-instrumentation.yaml | 5 +- build-tools/scripts/TestApks.targets | 18 +++++ .../Mono.Android-Tests/System.Net/SslTest.cs | 2 +- .../AndroidClientHandlerTests.cs | 67 ++----------------- 5 files changed, 25 insertions(+), 69 deletions(-) diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index f5f39b30df5..4d2393d5564 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -383,7 +383,6 @@ stages: testName: Mono.Android_TestsAppBundle project: tests/Mono.Android-Tests/Runtime-AppBundle/Mono.Android-TestsAppBundle.csproj testResultsFiles: TestResult-Mono.Android_TestsAppBundle-$(ApkTestConfiguration).xml - packageType: Aab artifactSource: bin/Test$(ApkTestConfiguration)/Mono.Android_TestsAppBundle-Signed.aab artifactFolder: Aab @@ -609,7 +608,6 @@ stages: project: tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)Aab.xml extraBuildArgs: /p:TestsFlavor=Aab /p:AndroidPackageFormat=aab - packageType: Aab artifactSource: bin/Test$(XA.Build.Configuration)/net6.0-android/Mono.Android.NET_Tests-Signed.aab artifactFolder: net6-Aab useDotNet: true diff --git a/build-tools/automation/yaml-templates/apk-instrumentation.yaml b/build-tools/automation/yaml-templates/apk-instrumentation.yaml index b2c87e6deb5..5dcdc465e86 100644 --- a/build-tools/automation/yaml-templates/apk-instrumentation.yaml +++ b/build-tools/automation/yaml-templates/apk-instrumentation.yaml @@ -5,7 +5,6 @@ parameters: testResultsFiles: "" extraBuildArgs: "" testResultsFormat: NUnit - packageType: Apk artifactSource: "" artifactFolder: "" useDotNet: false @@ -20,7 +19,7 @@ steps: configuration: ${{ parameters.configuration }} msbuildArguments: >- /restore - /t:AcquireAndroidTarget,SignAndroidPackage,DeployTest${{ parameters.packageType }}s,CheckAndRecordApkSizes,RunTestApks,UndeployTestApks,RenameApkTestCases,ReportComponentFailures + /t:RunTestApp /bl:$(System.DefaultWorkingDirectory)/bin/Test${{ parameters.configuration }}/run-${{ parameters.testName }}.binlog ${{ parameters.extraBuildArgs }} condition: ${{ parameters.condition }} @@ -32,7 +31,7 @@ steps: displayName: run ${{ parameters.testName }} project: ${{ parameters.project }} arguments: >- - -t:AcquireAndroidTarget,SignAndroidPackage,DeployTest${{ parameters.packageType }}s,CheckAndRecordApkSizes,RunTestApks,UndeployTestApks,RenameApkTestCases,ReportComponentFailures + -t:RunTestApp -bl:$(System.DefaultWorkingDirectory)/bin/Test${{ parameters.configuration }}/run-${{ parameters.testName }}.binlog -v:n -c ${{ parameters.configuration }} ${{ parameters.extraBuildArgs }} condition: ${{ parameters.condition }} diff --git a/build-tools/scripts/TestApks.targets b/build-tools/scripts/TestApks.targets index 4e5e09c05d5..a2176a8a50b 100644 --- a/build-tools/scripts/TestApks.targets +++ b/build-tools/scripts/TestApks.targets @@ -392,4 +392,22 @@ /> + + + AcquireAndroidTarget; + SignAndroidPackage; + DeployTestApks; + DeployTestAabs; + CheckAndRecordApkSizes; + RunTestApks; + UndeployTestApks; + RenameApkTestCases; + ReportComponentFailures; + + + + + + diff --git a/tests/Mono.Android-Tests/System.Net/SslTest.cs b/tests/Mono.Android-Tests/System.Net/SslTest.cs index d6f94d3e389..d986021d339 100644 --- a/tests/Mono.Android-Tests/System.Net/SslTest.cs +++ b/tests/Mono.Android-Tests/System.Net/SslTest.cs @@ -39,7 +39,7 @@ public void SslWithinTasksShouldWork () Exception exception = null; var thread = new Thread (() => { - string url = "https://tls-test-1.internalx.com"; + string url = "https://dotnet.microsoft.com/"; var downloadTask = new WebClient ().DownloadDataTaskAsync (url); var completeTask = downloadTask.ContinueWith (t => { diff --git a/tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidClientHandlerTests.cs b/tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidClientHandlerTests.cs index b9f27f2a935..f6b344744c4 100644 --- a/tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidClientHandlerTests.cs +++ b/tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidClientHandlerTests.cs @@ -147,28 +147,6 @@ bool IgnoreIfConnectionFailed (WebException wex, out bool connectionFailed) public abstract class AndroidHandlerTestBase : HttpClientHandlerTestBase { - const string Tls_1_2_Url = "https://tls-test.internalx.com"; - - [Test] - public void Tls_1_2_Url_Works () - { - if (((int) Build.VERSION.SdkInt) < 16) { - Assert.Ignore ("Host platform doesn't support TLS 1.2."); - return; - } - using (var c = new HttpClient (CreateHandler ())) { - var tr = ConnectIgnoreFailure (() => c.GetAsync (Tls_1_2_Url), out bool connectionFailed); - if (connectionFailed) - return; - - RunIgnoringNetworkIssues (() => tr.Wait (), out connectionFailed); - if (connectionFailed) - return; - - tr.Result.EnsureSuccessStatusCode (); - } - } - static IEnumerable Exceptions (Exception e) { yield return e; @@ -194,43 +172,6 @@ static Type GetInnerHandlerType (HttpClient httpClient) return innerHandler.GetType (); } - [Test, Category ("DotNetIgnore")] - public void Sanity_Tls_1_2_Url_WithMonoClientHandlerFails () - { - var tlsProvider = global::System.Environment.GetEnvironmentVariable ("XA_TLS_PROVIDER"); - var supportTls1_2 = tlsProvider.Equals ("btls", StringComparison.OrdinalIgnoreCase); - using (var c = new HttpClient (new HttpClientHandler ())) { - try { - Assert.AreEqual ("SocketsHttpHandler", GetInnerHandlerType (c).Name, - "Underlying HttpClientHandler is expected to use SocketsHttpHandler by default. " + - "XA_HTTP_CLIENT_HANDLER_TYPE=" + global::System.Environment.GetEnvironmentVariable ("XA_HTTP_CLIENT_HANDLER_TYPE")); - - var tr = ConnectIgnoreFailure (() => c.GetAsync (Tls_1_2_Url), out bool connectionFailed); - if (connectionFailed) - return; - - RunIgnoringNetworkIssues (() => tr.Wait (), out connectionFailed); - if (connectionFailed) - return; - - tr.Result.EnsureSuccessStatusCode (); - if (!supportTls1_2) { - Assert.Fail ("SHOULD NOT BE REACHED: Mono's HttpClientHandler doesn't support TLS 1.2."); - } - } - catch (AggregateException e) { - if (supportTls1_2) { - Assert.Fail ("SHOULD NOT BE REACHED: BTLS is present, TLS 1.2 should work. Network error? {0}", e.ToString ()); - } - if (!supportTls1_2) { - Assert.IsTrue (IsSecureChannelFailure (e), - "Nested exception and/or corresponding status code did not match expected results for TLS 1.2 incompatibility {0}", - e); - } - } - } - } - [Test] public void Cancel_Client_Works() { @@ -305,8 +246,8 @@ public void Property_Timeout_Works() [Test] public void Redirect_Without_Protocol_Works() { - var requestURI = new Uri ("http://tls-test.internalx.com/redirect.php"); - var redirectedURI = new Uri ("http://tls-test.internalx.com/redirect-301.html"); + var requestURI = new Uri ("https://httpbingo.org/redirect-to?url=https://github.com/xamarin/xamarin-android"); + var redirectedURI = new Uri ("https://github.com/xamarin/xamarin-android"); using (var c = new HttpClient (CreateHandler ())) { var tr = ConnectIgnoreFailure (() => c.GetAsync (requestURI), out bool connectionFailed); if (connectionFailed) @@ -324,8 +265,8 @@ public void Redirect_Without_Protocol_Works() [Test] public void Redirect_POST_With_Content_Works () { - var requestURI = new Uri ("http://tls-test.internalx.com/redirect.php"); - var redirectedURI = new Uri ("http://tls-test.internalx.com/redirect-301.html"); + var requestURI = new Uri ("https://httpbingo.org/redirect-to?url=https://github.com/xamarin/xamarin-android"); + var redirectedURI = new Uri ("https://github.com/xamarin/xamarin-android"); using (var c = new HttpClient (CreateHandler ())) { var request = new HttpRequestMessage (HttpMethod.Post, requestURI); request.Content = new StringContent("{}", Encoding.UTF8, "application/json");