private async Task UpgradeFeatureDetectionDeployer(bool disableWebSocket, string sitePath, string expected, HostingModel hostingModel) { var deploymentParameters = new IISDeploymentParameters(sitePath, DeployerSelector.ServerType, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) { TargetFramework = Tfm.NetCoreApp22, ApplicationType = ApplicationType.Portable, AncmVersion = AncmVersion.AspNetCoreModuleV2, HostingModel = hostingModel, PublishApplicationBeforeDeployment = hostingModel == HostingModel.InProcess }; if (disableWebSocket) { // For IIS, we need to modify the apphost.config file deploymentParameters.AddServerConfigAction( element => element.Descendants("webSocket") .Single() .SetAttributeValue("enabled", "false")); } var deploymentResult = await DeployAsync(deploymentParameters); var response = await deploymentResult.RetryingHttpClient.GetAsync("UpgradeFeatureDetection"); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(expected, responseText); }
public IISTestSiteFixture() { var logging = AssemblyTestLog.ForAssembly(typeof(IISTestSiteFixture).Assembly); var deploymentParameters = new IISDeploymentParameters(Helpers.GetInProcessTestSitesPath(), DeployerSelector.ServerType, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) { TargetFramework = Tfm.NetCoreApp22, AncmVersion = AncmVersion.AspNetCoreModuleV2, HostingModel = HostingModel.InProcess, PublishApplicationBeforeDeployment = true, }; _forwardingProvider = new ForwardingProvider(); var loggerFactory = logging.CreateLoggerFactory(null, nameof(IISTestSiteFixture)); loggerFactory.AddProvider(_forwardingProvider); _deployer = IISApplicationDeployerFactory.Create(deploymentParameters, loggerFactory); DeploymentResult = _deployer.DeployAsync().Result; Client = DeploymentResult.HttpClient; BaseUri = DeploymentResult.ApplicationBaseUri; ShutdownToken = DeploymentResult.HostShutdownToken; }
public static void EnableModule(this IISDeploymentParameters parameters, string moduleName, string modulePath) { if (parameters.ServerType == ServerType.IIS) { modulePath = modulePath.Replace("%IIS_BIN%", "%windir%\\System32\\inetsrv"); } parameters.ServerConfigActionList.Add( (element, _) => { var webServerElement = element .RequiredElement("system.webServer"); webServerElement .RequiredElement("globalModules") .GetOrAdd("add", "name", moduleName) .SetAttributeValue("image", modulePath); (webServerElement.Element("modules") ?? element .Element("location") .RequiredElement("system.webServer") .RequiredElement("modules")) .GetOrAdd("add", "name", moduleName); }); }
private void EnsureInitialized() { if (_deployer != null) { return; } var deploymentParameters = new IISDeploymentParameters(Helpers.GetInProcessTestSitesPath(), DeployerSelector.ServerType, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) { TargetFramework = Tfm.NetCoreApp30, AncmVersion = AncmVersion.AspNetCoreModuleV2, HostingModel = HostingModel.InProcess, PublishApplicationBeforeDeployment = true }; _configure(deploymentParameters); deploymentParameters.ApplicationPublisher = new PublishedApplicationPublisher(deploymentParameters.ApplicationPath); _deployer = IISApplicationDeployerFactory.Create(deploymentParameters, _loggerFactory); _deploymentResult = (IISDeploymentResult)_deployer.DeployAsync().Result; }
private static void Configure(IISDeploymentParameters deploymentParameters) { deploymentParameters.ApplicationPublisher = new PublishedApplicationPublisher(Helpers.GetOutOfProcessTestSitesName());; deploymentParameters.ApplicationPath = Helpers.GetOutOfProcessTestSitesName(); deploymentParameters.HostingModel = HostingModel.OutOfProcess; deploymentParameters.AncmVersion = AncmVersion.AspNetCoreModule; }
public static void EnableLogging(this IISDeploymentParameters deploymentParameters, string path) { deploymentParameters.WebConfigActionList.Add( WebConfigHelpers.AddOrModifyAspNetCoreSection("stdoutLogEnabled", "true")); deploymentParameters.WebConfigActionList.Add( WebConfigHelpers.AddOrModifyAspNetCoreSection("stdoutLogFile", Path.Combine(path, "std"))); }
protected virtual async Task <IISDeploymentResult> StartAsync(IISDeploymentParameters parameters) { var result = await DeployAsync(parameters); await result.AssertStarts(); return(result); }
public static void TransformPath(this IISDeploymentParameters parameters, Func <string, string, string> transformation) { parameters.WebConfigActionList.Add( (config, contentRoot) => { var aspNetCoreElement = config.Descendants("aspNetCore").Single(); aspNetCoreElement.SetAttributeValue("processPath", transformation((string)aspNetCoreElement.Attribute("processPath"), contentRoot)); }); }
private async Task<IISDeploymentResult> SetupFrebApp(IISDeploymentParameters parameters = null) { parameters = parameters ?? Fixture.GetBaseDeploymentParameters(); parameters.EnableFreb("Verbose", _logFolderPath); Directory.CreateDirectory(_logFolderPath); var result = await DeployAsync(parameters); return result; }
private static void TransformArguments(IISDeploymentParameters parameters, Func <string, string, string> transformation) { parameters.WebConfigActionList.Add( (config, contentRoot) => { var aspNetCoreElement = config.Descendants("aspNetCore").Single(); aspNetCoreElement.SetAttributeValue("arguments", transformation((string)aspNetCoreElement.Attribute("arguments"), contentRoot)); }); }
protected ApplicationDeployer CreateDeployer(IISDeploymentParameters parameters) { if (parameters.ServerType == ServerType.IISExpress && !parameters.EnvironmentVariables.ContainsKey(DebugEnvironmentVariable)) { parameters.EnvironmentVariables[DebugEnvironmentVariable] = "console"; } return(IISApplicationDeployerFactory.Create(parameters, LoggerFactory)); }
private async Task <HttpResponseMessage> DeployAppWithStartupFailure(IISDeploymentParameters deploymentParameters) { deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("processPath", "doesnot")); deploymentParameters.WebConfigActionList.Add(WebConfigHelpers.AddOrModifyAspNetCoreSection("arguments", "start")); deploymentParameters.EnvironmentVariables["ANCM_ADDITIONAL_ERROR_PAGE_LINK"] = "http://example"; var deploymentResult = await DeployAsync(deploymentParameters); return(await deploymentResult.HttpClient.GetAsync("HelloWorld")); }
public static void SetAnonymousAuth(this IISDeploymentParameters parameters, bool enabled = true) { parameters.AddServerConfigAction( element => { element .RequiredElement("system.webServer") .RequiredElement("security") .RequiredElement("authentication") .GetOrAdd("anonymousAuthentication") .SetAttributeValue("enabled", enabled); }); }
public static void AddHttpsWithClientCertToServerConfig(this IISDeploymentParameters parameters) { parameters.AddServerConfigAction( element => { element.Descendants("binding") .Single() .SetAttributeValue("protocol", "https"); element.Descendants("access") .Single() .SetAttributeValue("sslFlags", "Ssl, SslNegotiateCert"); }); }
private static void EnablePreload(IISDeploymentParameters baseDeploymentParameters) { baseDeploymentParameters.EnsureSection("applicationInitialization", "system.webServer"); baseDeploymentParameters.ServerConfigActionList.Add( (config, _) => { config .RequiredElement("system.applicationHost") .RequiredElement("sites") .RequiredElement("site") .RequiredElement("application") .SetAttributeValue("preloadEnabled", true); }); baseDeploymentParameters.EnableModule("ApplicationInitializationModule", "%IIS_BIN%\\warmup.dll"); }
public static void SetBasicAuth(this IISDeploymentParameters parameters, bool enabled = true) { parameters.EnableModule("BasicAuthenticationModule", "%IIS_BIN%\\authbas.dll"); parameters.AddServerConfigAction( element => { element .RequiredElement("system.webServer") .RequiredElement("security") .RequiredElement("authentication") .GetOrAdd("basicAuthentication") .SetAttributeValue("enabled", enabled); }); }
public IISDeploymentResult(ILoggerFactory loggerFactory, IISDeploymentParameters deploymentParameters, string applicationBaseUri, string contentRoot, CancellationToken hostShutdownToken, Process hostProcess) : base(loggerFactory, deploymentParameters, applicationBaseUri, contentRoot, hostShutdownToken) { HostProcess = hostProcess; Logger = loggerFactory.CreateLogger(deploymentParameters.SiteName); HttpClient = CreateClient(new HttpClientHandler()); }
public async Task HelloWorld(TestVariant variant) { var deploymentParameters = new IISDeploymentParameters(variant) { ApplicationPath = Helpers.GetInProcessTestSitesPath(), PublishApplicationBeforeDeployment = true }; var deploymentResult = await DeployAsync(deploymentParameters); var response = await deploymentResult.RetryingHttpClient.GetAsync("/HelloWorld"); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("Hello World", responseText); }
protected virtual async Task <IISDeploymentResult> DeployAsync(IISDeploymentParameters parameters) { if (!parameters.EnvironmentVariables.ContainsKey(DebugEnvironmentVariable)) { parameters.EnvironmentVariables[DebugEnvironmentVariable] = "4"; } if (parameters.ServerType == ServerType.IISExpress) { parameters.ServerConfigTemplateContent = parameters.ServerConfigTemplateContent ?? File.ReadAllText("IISExpress.config"); } _deployer = IISApplicationDeployerFactory.Create(parameters, LoggerFactory); return((IISDeploymentResult)await _deployer.DeployAsync()); }
public static void EnsureSection(this IISDeploymentParameters parameters, string name, params string[] path) { parameters.ServerConfigActionList.Add( (config, _) => { var element = config .RequiredElement("configSections"); foreach (var s in path) { element = element.GetOrAdd("sectionGroup", "name", s); } element.GetOrAdd("section", "name", "applicationInitialization") .SetAttributeValue("overrideModeDefault", "Allow"); }); }
public async Task WindowsAuthTest(TestVariant variant) { var deploymentParameters = new IISDeploymentParameters(variant) { ApplicationPath = Helpers.GetOutOfProcessTestSitesPath(), }; deploymentParameters.AddWindowsAuthToServerConfig(); // The default in hosting sets windows auth to true. var deploymentResult = await DeployAsync(deploymentParameters); var response = await deploymentResult.HttpClient.GetAsync("/Auth"); var responseText = await response.Content.ReadAsStringAsync(); Assert.True("backcompat;Windows".Equals(responseText) || "latest;Windows".Equals(responseText), "Auth"); }
private static void MoveApplication( IISDeploymentParameters parameters, string subdirectory) { parameters.WebConfigActionList.Add((config, contentRoot) => { var source = new DirectoryInfo(contentRoot); var subDirectoryPath = source.CreateSubdirectory(subdirectory); // Copy everything into a subfolder Helpers.CopyFiles(source, subDirectoryPath, null); // Cleanup files foreach (var fileSystemInfo in source.GetFiles()) { fileSystemInfo.Delete(); } }); }
protected ApplicationDeployer CreateDeployer(IISDeploymentParameters parameters) { if (!parameters.EnvironmentVariables.ContainsKey(DebugEnvironmentVariable)) { 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"); } return(IISApplicationDeployerFactory.Create(parameters, LoggerFactory)); }
private async Task HttpsHelloWorldCerts(TestVariant variant, bool sendClientCert) { var port = TestPortHelper.GetNextSSLPort(); var deploymentParameters = new IISDeploymentParameters(variant) { ApplicationPath = Helpers.GetOutOfProcessTestSitesPath(), ApplicationBaseUriHint = $"https://localhost:{port}/", }; deploymentParameters.AddHttpsToServerConfig(); var deploymentResult = await DeployAsync(deploymentParameters); var handler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (a, b, c, d) => true, ClientCertificateOptions = ClientCertificateOption.Manual }; if (sendClientCert) { X509Certificate2 clientCert = FindClientCert(); Assert.NotNull(clientCert); handler.ClientCertificates.Add(clientCert); } var client = deploymentResult.CreateRetryClient(handler); // Request to base address and check if various parts of the body are rendered & measure the cold startup time. var response = await client.GetAsync("checkclientcert"); var responseText = await response.Content.ReadAsStringAsync(); if (sendClientCert) { Assert.Equal("Scheme:https; Original:http; has cert? True", responseText); } else { Assert.Equal("Scheme:https; Original:http; has cert? False", responseText); } }
public static void SetWindowsAuth(this IISDeploymentParameters parameters, bool enabled = true) { parameters.EnsureSection("windowsAuthentication", "system.webServer", "security", "windowsAuthentication"); parameters.EnableModule("WindowsAuthenticationModule", "%IIS_BIN%\\authsspi.dll"); parameters.AddServerConfigAction( element => { var windowsAuthentication = element .RequiredElement("system.webServer") .RequiredElement("security") .RequiredElement("authentication") .GetOrAdd("windowsAuthentication"); windowsAuthentication.SetAttributeValue("enabled", enabled); var providers = windowsAuthentication.GetOrAdd("providers"); providers.GetOrAdd("add", "value", "Negotiate"); providers.GetOrAdd("add", "value", "NTLM"); }); }
public async Task HelloWorld(TestVariant variant) { // The default in hosting sets windows auth to true. // Set it to the IISExpress.config file var deploymentParameters = new IISDeploymentParameters(variant) { ApplicationPath = Helpers.GetOutOfProcessTestSitesPath() }; var deploymentResult = await DeployAsync(deploymentParameters); var response = await deploymentResult.RetryingHttpClient.GetAsync("/HelloWorld"); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("Hello World", responseText); response = await deploymentResult.HttpClient.GetAsync("/Path/%3F%3F?query"); responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("/??", responseText); response = await deploymentResult.HttpClient.GetAsync("/Query/%3FPath?query?"); responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("?query?", responseText); response = await deploymentResult.HttpClient.GetAsync("/BodyLimit"); responseText = await response.Content.ReadAsStringAsync(); Assert.Equal("null", responseText); response = await deploymentResult.HttpClient.GetAsync("/Auth"); responseText = await response.Content.ReadAsStringAsync(); Assert.True("backcompat;Windows".Equals(responseText) || "latest;null".Equals(responseText), "Auth"); }
private static void Configure(IISDeploymentParameters deploymentParameters) { // Enable dynamic compression deploymentParameters.ServerConfigActionList.Add( (element, _) => { var webServerElement = element .RequiredElement("system.webServer"); webServerElement .GetOrAdd("urlCompression") .SetAttributeValue("doDynamicCompression", "true"); webServerElement .GetOrAdd("httpCompression") .GetOrAdd("dynamicTypes") .GetOrAdd("add", "mimeType", "text/*") .SetAttributeValue("enabled", "true"); }); deploymentParameters.EnableModule("DynamicCompressionModule", "%IIS_BIN%\\compdyn.dll"); }
internal IISTestSiteFixture(Action <IISDeploymentParameters> configure) { var logging = AssemblyTestLog.ForAssembly(typeof(IISTestSiteFixture).Assembly); _loggerFactory = logging.CreateLoggerFactory(null, nameof(IISTestSiteFixture)); _forwardingProvider = new ForwardingProvider(); _loggerFactory.AddProvider(_forwardingProvider); _configure = configure; DeploymentParameters = new IISDeploymentParameters() { RuntimeArchitecture = RuntimeArchitecture.x64, RuntimeFlavor = RuntimeFlavor.CoreClr, TargetFramework = Tfm.Default, HostingModel = HostingModel.InProcess, PublishApplicationBeforeDeployment = true, ApplicationPublisher = new PublishedApplicationPublisher(Helpers.GetInProcessTestSitesName()), ServerType = DeployerSelector.ServerType }; }
private static void CopyShimToOutput(IISDeploymentParameters parameters) { parameters.AddServerConfigAction( (config, contentRoot) => { var moduleNodes = config.DescendantNodesAndSelf() .OfType <XElement>() .Where(element => element.Name == "add" && element.Attribute("name")?.Value.StartsWith("AspNetCoreModule") == true && element.Attribute("image") != null); var sourceDirectory = new DirectoryInfo(Path.GetDirectoryName(moduleNodes.First().Attribute("image").Value)); var destinationDirectory = new DirectoryInfo(Path.Combine(contentRoot, sourceDirectory.Name)); destinationDirectory.Create(); foreach (var element in moduleNodes) { var imageAttribute = element.Attribute("image"); imageAttribute.Value = imageAttribute.Value.Replace(sourceDirectory.FullName, destinationDirectory.FullName); } CopyFiles(sourceDirectory, destinationDirectory); }); }
private void EnsureInitialized() { if (_deployer != null) { return; } var deploymentParameters = new IISDeploymentParameters() { RuntimeArchitecture = RuntimeArchitecture.x64, RuntimeFlavor = RuntimeFlavor.CoreClr, TargetFramework = Tfm.NetCoreApp50, HostingModel = HostingModel.InProcess, PublishApplicationBeforeDeployment = true, ApplicationPublisher = new PublishedApplicationPublisher(Helpers.GetInProcessTestSitesName()), ServerType = DeployerSelector.ServerType }; _configure(deploymentParameters); _deployer = IISApplicationDeployerFactory.Create(deploymentParameters, _loggerFactory); _deploymentResult = (IISDeploymentResult)_deployer.DeployAsync().Result; }