Skip to content

Commit 234cf2c

Browse files
authored
[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.<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.
1 parent b7a368a commit 234cf2c

File tree

5 files changed

+25
-69
lines changed

5 files changed

+25
-69
lines changed

build-tools/automation/azure-pipelines.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ stages:
383383
testName: Mono.Android_TestsAppBundle
384384
project: tests/Mono.Android-Tests/Runtime-AppBundle/Mono.Android-TestsAppBundle.csproj
385385
testResultsFiles: TestResult-Mono.Android_TestsAppBundle-$(ApkTestConfiguration).xml
386-
packageType: Aab
387386
artifactSource: bin/Test$(ApkTestConfiguration)/Mono.Android_TestsAppBundle-Signed.aab
388387
artifactFolder: Aab
389388

@@ -609,7 +608,6 @@ stages:
609608
project: tests/Mono.Android-Tests/Runtime-Microsoft.Android.Sdk/Mono.Android.NET-Tests.csproj
610609
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)Aab.xml
611610
extraBuildArgs: /p:TestsFlavor=Aab /p:AndroidPackageFormat=aab
612-
packageType: Aab
613611
artifactSource: bin/Test$(XA.Build.Configuration)/net6.0-android/Mono.Android.NET_Tests-Signed.aab
614612
artifactFolder: net6-Aab
615613
useDotNet: true

build-tools/automation/yaml-templates/apk-instrumentation.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ parameters:
55
testResultsFiles: ""
66
extraBuildArgs: ""
77
testResultsFormat: NUnit
8-
packageType: Apk
98
artifactSource: ""
109
artifactFolder: ""
1110
useDotNet: false
@@ -20,7 +19,7 @@ steps:
2019
configuration: ${{ parameters.configuration }}
2120
msbuildArguments: >-
2221
/restore
23-
/t:AcquireAndroidTarget,SignAndroidPackage,DeployTest${{ parameters.packageType }}s,CheckAndRecordApkSizes,RunTestApks,UndeployTestApks,RenameApkTestCases,ReportComponentFailures
22+
/t:RunTestApp
2423
/bl:$(System.DefaultWorkingDirectory)/bin/Test${{ parameters.configuration }}/run-${{ parameters.testName }}.binlog
2524
${{ parameters.extraBuildArgs }}
2625
condition: ${{ parameters.condition }}
@@ -32,7 +31,7 @@ steps:
3231
displayName: run ${{ parameters.testName }}
3332
project: ${{ parameters.project }}
3433
arguments: >-
35-
-t:AcquireAndroidTarget,SignAndroidPackage,DeployTest${{ parameters.packageType }}s,CheckAndRecordApkSizes,RunTestApks,UndeployTestApks,RenameApkTestCases,ReportComponentFailures
34+
-t:RunTestApp
3635
-bl:$(System.DefaultWorkingDirectory)/bin/Test${{ parameters.configuration }}/run-${{ parameters.testName }}.binlog
3736
-v:n -c ${{ parameters.configuration }} ${{ parameters.extraBuildArgs }}
3837
condition: ${{ parameters.condition }}

build-tools/scripts/TestApks.targets

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,22 @@
392392
/>
393393
</Target>
394394

395+
<PropertyGroup>
396+
<RunTestAppDependsOn>
397+
AcquireAndroidTarget;
398+
SignAndroidPackage;
399+
DeployTestApks;
400+
DeployTestAabs;
401+
CheckAndRecordApkSizes;
402+
RunTestApks;
403+
UndeployTestApks;
404+
RenameApkTestCases;
405+
ReportComponentFailures;
406+
</RunTestAppDependsOn>
407+
</PropertyGroup>
408+
409+
<Target Name="RunTestApp"
410+
DependsOnTargets="$(RunTestAppDependsOn)">
411+
</Target>
412+
395413
</Project>

tests/Mono.Android-Tests/System.Net/SslTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void SslWithinTasksShouldWork ()
3939
Exception exception = null;
4040

4141
var thread = new Thread (() => {
42-
string url = "https://tls-test-1.internalx.com";
42+
string url = "https://dotnet.microsoft.com/";
4343

4444
var downloadTask = new WebClient ().DownloadDataTaskAsync (url);
4545
var completeTask = downloadTask.ContinueWith (t => {

tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidClientHandlerTests.cs

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -147,28 +147,6 @@ bool IgnoreIfConnectionFailed (WebException wex, out bool connectionFailed)
147147

148148
public abstract class AndroidHandlerTestBase : HttpClientHandlerTestBase
149149
{
150-
const string Tls_1_2_Url = "https://tls-test.internalx.com";
151-
152-
[Test]
153-
public void Tls_1_2_Url_Works ()
154-
{
155-
if (((int) Build.VERSION.SdkInt) < 16) {
156-
Assert.Ignore ("Host platform doesn't support TLS 1.2.");
157-
return;
158-
}
159-
using (var c = new HttpClient (CreateHandler ())) {
160-
var tr = ConnectIgnoreFailure (() => c.GetAsync (Tls_1_2_Url), out bool connectionFailed);
161-
if (connectionFailed)
162-
return;
163-
164-
RunIgnoringNetworkIssues (() => tr.Wait (), out connectionFailed);
165-
if (connectionFailed)
166-
return;
167-
168-
tr.Result.EnsureSuccessStatusCode ();
169-
}
170-
}
171-
172150
static IEnumerable<Exception> Exceptions (Exception e)
173151
{
174152
yield return e;
@@ -194,43 +172,6 @@ static Type GetInnerHandlerType (HttpClient httpClient)
194172
return innerHandler.GetType ();
195173
}
196174

197-
[Test, Category ("DotNetIgnore")]
198-
public void Sanity_Tls_1_2_Url_WithMonoClientHandlerFails ()
199-
{
200-
var tlsProvider = global::System.Environment.GetEnvironmentVariable ("XA_TLS_PROVIDER");
201-
var supportTls1_2 = tlsProvider.Equals ("btls", StringComparison.OrdinalIgnoreCase);
202-
using (var c = new HttpClient (new HttpClientHandler ())) {
203-
try {
204-
Assert.AreEqual ("SocketsHttpHandler", GetInnerHandlerType (c).Name,
205-
"Underlying HttpClientHandler is expected to use SocketsHttpHandler by default. " +
206-
"XA_HTTP_CLIENT_HANDLER_TYPE=" + global::System.Environment.GetEnvironmentVariable ("XA_HTTP_CLIENT_HANDLER_TYPE"));
207-
208-
var tr = ConnectIgnoreFailure (() => c.GetAsync (Tls_1_2_Url), out bool connectionFailed);
209-
if (connectionFailed)
210-
return;
211-
212-
RunIgnoringNetworkIssues (() => tr.Wait (), out connectionFailed);
213-
if (connectionFailed)
214-
return;
215-
216-
tr.Result.EnsureSuccessStatusCode ();
217-
if (!supportTls1_2) {
218-
Assert.Fail ("SHOULD NOT BE REACHED: Mono's HttpClientHandler doesn't support TLS 1.2.");
219-
}
220-
}
221-
catch (AggregateException e) {
222-
if (supportTls1_2) {
223-
Assert.Fail ("SHOULD NOT BE REACHED: BTLS is present, TLS 1.2 should work. Network error? {0}", e.ToString ());
224-
}
225-
if (!supportTls1_2) {
226-
Assert.IsTrue (IsSecureChannelFailure (e),
227-
"Nested exception and/or corresponding status code did not match expected results for TLS 1.2 incompatibility {0}",
228-
e);
229-
}
230-
}
231-
}
232-
}
233-
234175
[Test]
235176
public void Cancel_Client_Works()
236177
{
@@ -305,8 +246,8 @@ public void Property_Timeout_Works()
305246
[Test]
306247
public void Redirect_Without_Protocol_Works()
307248
{
308-
var requestURI = new Uri ("http://tls-test.internalx.com/redirect.php");
309-
var redirectedURI = new Uri ("http://tls-test.internalx.com/redirect-301.html");
249+
var requestURI = new Uri ("https://httpbingo.org/redirect-to?url=https://github.com/xamarin/xamarin-android");
250+
var redirectedURI = new Uri ("https://github.com/xamarin/xamarin-android");
310251
using (var c = new HttpClient (CreateHandler ())) {
311252
var tr = ConnectIgnoreFailure (() => c.GetAsync (requestURI), out bool connectionFailed);
312253
if (connectionFailed)
@@ -324,8 +265,8 @@ public void Redirect_Without_Protocol_Works()
324265
[Test]
325266
public void Redirect_POST_With_Content_Works ()
326267
{
327-
var requestURI = new Uri ("http://tls-test.internalx.com/redirect.php");
328-
var redirectedURI = new Uri ("http://tls-test.internalx.com/redirect-301.html");
268+
var requestURI = new Uri ("https://httpbingo.org/redirect-to?url=https://github.com/xamarin/xamarin-android");
269+
var redirectedURI = new Uri ("https://github.com/xamarin/xamarin-android");
329270
using (var c = new HttpClient (CreateHandler ())) {
330271
var request = new HttpRequestMessage (HttpMethod.Post, requestURI);
331272
request.Content = new StringContent("{}", Encoding.UTF8, "application/json");

0 commit comments

Comments
 (0)