Skip to content

Commit

Permalink
[Mono.Android-Tests] Stop using tls-test.internalx.com (#6678)
Browse files Browse the repository at this point in the history
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.<Sanity_Tls_1_2_Url_WithMonoClientHandlerFails>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.
  • Loading branch information
pjcollins authored Jan 28, 2022
1 parent b7a368a commit 234cf2c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 69 deletions.
2 changes: 0 additions & 2 deletions build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ parameters:
testResultsFiles: ""
extraBuildArgs: ""
testResultsFormat: NUnit
packageType: Apk
artifactSource: ""
artifactFolder: ""
useDotNet: false
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand Down
18 changes: 18 additions & 0 deletions build-tools/scripts/TestApks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,22 @@
/>
</Target>

<PropertyGroup>
<RunTestAppDependsOn>
AcquireAndroidTarget;
SignAndroidPackage;
DeployTestApks;
DeployTestAabs;
CheckAndRecordApkSizes;
RunTestApks;
UndeployTestApks;
RenameApkTestCases;
ReportComponentFailures;
</RunTestAppDependsOn>
</PropertyGroup>

<Target Name="RunTestApp"
DependsOnTargets="$(RunTestAppDependsOn)">
</Target>

</Project>
2 changes: 1 addition & 1 deletion tests/Mono.Android-Tests/System.Net/SslTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Exception> Exceptions (Exception e)
{
yield return e;
Expand All @@ -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()
{
Expand Down Expand Up @@ -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)
Expand All @@ -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");
Expand Down

0 comments on commit 234cf2c

Please sign in to comment.