diff --git a/src/AspNetCoreModuleV1/AspNetCore/src/serverprocess.cxx b/src/AspNetCoreModuleV1/AspNetCore/src/serverprocess.cxx index 4caf8cd3a3..76da27a99b 100644 --- a/src/AspNetCoreModuleV1/AspNetCore/src/serverprocess.cxx +++ b/src/AspNetCoreModuleV1/AspNetCore/src/serverprocess.cxx @@ -132,7 +132,6 @@ SERVER_PROCESS::SetupListenPort( pEnvironmentVarTable->FindKey(ASPNETCORE_PORT_ENV_STR, &pEntry); if (pEntry != NULL) { - pEntry->Dereference(); if (pEntry->QueryValue() != NULL || pEntry->QueryValue()[0] != L'\0') { m_dwPort = (DWORD)_wtoi(pEntry->QueryValue()); diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/Http.config b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/Http.config index 4508dea843..8c74496e12 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/Http.config +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/Http.config @@ -176,9 +176,6 @@ - - - @@ -255,8 +252,6 @@ - - @@ -931,11 +926,8 @@ - - - @@ -1031,4 +1023,4 @@ - \ No newline at end of file + diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployer.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployer.cs index ca0ced4218..d2df4a8f8c 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployer.cs @@ -276,32 +276,13 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS private void ConfigureAppHostConfig(XElement config, string contentRoot, int port) { - var siteElement = config - .RequiredElement("system.applicationHost") - .RequiredElement("sites") - .RequiredElement("site"); - - siteElement - .RequiredElement("application") - .RequiredElement("virtualDirectory") - .SetAttributeValue("physicalPath", contentRoot); - - siteElement - .RequiredElement("bindings") - .RequiredElement("binding") - .SetAttributeValue("bindingInformation", $"*:{port}:"); - - var ancmVersion = DeploymentParameters.AncmVersion.ToString(); - config - .RequiredElement("system.webServer") - .RequiredElement("globalModules") - .GetOrAdd("add", "name", ancmVersion) - .SetAttributeValue("image", GetAncmLocation(DeploymentParameters.AncmVersion)); + ConfigureModuleAndBinding(config, contentRoot, port); + // In IISExpress system.webServer/modules in under location element config .RequiredElement("system.webServer") .RequiredElement("modules") - .GetOrAdd("add", "name", ancmVersion); + .GetOrAdd("add", "name", DeploymentParameters.AncmVersion.ToString()); var pool = config .RequiredElement("system.applicationHost") diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployerBase.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployerBase.cs index 614d68b145..5e6aabdadb 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployerBase.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISDeployerBase.cs @@ -124,5 +124,30 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS .SetAttributeValue("value", handlerSetting.Value); } } + + protected void ConfigureModuleAndBinding(XElement config, string contentRoot, int port) + { + var siteElement = config + .RequiredElement("system.applicationHost") + .RequiredElement("sites") + .RequiredElement("site"); + + siteElement + .RequiredElement("application") + .RequiredElement("virtualDirectory") + .SetAttributeValue("physicalPath", contentRoot); + + siteElement + .RequiredElement("bindings") + .RequiredElement("binding") + .SetAttributeValue("bindingInformation", $":{port}:localhost"); + + var ancmVersion = DeploymentParameters.AncmVersion.ToString(); + config + .RequiredElement("system.webServer") + .RequiredElement("globalModules") + .GetOrAdd("add", "name", ancmVersion) + .SetAttributeValue("image", GetAncmLocation(DeploymentParameters.AncmVersion)); + } } } diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISExpressDeployer.cs b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISExpressDeployer.cs index c1bc7a26e1..fd2aca9b4c 100644 --- a/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISExpressDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting.IIS/IISExpressDeployer.cs @@ -91,6 +91,8 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS DeploymentParameters.EnvironmentVariables["ASPNETCORE_CONTENTROOT"] = DeploymentParameters.ApplicationPath; } + RunWebConfigActions(contentRoot); + var testUri = TestUriHelper.BuildTestUri(ServerType.IISExpress, DeploymentParameters.ApplicationBaseUriHint); // Launch the host process. @@ -260,40 +262,35 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS private void PrepareConfig(string contentRoot, int port) { + var serverConfig = DeploymentParameters.ServerConfigTemplateContent;; // Config is required. If not present then fall back to one we carry with us. - if (string.IsNullOrEmpty(DeploymentParameters.ServerConfigTemplateContent)) + if (string.IsNullOrEmpty(serverConfig)) { using (var stream = GetType().Assembly.GetManifestResourceStream("Microsoft.AspNetCore.Server.IntegrationTesting.IIS.Http.config")) using (var reader = new StreamReader(stream)) { - DeploymentParameters.ServerConfigTemplateContent = reader.ReadToEnd(); + serverConfig = reader.ReadToEnd(); } } - var serverConfig = DeploymentParameters.ServerConfigTemplateContent; - + XDocument config = XDocument.Parse(serverConfig); // Pass on the applicationhost.config to iis express. With this don't need to pass in the /path /port switches as they are in the applicationHost.config // We take a copy of the original specified applicationHost.Config to prevent modifying the one in the repo. - serverConfig = ModifyANCMPathInConfig(replaceFlag: "[ANCMPath]", AncmVersion.AspNetCoreModule, serverConfig); - serverConfig = ModifyANCMPathInConfig(replaceFlag: "[ANCMV2Path]", AncmVersion.AspNetCoreModuleV2, serverConfig); - serverConfig = ReplacePlaceholder(serverConfig, "[PORT]", port.ToString(CultureInfo.InvariantCulture)); - serverConfig = ReplacePlaceholder(serverConfig, "[ApplicationPhysicalPath]", contentRoot); + config.Root + .RequiredElement("location") + .RequiredElement("system.webServer") + .RequiredElement("modules") + .GetOrAdd("add", "name", DeploymentParameters.AncmVersion.ToString()); - if (DeploymentParameters.PublishApplicationBeforeDeployment) - { - serverConfig = RemoveRedundantElements(serverConfig); - } - else + ConfigureModuleAndBinding(config.Root, contentRoot, port); + + if (!DeploymentParameters.PublishApplicationBeforeDeployment) { // The elements normally in the web.config are in the applicationhost.config for unpublished apps. - serverConfig = ReplacePlaceholder(serverConfig, "[HostingModel]", DeploymentParameters.HostingModel.ToString()); - serverConfig = ReplacePlaceholder(serverConfig, "[AspNetCoreModule]", DeploymentParameters.AncmVersion.ToString()); + AddAspNetCoreElement(config.Root); } - RunWebConfigActions(contentRoot); - - var config = XDocument.Parse(serverConfig); RunServerConfigActions(config.Root, contentRoot); serverConfig = config.ToString(); @@ -303,14 +300,31 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS File.WriteAllText(DeploymentParameters.ServerConfigLocation, serverConfig); } - private string ReplacePlaceholder(string content, string field, string value) + private void AddAspNetCoreElement(XElement config) { - if (content.Contains(field)) - { - content = content.Replace(field, value); - Logger.LogDebug("Writing {field} '{value}' to config", field, value); - } - return content; + var aspNetCore = config + .RequiredElement("system.webServer") + .GetOrAdd("aspNetCore"); + + aspNetCore.SetAttributeValue("hostingModel", DeploymentParameters.HostingModel.ToString()); + aspNetCore.SetAttributeValue("arguments", "%LAUNCHER_ARGS%"); + aspNetCore.SetAttributeValue("processPath", "%LAUNCHER_PATH%"); + + var handlers = config + .RequiredElement("location") + .RequiredElement("system.webServer") + .RequiredElement("handlers"); + + var aspNetCoreHandler = handlers + .GetOrAdd("add", "name", "aspNetCore"); + + aspNetCoreHandler.SetAttributeValue("path", "*"); + aspNetCoreHandler.SetAttributeValue("verb", "*"); + aspNetCoreHandler.SetAttributeValue("modules", DeploymentParameters.AncmVersion.ToString()); + aspNetCoreHandler.SetAttributeValue("resourceType", "Unspecified"); + // Make aspNetCore handler first + aspNetCoreHandler.Remove(); + handlers.AddFirst(aspNetCoreHandler); } protected override IEnumerable> GetWebConfigActions() @@ -347,18 +361,6 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS } } - private string ModifyANCMPathInConfig(string replaceFlag, AncmVersion version, string serverConfig) - { - if (serverConfig.Contains(replaceFlag)) - { - var ancmFile = GetAncmLocation(version); - - Logger.LogDebug($"Writing '{replaceFlag}' '{ancmFile}' to config"); - return serverConfig.Replace(replaceFlag, ancmFile); - } - return serverConfig; - } - private string GetIISExpressPath() { var programFiles = "Program Files"; @@ -477,21 +479,5 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.IIS throw new InvalidOperationException($"iisexpress Process {hostProcess.Id} crashed before shutdown was triggered."); } } - - // These elements are duplicated in the web.config if you publish. Remove them from the host.config. - private string RemoveRedundantElements(string serverConfig) - { - var hostConfig = XDocument.Parse(serverConfig); - - var coreElement = hostConfig.Descendants("aspNetCore").FirstOrDefault(); - coreElement?.Remove(); - - var handlersElement = hostConfig.Descendants("handlers").First(); - var handlerElement = handlersElement.Descendants("add") - .Where(x => x.Attribute("name").Value == "aspNetCore").FirstOrDefault(); - handlerElement?.Remove(); - - return hostConfig.ToString(); - } } } diff --git a/test/Common.FunctionalTests/AppHostConfig/IISExpress.config b/test/Common.FunctionalTests/AppHostConfig/IISExpress.config deleted file mode 100644 index 9dfe324091..0000000000 --- a/test/Common.FunctionalTests/AppHostConfig/IISExpress.config +++ /dev/null @@ -1,1035 +0,0 @@ - - - - - - - - -
-
-
-
-
-
-
-
- - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
- -
-
- -
-
-
- - -
-
-
-
-
-
- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/Common.FunctionalTests/Inprocess/EventLogTests.cs b/test/Common.FunctionalTests/Inprocess/EventLogTests.cs index d8353181d3..3139f3b251 100644 --- a/test/Common.FunctionalTests/Inprocess/EventLogTests.cs +++ b/test/Common.FunctionalTests/Inprocess/EventLogTests.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests StopServer(); - EventLogHelpers.VerifyEventLogEvent(TestSink, "Application '.+' started the coreclr in-process successfully."); + EventLogHelpers.VerifyEventLogEvent(deploymentResult, TestSink, "Application '.+' started the coreclr in-process successfully."); } [ConditionalFact] @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests StopServer(); - EventLogHelpers.VerifyEventLogEvent(TestSink, "Application '.+' has shutdown."); + EventLogHelpers.VerifyEventLogEvent(deploymentResult, TestSink, "Application '.+' has shutdown."); } } } diff --git a/test/Common.FunctionalTests/MultiApplicationTests.cs b/test/Common.FunctionalTests/MultiApplicationTests.cs index df9bb035f9..a91dfa4d76 100644 --- a/test/Common.FunctionalTests/MultiApplicationTests.cs +++ b/test/Common.FunctionalTests/MultiApplicationTests.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests Assert.Equal(200, (int)result1.StatusCode); Assert.Equal(500, (int)result2.StatusCode); StopServer(); - EventLogHelpers.VerifyEventLogEvent(TestSink, "Only one inprocess application is allowed per IIS application pool"); + EventLogHelpers.VerifyEventLogEvent(result, TestSink, "Only one inprocess application is allowed per IIS application pool"); } [ConditionalTheory] @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests Assert.Equal(200, (int)result1.StatusCode); Assert.Equal(500, (int)result2.StatusCode); StopServer(); - EventLogHelpers.VerifyEventLogEvent(TestSink, "Mixed hosting model is not supported."); + EventLogHelpers.VerifyEventLogEvent(result, TestSink, "Mixed hosting model is not supported."); } private void SetHostingModel(string directory, HostingModel model) diff --git a/test/Common.FunctionalTests/OutOfProcess/AspNetCorePortTests.cs b/test/Common.FunctionalTests/OutOfProcess/AspNetCorePortTests.cs new file mode 100644 index 0000000000..89824163ed --- /dev/null +++ b/test/Common.FunctionalTests/OutOfProcess/AspNetCorePortTests.cs @@ -0,0 +1,89 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using System.Threading.Tasks; +using Xunit; +using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.AspNetCore.Testing.xunit; + +namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests +{ + [Collection(PublishedSitesCollection.Name)] + public class AspNetCorePortTests : IISFunctionalTestBase + { + private static readonly Random _random = new Random(); + + private readonly PublishedSitesFixture _fixture; + + public AspNetCorePortTests(PublishedSitesFixture fixture) + { + _fixture = fixture; + } + + public static TestMatrix TestVariants + => TestMatrix.ForServers(DeployerSelector.ServerType) + .WithTfms(Tfm.NetCoreApp22) + .WithApplicationTypes(ApplicationType.Portable) + .WithAllAncmVersions(); + + [ConditionalTheory] + [MemberData(nameof(TestVariants))] + public async Task EnvVarInWebConfig(TestVariant variant) + { + // Must publish to set env vars in web.config + var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant, publish: true); + var port = GetUnusedRandomPort(); + deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_PORT"] = port.ToString(); + + var deploymentResult = await DeployAsync(deploymentParameters); + + var response = await deploymentResult.HttpClient.GetAsync("/ServerAddresses"); + var responseText = await response.Content.ReadAsStringAsync(); + + Assert.Equal(port, new Uri(responseText).Port); + } + + private static int GetUnusedRandomPort() + { + // Port range allowed by ANCM config + const int minPort = 1025; + const int maxPort = 48000; + + // Large number of retries to prevent test failures due to port collisions, but not infinite + // to prevent infinite loop in case Bind() fails repeatedly for some other reason. + const int retries = 100; + + List exceptions = null; + + for (var i = 0; i < retries; i++) + { + var port = _random.Next(minPort, maxPort); + + using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + socket.Bind(new IPEndPoint(IPAddress.Loopback, port)); + return port; + } + catch (Exception e) + { + // Bind failed, most likely because port is in use. Save exception and retry. + if (exceptions == null) + { + exceptions = new List(retries); + } + exceptions.Add(e); + } + } + } + + throw new AggregateException($"Unable to find unused random port after {retries} retries.", exceptions); + } + } +} diff --git a/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs b/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs index 0b05ff54db..3f748f2314 100644 --- a/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs +++ b/test/Common.FunctionalTests/OutOfProcess/HelloWorldTest.cs @@ -2,9 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities; using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; using Microsoft.AspNetCore.Testing.xunit; using Xunit; @@ -30,9 +33,16 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests [MemberData(nameof(TestVariants))] public async Task HelloWorld(TestVariant variant) { - // The default in hosting sets windows auth to true. - // Set it to the IISExpress.config file var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant); + deploymentParameters.ServerConfigActionList.Add( + (element, _) => { + element + .RequiredElement("system.webServer") + .RequiredElement("security") + .RequiredElement("authentication") + .Element("windowsAuthentication") + ?.SetAttributeValue("enabled", "false"); + }); var deploymentResult = await DeployAsync(deploymentParameters); @@ -63,6 +73,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests $"WebRootPath {deploymentResult.ContentRoot}\\wwwroot" + Environment.NewLine + $"CurrentDirectory {deploymentResult.ContentRoot}", await deploymentResult.HttpClient.GetStringAsync("/HostingEnvironment")); + + var expectedDll = variant.AncmVersion == AncmVersion.AspNetCoreModule ? "aspnetcore.dll" : "aspnetcorev2.dll"; + Assert.Contains(deploymentResult.HostProcess.Modules.OfType(), m=> m.FileName.Contains(expectedDll)); } } } diff --git a/test/Common.FunctionalTests/PublishedSitesFixture.cs b/test/Common.FunctionalTests/PublishedSitesFixture.cs index 90104f6652..64e39e68df 100644 --- a/test/Common.FunctionalTests/PublishedSitesFixture.cs +++ b/test/Common.FunctionalTests/PublishedSitesFixture.cs @@ -49,7 +49,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests publisher, new DeploymentParameters(publisher.ApplicationPath, DeployerSelector.ServerType, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) { - HostingModel = hostingModel + HostingModel = hostingModel, + TargetFramework = "netcoreapp2.2", + AncmVersion = AncmVersion.AspNetCoreModuleV2 }, publish); } @@ -60,10 +62,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { ApplicationPublisher = publisher, ApplicationPath = publisher.ApplicationPath, - TargetFramework = Tfm.NetCoreApp22, - ApplicationType = ApplicationType.Portable, - AncmVersion = AncmVersion.AspNetCoreModuleV2, - PublishApplicationBeforeDeployment = publish, + PublishApplicationBeforeDeployment = publish }; } } diff --git a/test/Common.FunctionalTests/Utilities/EventLogHelpers.cs b/test/Common.FunctionalTests/Utilities/EventLogHelpers.cs index 7729b4359b..9d8d79fb6c 100644 --- a/test/Common.FunctionalTests/Utilities/EventLogHelpers.cs +++ b/test/Common.FunctionalTests/Utilities/EventLogHelpers.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Text.RegularExpressions; +using Microsoft.AspNetCore.Server.IntegrationTesting.IIS; using Microsoft.Extensions.Logging.Testing; using Xunit; @@ -9,8 +10,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { public class EventLogHelpers { - public static void VerifyEventLogEvent(ITestSink testSink, string expectedRegexMatchString) + public static void VerifyEventLogEvent(IISDeploymentResult deploymentResult, ITestSink testSink, string expectedRegexMatchString) { + Assert.True(deploymentResult.HostProcess.HasExited); + var eventLogRegex = new Regex($"Event Log: {expectedRegexMatchString}"); int count = 0; diff --git a/test/Common.FunctionalTests/Utilities/FunctionalTestsBase.cs b/test/Common.FunctionalTests/Utilities/FunctionalTestsBase.cs index 79919e5753..a9b6b3a4fe 100644 --- a/test/Common.FunctionalTests/Utilities/FunctionalTestsBase.cs +++ b/test/Common.FunctionalTests/Utilities/FunctionalTestsBase.cs @@ -28,11 +28,6 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting parameters.EnvironmentVariables[DebugEnvironmentVariable] = "console"; } - if (parameters.ServerType == ServerType.IISExpress) - { - parameters.ServerConfigTemplateContent = parameters.ServerConfigTemplateContent ?? File.ReadAllText("IISExpress.config"); - } - if (parameters.ApplicationPublisher == null) { throw new InvalidOperationException("All tests should use ApplicationPublisher"); diff --git a/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs b/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs index 89c17d8492..e6b48f28bf 100644 --- a/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs +++ b/test/IISExpress.FunctionalTests/InProcess/StartupTests.cs @@ -55,7 +55,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); - EventLogHelpers.VerifyEventLogEvent(TestSink, @"Invalid or unknown processPath provided in web\.config: processPath = '.+', ErrorCode = '0x80070002'\."); + StopServer(); + + EventLogHelpers.VerifyEventLogEvent(deploymentResult, TestSink, @"Invalid or unknown processPath provided in web\.config: processPath = '.+', ErrorCode = '0x80070002'\."); } [ConditionalFact] @@ -158,7 +160,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); - EventLogHelpers.VerifyEventLogEvent(TestSink, "Unknown hosting model 'bogus'. Please specify either hostingModel=\"inprocess\" or hostingModel=\"outofprocess\" in the web.config file."); + StopServer(); + + EventLogHelpers.VerifyEventLogEvent(deploymentResult, TestSink, "Unknown hosting model 'bogus'. Please specify either hostingModel=\"inprocess\" or hostingModel=\"outofprocess\" in the web.config file."); } } } diff --git a/test/WebSites/OutOfProcessWebSite/Startup.cs b/test/WebSites/OutOfProcessWebSite/Startup.cs index 059b5a1264..8a8358d364 100644 --- a/test/WebSites/OutOfProcessWebSite/Startup.cs +++ b/test/WebSites/OutOfProcessWebSite/Startup.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.IISIntegration.FunctionalTests; @@ -22,9 +23,13 @@ namespace TestSites { public class Startup { + private IServerAddressesFeature _serverAddresses; + public void Configure(IApplicationBuilder app) { TestStartup.Register(app, this); + + _serverAddresses = app.ServerFeatures.Get(); } public Task Path(HttpContext ctx) => ctx.Response.WriteAsync(ctx.Request.Path.Value); @@ -120,5 +125,10 @@ namespace TestSites { await context.Response.WriteAsync(Process.GetCurrentProcess().Id.ToString()); } + + private async Task ServerAddresses(HttpContext context) + { + await context.Response.WriteAsync(string.Join(",", _serverAddresses.Addresses)); + } } }