From 9a5ef961b9e6ef6fa3d88741189c96cc8c09e48d Mon Sep 17 00:00:00 2001 From: Tomas Weinfurt Date: Mon, 20 Jul 2020 00:59:22 -0700 Subject: [PATCH] add SupportsTls11 and SupportsTls12 to PlatformDetection avoid OS versions in tests (#39482) * add SupportsTls11 and SupportsTls12 to avoid OS versions in tests * feedback from review * fix condition --- .../TestUtilities/System/PlatformDetection.cs | 3 +++ .../ServerAsyncAuthenticateTest.cs | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index 68d07741e57a7a..7a4d50d540bbd7 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -125,6 +125,9 @@ public static bool IsNonZeroLowerBoundArraySupported public static bool SupportsClientAlpn => SupportsAlpn || IsOSX || IsiOS || IstvOS; + // TLS 1.1 and 1.2 can work on Windows7 but it is not enabled by default. + public static bool SupportsTls11 => !IsWindows7 && !IsDebian10; + public static bool SupportsTls12 => !IsWindows7; // OpenSSL 1.1.1 and above. public static bool SupportsTls13 => GetTls13Support(); diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/ServerAsyncAuthenticateTest.cs b/src/libraries/System.Net.Security/tests/FunctionalTests/ServerAsyncAuthenticateTest.cs index 1518cfc3fa545e..6695fc966ae5ab 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/ServerAsyncAuthenticateTest.cs +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/ServerAsyncAuthenticateTest.cs @@ -23,8 +23,6 @@ public class ServerAsyncAuthenticateTest : IDisposable private readonly ITestOutputHelper _logVerbose; private readonly X509Certificate2 _serverCertificate; - public static bool IsNotWindows7 => !PlatformDetection.IsWindows7; - public ServerAsyncAuthenticateTest(ITestOutputHelper output) { _log = output; @@ -99,9 +97,8 @@ public async Task ServerAsyncAuthenticate_SimpleSniOptions_Success() } } - [ConditionalTheory(nameof(IsNotWindows7))] - [InlineData(SslProtocols.Tls11)] - [InlineData(SslProtocols.Tls12)] + [Theory] + [MemberData(nameof(SupportedProtocolData))] public async Task ServerAsyncAuthenticate_SniSetVersion_Success(SslProtocols version) { var serverOptions = new SslServerAuthenticationOptions() { ServerCertificate = _serverCertificate, EnabledSslProtocols = version }; @@ -247,6 +244,18 @@ public static IEnumerable ProtocolMismatchData() yield return new object[] { SslProtocols.Tls12, SslProtocols.Tls11, typeof(AuthenticationException) }; } + public static IEnumerable SupportedProtocolData() + { + if (PlatformDetection.SupportsTls11) + { + yield return new object[] { SslProtocols.Tls11 }; + } + + if (PlatformDetection.SupportsTls12) + { + yield return new object[] { SslProtocols.Tls12 }; + } + } #region Helpers private async Task ServerAsyncSslHelper(