From 56fe92f736ecb5d61a5fa5eb42745847cc7e4f81 Mon Sep 17 00:00:00 2001 From: Tomas Weinfurt Date: Thu, 18 Apr 2019 12:10:31 -0700 Subject: [PATCH] allow Http2 loopback test be unencrypted (dotnet/corefx#36968) * fix tests with http/2 * make SSL on Loopback server configurable via environment * update variable names Commit migrated from https://github.com/dotnet/corefx/commit/95987e3e3aa95b2ae6386b17271a172d20fe50cc --- src/libraries/Common/tests/System/Net/Capability.Security.cs | 10 ++++++++++ src/libraries/Common/tests/System/Net/Configuration.Http.cs | 1 + .../Common/tests/System/Net/Http/Http2LoopbackServer.cs | 2 +- .../System.Net.Http/tests/FunctionalTests/TestHelper.cs | 5 +++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libraries/Common/tests/System/Net/Capability.Security.cs b/src/libraries/Common/tests/System/Net/Capability.Security.cs index 5280f55..c2c7f30 100644 --- a/src/libraries/Common/tests/System/Net/Capability.Security.cs +++ b/src/libraries/Common/tests/System/Net/Capability.Security.cs @@ -37,6 +37,16 @@ namespace System.Net.Test.Common return !(Configuration.Security.HostsFileNamesInstalled == null); } + public static bool Http2ForceUnencryptedLoopback() + { + string value = Configuration.Http.Http2ForceUnencryptedLoopback; + if (value != null && (value.Equals("true", StringComparison.OrdinalIgnoreCase) || value.Equals("1"))) + { + return true; + } + return false; + } + private static bool InitializeTrustedRootCertificateCapability() { using (var store = new X509Store(StoreName.Root, StoreLocation.CurrentUser)) diff --git a/src/libraries/Common/tests/System/Net/Configuration.Http.cs b/src/libraries/Common/tests/System/Net/Configuration.Http.cs index 1c388fe..90db9a9 100644 --- a/src/libraries/Common/tests/System/Net/Configuration.Http.cs +++ b/src/libraries/Common/tests/System/Net/Configuration.Http.cs @@ -42,6 +42,7 @@ namespace System.Net.Test.Common public static string RevokedCertRemoteServer => GetValue("COREFX_HTTPHOST_REVOKEDCERT", "https://revoked.badssl.com/"); public static string EchoClientCertificateRemoteServer => GetValue("COREFX_HTTPHOST_ECHOCLIENTCERT", "https://corefx-net-tls.azurewebsites.net/EchoClientCertificate.ashx"); + public static string Http2ForceUnencryptedLoopback => GetValue("COREFX_HTTP2_FORCEUNENCRYPTEDLOOPBACK"); private const string HttpScheme = "http"; private const string HttpsScheme = "https"; diff --git a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackServer.cs index bfabf9d..08be33f 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http2LoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http2LoopbackServer.cs @@ -673,7 +673,7 @@ namespace System.Net.Test.Common { public IPAddress Address { get; set; } = IPAddress.Loopback; public int ListenBacklog { get; set; } = 1; - public bool UseSsl { get; set; } = PlatformDetection.SupportsAlpn; + public bool UseSsl { get; set; } = PlatformDetection.SupportsAlpn && !Capability.Http2ForceUnencryptedLoopback(); public SslProtocols SslProtocols { get; set; } = SslProtocols.Tls12; } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/TestHelper.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/TestHelper.cs index bd675de..838a781 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/TestHelper.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/TestHelper.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Net.NetworkInformation; using System.Net.Security; +using System.Net.Test.Common; using System.Reflection; using System.Runtime.InteropServices; using System.Security.Cryptography; @@ -156,13 +157,13 @@ namespace System.Net.Http.Functional.Tests BindingFlags.NonPublic | BindingFlags.Instance); field_maxHttpVersion.SetValue(_settings, new Version(2, 0)); - if (useHttp2LoopbackServer && !PlatformDetection.SupportsAlpn) + if (useHttp2LoopbackServer && (!PlatformDetection.SupportsAlpn || Capability.Http2ForceUnencryptedLoopback())) { // Allow HTTP/2.0 via unencrypted socket if ALPN is not supported on platform. FieldInfo field_allowPlainHttp2 = type_HttpConnectionSettings.GetField( "_allowUnencryptedHttp2", BindingFlags.NonPublic | BindingFlags.Instance); - field_allowPlainHttp2.SetValue(_settings, !PlatformDetection.SupportsAlpn); + field_allowPlainHttp2.SetValue(_settings, true); } } -- 2.7.4