From 55feeeab15d9c00115ba1982f7638e0752e499a1 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 18 Apr 2018 15:18:59 -0700 Subject: [PATCH] Add DeploymentParameters.Scheme property (#1388) - Allows tests to use HTTPS with dynamic port "0" --- .../Common/DeploymentParameters.cs | 5 +++++ .../Common/TestUriHelper.cs | 10 ++++++---- .../Deployers/SelfHostDeployer.cs | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/DeploymentParameters.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/DeploymentParameters.cs index 02b9c10cfa..b22f5e54ce 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/DeploymentParameters.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/DeploymentParameters.cs @@ -60,6 +60,11 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting /// public string ApplicationBaseUriHint { get; set; } + /// + /// Scheme used by the deployed application if is empty. + /// + public string Scheme { get; set; } = Uri.UriSchemeHttp; + public string EnvironmentName { get; set; } public string ServerConfigTemplateContent { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/TestUriHelper.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/TestUriHelper.cs index c1feec8c6d..012105a8ff 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/TestUriHelper.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Common/TestUriHelper.cs @@ -17,10 +17,12 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.Common internal static Uri BuildTestUri(ServerType serverType, string hint) { // Assume status messages are enabled for Kestrel and disabled for all other servers. - return BuildTestUri(serverType, hint, statusMessagesEnabled: serverType == ServerType.Kestrel); + var statusMessagesEnabled = (serverType == ServerType.Kestrel); + + return BuildTestUri(serverType, Uri.UriSchemeHttp, hint, statusMessagesEnabled); } - internal static Uri BuildTestUri(ServerType serverType, string hint, bool statusMessagesEnabled) + internal static Uri BuildTestUri(ServerType serverType, string scheme, string hint, bool statusMessagesEnabled) { if (string.IsNullOrEmpty(hint)) { @@ -31,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.Common // once and never released. Binding to dynamic port "0" on "localhost" (both IPv4 and IPv6) is not // supported, so the port is only bound on "127.0.0.1" (IPv4). If a test explicitly requires IPv6, // it should provide a hint URL with "localhost" (IPv4 and IPv6) or "[::1]" (IPv6-only). - return new UriBuilder("http", "127.0.0.1", 0).Uri; + return new UriBuilder(scheme, "127.0.0.1", 0).Uri; } else { @@ -39,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.Common // from which to scrape the assigned port, so the less reliable GetNextPort() must be used. The // port is bound on "localhost" (both IPv4 and IPv6), since this is supported when using a specific // (non-zero) port. - return new UriBuilder("http", "localhost", GetNextPort()).Uri; + return new UriBuilder(scheme, "localhost", GetNextPort()).Uri; } } else diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/SelfHostDeployer.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/SelfHostDeployer.cs index 4204d7415a..35a06c8a9f 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/SelfHostDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Deployers/SelfHostDeployer.cs @@ -43,6 +43,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting var hintUrl = TestUriHelper.BuildTestUri( DeploymentParameters.ServerType, + DeploymentParameters.Scheme, DeploymentParameters.ApplicationBaseUriHint, DeploymentParameters.StatusMessagesEnabled);