public async Task DeployTestAndAddToSpec(ServerType server, bool ssl, string environment, CancellationToken cancellationToken, Action <AutobahnExpectations> expectationConfig = null) { var sslNamePart = ssl ? "SSL" : "NoSSL"; var name = $"{server}|{sslNamePart}|{environment}"; var logger = _loggerFactory.CreateLogger($"AutobahnTestApp:{server}:{sslNamePart}:{environment}"); var appPath = Helpers.GetApplicationPath("AutobahnTestApp"); var configPath = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "Http.config"); var targetFramework = #if NETCOREAPP2_2 "netcoreapp2.2"; #else #error Target frameworks need to be updated #endif var parameters = new DeploymentParameters(appPath, server, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) { Scheme = (ssl ? Uri.UriSchemeHttps : Uri.UriSchemeHttp), ApplicationType = ApplicationType.Portable, TargetFramework = targetFramework, EnvironmentName = environment, SiteName = "HttpTestSite", // This is configured in the Http.config ServerConfigTemplateContent = (server == ServerType.IISExpress) ? File.ReadAllText(configPath) : null, }; var deployer = ApplicationDeployerFactory.Create(parameters, _loggerFactory); var result = await deployer.DeployAsync(); _deployers.Add(deployer); _deployments.Add(result); cancellationToken.ThrowIfCancellationRequested(); var handler = new HttpClientHandler(); // Win7 HttpClient on NetCoreApp2.2 defaults to TLS 1.0 and won't connect to Kestrel. https://github.com/dotnet/corefx/issues/28733 // Mac HttpClient on NetCoreApp2.0 doesn't alow you to set some combinations. // https://github.com/dotnet/corefx/blob/586cffcdfdf23ad6c193a4bf37fce88a1bf69508/src/System.Net.Http/src/System/Net/Http/CurlHandler/CurlHandler.SslProvider.OSX.cs#L104-L106 handler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls; handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; var client = result.CreateHttpClient(handler); // Make sure the server works var resp = await RetryHelper.RetryRequest(() => { cancellationToken.ThrowIfCancellationRequested(); return(client.GetAsync(result.ApplicationBaseUri)); }, logger, CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, result.HostShutdownToken).Token); resp.EnsureSuccessStatusCode(); cancellationToken.ThrowIfCancellationRequested(); // Add to the current spec var wsUrl = result.ApplicationBaseUri.Replace("https://", "wss://").Replace("http://", "ws://"); Spec.WithServer(name, wsUrl); var expectations = new AutobahnExpectations(server, ssl, environment); expectationConfig?.Invoke(expectations); _expectations.Add(expectations); cancellationToken.ThrowIfCancellationRequested(); }
public async Task DeployTestAndAddToSpec(ServerType server, bool ssl, string environment, CancellationToken cancellationToken, Action <AutobahnExpectations> expectationConfig = null) { var baseUrl = ssl ? "https://localhost:0" : "http://localhost:0"; var sslNamePart = ssl ? "SSL" : "NoSSL"; var name = $"{server}|{sslNamePart}|{environment}"; var logger = _loggerFactory.CreateLogger($"AutobahnTestApp:{server}:{sslNamePart}:{environment}"); var appPath = Helpers.GetApplicationPath("AutobahnTestApp"); var configPath = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "Http.config"); var targetFramework = #if NETCOREAPP2_1 "netcoreapp2.1"; #elif NETCOREAPP2_0 "netcoreapp2.0"; #else #error Target frameworks need to be updated #endif var parameters = new DeploymentParameters(appPath, server, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64) { ApplicationBaseUriHint = baseUrl, ApplicationType = ApplicationType.Portable, TargetFramework = targetFramework, EnvironmentName = environment, SiteName = "HttpTestSite", // This is configured in the Http.config ServerConfigTemplateContent = (server == ServerType.IISExpress) ? File.ReadAllText(configPath) : null, }; var deployer = ApplicationDeployerFactory.Create(parameters, _loggerFactory); var result = await deployer.DeployAsync(); _deployers.Add(deployer); _deployments.Add(result); cancellationToken.ThrowIfCancellationRequested(); var handler = new HttpClientHandler(); if (ssl) { // Don't take this out of the "if(ssl)". If we set it on some platforms, it crashes // So we avoid running SSL tests on those platforms (for now). // See https://github.com/dotnet/corefx/issues/9728 handler.ServerCertificateCustomValidationCallback = (_, __, ___, ____) => true; } var client = result.CreateHttpClient(handler); // Make sure the server works var resp = await RetryHelper.RetryRequest(() => { cancellationToken.ThrowIfCancellationRequested(); return(client.GetAsync(result.ApplicationBaseUri)); }, logger, CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, result.HostShutdownToken).Token); resp.EnsureSuccessStatusCode(); cancellationToken.ThrowIfCancellationRequested(); // Add to the current spec var wsUrl = result.ApplicationBaseUri.Replace("https://", "wss://").Replace("http://", "ws://"); Spec.WithServer(name, wsUrl); var expectations = new AutobahnExpectations(server, ssl, environment); expectationConfig?.Invoke(expectations); _expectations.Add(expectations); cancellationToken.ThrowIfCancellationRequested(); }