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/OutOfProcess/AspNetCorePortTests.cs b/test/Common.FunctionalTests/OutOfProcess/AspNetCorePortTests.cs index e4c281c467..89824163ed 100644 --- a/test/Common.FunctionalTests/OutOfProcess/AspNetCorePortTests.cs +++ b/test/Common.FunctionalTests/OutOfProcess/AspNetCorePortTests.cs @@ -37,11 +37,6 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { // Must publish to set env vars in web.config var deploymentParameters = _fixture.GetBaseDeploymentParameters(variant, publish: true); - - // Workaround "PublishedSitesFixture.GetBaseDeploymentParameters() overrides too many properties of baseParameters" - // https://github.com/aspnet/IISIntegration/issues/1237 - deploymentParameters.AncmVersion = variant.AncmVersion; - var port = GetUnusedRandomPort(); deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_PORT"] = port.ToString(); 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/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");