Add HTTPS tests for node/browser tests (#3283)

This commit is contained in:
BrennanConroy 2018-11-09 15:29:00 -08:00 committed by GitHub
parent d0dac557ac
commit df668017ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 158 additions and 69 deletions

View File

@ -5,58 +5,58 @@
<PropertyGroup Label="Package Versions"> <PropertyGroup Label="Package Versions">
<BenchmarkDotNetPackageVersion>0.10.13</BenchmarkDotNetPackageVersion> <BenchmarkDotNetPackageVersion>0.10.13</BenchmarkDotNetPackageVersion>
<GoogleProtobufPackageVersion>3.1.0</GoogleProtobufPackageVersion> <GoogleProtobufPackageVersion>3.1.0</GoogleProtobufPackageVersion>
<InternalAspNetCoreAnalyzersPackageVersion>2.2.0-rtm-35532</InternalAspNetCoreAnalyzersPackageVersion> <InternalAspNetCoreAnalyzersPackageVersion>2.2.0-rtm-181106-13</InternalAspNetCoreAnalyzersPackageVersion>
<InternalAspNetCoreSdkPackageVersion>2.2.0-preview2-20181011.2</InternalAspNetCoreSdkPackageVersion> <InternalAspNetCoreSdkPackageVersion>2.2.0-preview2-20181011.2</InternalAspNetCoreSdkPackageVersion>
<MessagePackPackageVersion>1.7.3.4</MessagePackPackageVersion> <MessagePackPackageVersion>1.7.3.4</MessagePackPackageVersion>
<MicrosoftAspNetCoreAllPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreAllPackageVersion> <MicrosoftAspNetCoreAllPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreAllPackageVersion>
<MicrosoftAspNetCoreAuthenticationCookiesPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreAuthenticationCookiesPackageVersion> <MicrosoftAspNetCoreAuthenticationCookiesPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreAuthenticationCookiesPackageVersion>
<MicrosoftAspNetCoreAuthenticationCorePackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreAuthenticationCorePackageVersion> <MicrosoftAspNetCoreAuthenticationCorePackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreAuthenticationCorePackageVersion>
<MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion> <MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreAuthenticationJwtBearerPackageVersion>
<MicrosoftAspNetCoreAuthorizationPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreAuthorizationPackageVersion> <MicrosoftAspNetCoreAuthorizationPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreAuthorizationPackageVersion>
<MicrosoftAspNetCoreAuthorizationPolicyPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreAuthorizationPolicyPackageVersion> <MicrosoftAspNetCoreAuthorizationPolicyPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreAuthorizationPolicyPackageVersion>
<MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion> <MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>2.2.0-rtm-181106-13</MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion>
<MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion> <MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>
<MicrosoftAspNetCoreCorsPackageVersion>2.2.0-preview3-35457</MicrosoftAspNetCoreCorsPackageVersion> <MicrosoftAspNetCoreCorsPackageVersion>2.2.0-preview3-35457</MicrosoftAspNetCoreCorsPackageVersion>
<MicrosoftAspNetCoreDiagnosticsEntityFrameworkCorePackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreDiagnosticsEntityFrameworkCorePackageVersion> <MicrosoftAspNetCoreDiagnosticsEntityFrameworkCorePackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreDiagnosticsEntityFrameworkCorePackageVersion>
<MicrosoftAspNetCoreDiagnosticsPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreDiagnosticsPackageVersion> <MicrosoftAspNetCoreDiagnosticsPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreDiagnosticsPackageVersion>
<MicrosoftAspNetCoreHostingAbstractionsPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreHostingAbstractionsPackageVersion> <MicrosoftAspNetCoreHostingAbstractionsPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreHostingAbstractionsPackageVersion>
<MicrosoftAspNetCoreHostingPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreHostingPackageVersion> <MicrosoftAspNetCoreHostingPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreHostingPackageVersion>
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreHttpAbstractionsPackageVersion> <MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>
<MicrosoftAspNetCoreHttpFeaturesPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreHttpFeaturesPackageVersion> <MicrosoftAspNetCoreHttpFeaturesPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreHttpFeaturesPackageVersion>
<MicrosoftAspNetCoreHttpPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreHttpPackageVersion> <MicrosoftAspNetCoreHttpPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreHttpPackageVersion>
<MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion> <MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion>
<MicrosoftAspNetCoreMvcPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreMvcPackageVersion> <MicrosoftAspNetCoreMvcPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreMvcPackageVersion>
<MicrosoftAspNetCoreRoutingPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreRoutingPackageVersion> <MicrosoftAspNetCoreRoutingPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreRoutingPackageVersion>
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreServerIISIntegrationPackageVersion> <MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
<MicrosoftAspNetCoreServerKestrelPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreServerKestrelPackageVersion> <MicrosoftAspNetCoreServerKestrelPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreServerKestrelPackageVersion>
<MicrosoftAspNetCoreStaticFilesPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreStaticFilesPackageVersion> <MicrosoftAspNetCoreStaticFilesPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreStaticFilesPackageVersion>
<MicrosoftAspNetCoreTestHostPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreTestHostPackageVersion> <MicrosoftAspNetCoreTestHostPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreTestHostPackageVersion>
<MicrosoftAspNetCoreTestingPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreTestingPackageVersion> <MicrosoftAspNetCoreTestingPackageVersion>2.2.0-rtm-181106-13</MicrosoftAspNetCoreTestingPackageVersion>
<MicrosoftAspNetCoreWebSocketsPackageVersion>2.2.0-rtm-35532</MicrosoftAspNetCoreWebSocketsPackageVersion> <MicrosoftAspNetCoreWebSocketsPackageVersion>2.2.0-rtm-35661</MicrosoftAspNetCoreWebSocketsPackageVersion>
<MicrosoftCSharpPackageVersion>4.5.0</MicrosoftCSharpPackageVersion> <MicrosoftCSharpPackageVersion>4.5.0</MicrosoftCSharpPackageVersion>
<MicrosoftEntityFrameworkCoreDesignPackageVersion>2.2.0-rtm-35532</MicrosoftEntityFrameworkCoreDesignPackageVersion> <MicrosoftEntityFrameworkCoreDesignPackageVersion>2.2.0-rtm-35661</MicrosoftEntityFrameworkCoreDesignPackageVersion>
<MicrosoftEntityFrameworkCoreSqlServerPackageVersion>2.2.0-rtm-35532</MicrosoftEntityFrameworkCoreSqlServerPackageVersion> <MicrosoftEntityFrameworkCoreSqlServerPackageVersion>2.2.0-rtm-35661</MicrosoftEntityFrameworkCoreSqlServerPackageVersion>
<MicrosoftEntityFrameworkCoreToolsPackageVersion>2.2.0-rtm-35532</MicrosoftEntityFrameworkCoreToolsPackageVersion> <MicrosoftEntityFrameworkCoreToolsPackageVersion>2.2.0-rtm-35661</MicrosoftEntityFrameworkCoreToolsPackageVersion>
<MicrosoftExtensionsBuffersTestingSourcesPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsBuffersTestingSourcesPackageVersion> <MicrosoftExtensionsBuffersTestingSourcesPackageVersion>2.2.0-rtm-35661</MicrosoftExtensionsBuffersTestingSourcesPackageVersion>
<MicrosoftExtensionsClosedGenericMatcherSourcesPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsClosedGenericMatcherSourcesPackageVersion> <MicrosoftExtensionsClosedGenericMatcherSourcesPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsClosedGenericMatcherSourcesPackageVersion>
<MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion> <MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>
<MicrosoftExtensionsConfigurationCommandLinePackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsConfigurationCommandLinePackageVersion> <MicrosoftExtensionsConfigurationCommandLinePackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsConfigurationCommandLinePackageVersion>
<MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion> <MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion>
<MicrosoftExtensionsConfigurationUserSecretsPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsConfigurationUserSecretsPackageVersion> <MicrosoftExtensionsConfigurationUserSecretsPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsConfigurationUserSecretsPackageVersion>
<MicrosoftExtensionsDependencyInjectionAbstractionsPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsDependencyInjectionAbstractionsPackageVersion> <MicrosoftExtensionsDependencyInjectionAbstractionsPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsDependencyInjectionAbstractionsPackageVersion>
<MicrosoftExtensionsDependencyInjectionPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsDependencyInjectionPackageVersion> <MicrosoftExtensionsDependencyInjectionPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsDependencyInjectionPackageVersion>
<MicrosoftExtensionsLoggingAbstractionsPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsLoggingAbstractionsPackageVersion> <MicrosoftExtensionsLoggingAbstractionsPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsLoggingAbstractionsPackageVersion>
<MicrosoftExtensionsLoggingConfigurationPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsLoggingConfigurationPackageVersion> <MicrosoftExtensionsLoggingConfigurationPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsLoggingConfigurationPackageVersion>
<MicrosoftExtensionsLoggingConsolePackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsLoggingConsolePackageVersion> <MicrosoftExtensionsLoggingConsolePackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsLoggingConsolePackageVersion>
<MicrosoftExtensionsLoggingDebugPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsLoggingDebugPackageVersion> <MicrosoftExtensionsLoggingDebugPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsLoggingDebugPackageVersion>
<MicrosoftExtensionsLoggingPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsLoggingPackageVersion> <MicrosoftExtensionsLoggingPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsLoggingPackageVersion>
<MicrosoftExtensionsLoggingTestingPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsLoggingTestingPackageVersion> <MicrosoftExtensionsLoggingTestingPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsLoggingTestingPackageVersion>
<MicrosoftExtensionsObjectMethodExecutorSourcesPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsObjectMethodExecutorSourcesPackageVersion> <MicrosoftExtensionsObjectMethodExecutorSourcesPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsObjectMethodExecutorSourcesPackageVersion>
<MicrosoftExtensionsOptionsPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsOptionsPackageVersion> <MicrosoftExtensionsOptionsPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsOptionsPackageVersion>
<MicrosoftExtensionsSecurityHelperSourcesPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsSecurityHelperSourcesPackageVersion> <MicrosoftExtensionsSecurityHelperSourcesPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsSecurityHelperSourcesPackageVersion>
<MicrosoftExtensionsValueStopwatchSourcesPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsValueStopwatchSourcesPackageVersion> <MicrosoftExtensionsValueStopwatchSourcesPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsValueStopwatchSourcesPackageVersion>
<MicrosoftExtensionsWebEncodersSourcesPackageVersion>2.2.0-rtm-35532</MicrosoftExtensionsWebEncodersSourcesPackageVersion> <MicrosoftExtensionsWebEncodersSourcesPackageVersion>2.2.0-rtm-181106-13</MicrosoftExtensionsWebEncodersSourcesPackageVersion>
<MicrosoftNETCoreApp22PackageVersion>2.2.0-preview3-27014-02</MicrosoftNETCoreApp22PackageVersion> <MicrosoftNETCoreApp22PackageVersion>2.2.0-rtm-27105-02</MicrosoftNETCoreApp22PackageVersion>
<MicrosoftNETTestSdkPackageVersion>15.6.1</MicrosoftNETTestSdkPackageVersion> <MicrosoftNETTestSdkPackageVersion>15.6.1</MicrosoftNETTestSdkPackageVersion>
<MoqPackageVersion>4.10.0</MoqPackageVersion> <MoqPackageVersion>4.10.0</MoqPackageVersion>
<NETStandardLibrary20PackageVersion>2.0.3</NETStandardLibrary20PackageVersion> <NETStandardLibrary20PackageVersion>2.0.3</NETStandardLibrary20PackageVersion>

View File

@ -3,8 +3,11 @@
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Win32;
namespace FunctionalTests namespace FunctionalTests
{ {
@ -31,7 +34,42 @@ namespace FunctionalTests
factory.AddDebug(); factory.AddDebug();
factory.SetMinimumLevel(LogLevel.Information); factory.SetMinimumLevel(LogLevel.Information);
}) })
.UseKestrel() .UseKestrel((builderContext, options) =>
{
options.ConfigureHttpsDefaults(httpsOptions =>
{
bool useRSA = false;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Detect Win10+
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
var major = key.GetValue("CurrentMajorVersionNumber") as int?;
var minor = key.GetValue("CurrentMinorVersionNumber") as int?;
if (major.HasValue && minor.HasValue)
{
useRSA = true;
}
}
else
{
useRSA = true;
}
if (useRSA)
{
// RSA cert, won't work on Windows 8.1 & Windows 2012 R2 using HTTP2, and ECC won't work in some Node environments
var certPath = Path.Combine(Directory.GetCurrentDirectory(), "testCert.pfx");
httpsOptions.ServerCertificate = new X509Certificate2(certPath, "testPassword");
}
else
{
// ECC cert, works on Windows 8.1 & Windows 2012 R2 using HTTP2
var certPath = Path.Combine(Directory.GetCurrentDirectory(), "testCertECC.pfx");
httpsOptions.ServerCertificate = new X509Certificate2(certPath, "testPassword");
}
});
})
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() .UseIISIntegration()
.UseStartup<Startup>(); .UseStartup<Startup>();

View File

@ -57,8 +57,9 @@ try {
ChromeHeadlessNoSandbox: { ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless', base: 'ChromeHeadless',
// Ignore cert errors to allow our test cert to work (NEVER do this outside of testing)
// ChromeHeadless runs about 10x slower on Windows 7 machines without the --proxy switches below. Why? ¯\_(ツ)_/¯ // ChromeHeadless runs about 10x slower on Windows 7 machines without the --proxy switches below. Why? ¯\_(ツ)_/¯
flags: ["--no-sandbox", "--proxy-server='direct://'", "--proxy-bypass-list=*"] flags: ["--no-sandbox", "--proxy-server='direct://'", "--proxy-bypass-list=*", "--allow-insecure-localhost", "--ignore-certificate-errors"]
} }
}, },
}); });

View File

@ -33,11 +33,12 @@ setTimeout(() => {
process.exit(1); process.exit(1);
}, 1000 * 60 * 10); }, 1000 * 60 * 10);
function waitForMatch(command: string, process: ChildProcess, regex: RegExp): Promise<RegExpMatchArray> { function waitForMatches(command: string, process: ChildProcess, regex: RegExp, matchCount: number): Promise<RegExpMatchArray> {
return new Promise<RegExpMatchArray>((resolve, reject) => { return new Promise<string[]>((resolve, reject) => {
const commandDebug = _debug(`${command}`); const commandDebug = _debug(`${command}`);
try { try {
let lastLine = ""; let lastLine = "";
let results: string[] = null;
async function onData(this: Readable, chunk: string | Buffer): Promise<void> { async function onData(this: Readable, chunk: string | Buffer): Promise<void> {
try { try {
@ -50,15 +51,23 @@ function waitForMatch(command: string, process: ChildProcess, regex: RegExp): Pr
lastLine = ""; lastLine = "";
chunk = chunk.substring(lineEnd + EOL.length); chunk = chunk.substring(lineEnd + EOL.length);
const res = regex.exec(chunkLine);
if (results == null && res != null) {
results = res;
} else if (res != null) {
results = Array<string>().concat(results, res);
}
const results = regex.exec(chunkLine); // * 2 because each match will have the original line plus the match
commandDebug(chunkLine); if (results && results.length >= matchCount * 2) {
if (results && results.length > 0) {
resolve(results); resolve(results);
return; return;
} }
commandDebug(chunkLine);
lineEnd = chunk.indexOf(EOL); lineEnd = chunk.indexOf(EOL);
} }
lastLine = chunk.toString(); lastLine = chunk.toString();
} catch (e) { } catch (e) {
this.removeAllListeners("data"); this.removeAllListeners("data");
@ -158,15 +167,17 @@ function runKarma(karmaConfig) {
}); });
} }
function runJest(url: string) { function runJest(httpsUrl: string, httpUrl: string) {
const jestPath = path.resolve(__dirname, "..", "..", "common", "node_modules", "jest", "bin", "jest.js"); const jestPath = path.resolve(__dirname, "..", "..", "common", "node_modules", "jest", "bin", "jest.js");
const configPath = path.resolve(__dirname, "..", "func.jest.config.js"); const configPath = path.resolve(__dirname, "..", "func.jest.config.js");
console.log("Starting Node tests using Jest."); console.log("Starting Node tests using Jest.");
return new Promise<number>((resolve, reject) => { return new Promise<number>((resolve, reject) => {
const logStream = fs.createWriteStream(path.resolve(__dirname, "..", "..", "..", "..", "artifacts", "logs", "node.functionaltests.log")); const logStream = fs.createWriteStream(path.resolve(__dirname, "..", "..", "..", "..", "artifacts", "logs", "node.functionaltests.log"));
const p = exec(`"${process.execPath}" "${jestPath}" --config "${configPath}"`, { env: { SERVER_URL: url }, timeout: 200000, maxBuffer: 10 * 1024 * 1024 }, // Use NODE_TLS_REJECT_UNAUTHORIZED to allow our test cert to be used by the Node tests (NEVER use this environment variable outside of testing)
const p = exec(`"${process.execPath}" "${jestPath}" --config "${configPath}"`, { env: { SERVER_URL: `${httpsUrl};${httpUrl}`, NODE_TLS_REJECT_UNAUTHORIZED: 0 }, timeout: 200000, maxBuffer: 10 * 1024 * 1024 },
(error: any, stdout, stderr) => { (error: any, stdout, stderr) => {
console.log("Finished Node tests.");
if (error) { if (error) {
console.log(error.message); console.log(error.message);
return resolve(error.code); return resolve(error.code);
@ -183,7 +194,7 @@ function runJest(url: string) {
const serverPath = path.resolve(__dirname, "..", "bin", configuration, "netcoreapp2.2", "FunctionalTests.dll"); const serverPath = path.resolve(__dirname, "..", "bin", configuration, "netcoreapp2.2", "FunctionalTests.dll");
debug(`Launching Functional Test Server: ${serverPath}`); debug(`Launching Functional Test Server: ${serverPath}`);
let desiredServerUrl = "http://127.0.0.1:0"; let desiredServerUrl = "https://127.0.0.1:0;http://127.0.0.1:0";
if (sauce) { if (sauce) {
// SauceLabs can only proxy certain ports for Edge and Safari. // SauceLabs can only proxy certain ports for Edge and Safari.
@ -212,11 +223,12 @@ function runJest(url: string) {
process.on("exit", cleanup); process.on("exit", cleanup);
debug("Waiting for Functional Test Server to start"); debug("Waiting for Functional Test Server to start");
const matches = await waitForMatch("dotnet", dotnet, /Now listening on: (http:\/\/[^\/]+:[\d]+)/); const matches = await waitForMatches("dotnet", dotnet, /Now listening on: (https?:\/\/[^\/]+:[\d]+)/, 2);
const url = matches[1]; const httpsUrl = matches[1];
debug(`Functional Test Server has started at ${url}`); const httpUrl = matches[3];
debug(`Functional Test Server has started at ${httpsUrl} and ${httpUrl}`);
debug(`Using SignalR Server: ${url}`); debug(`Using SignalR Server: ${httpsUrl} and ${httpUrl}`);
// Start karma server // Start karma server
const conf = { const conf = {
@ -238,9 +250,9 @@ function runJest(url: string) {
} }
// Pass server URL to tests // Pass server URL to tests
conf.client.args = ["--server", url]; conf.client.args = ["--server", `${httpsUrl};${httpUrl}`];
const jestExit = await runJest(url); const jestExit = await runJest(httpsUrl, httpUrl);
// Check if we got any browsers // Check if we got any browsers
let karmaExit; let karmaExit;

Binary file not shown.

Binary file not shown.

View File

@ -5,27 +5,35 @@ import { HttpTransportType, IHubProtocol, JsonHubProtocol } from "@aspnet/signal
import { MessagePackHubProtocol } from "@aspnet/signalr-protocol-msgpack"; import { MessagePackHubProtocol } from "@aspnet/signalr-protocol-msgpack";
export let ENDPOINT_BASE_URL: string; export let ENDPOINT_BASE_URL: string;
export let ENDPOINT_BASE_HTTPS_URL: string;
if (typeof window !== "undefined" && (window as any).__karma__) { if (typeof window !== "undefined" && (window as any).__karma__) {
const args = (window as any).__karma__.config.args as string[]; const args = (window as any).__karma__.config.args as string[];
let server = ""; let httpsServer = "";
let httpServer = "";
for (let i = 0; i < args.length; i += 1) { for (let i = 0; i < args.length; i += 1) {
switch (args[i]) { switch (args[i]) {
case "--server": case "--server":
i += 1; i += 1;
server = args[i]; const urls = args[i].split(";");
httpsServer = urls[0];
httpServer = urls[1];
console.log(httpServer);
break; break;
} }
} }
// Running in Karma? Need to use an absolute URL // Running in Karma? Need to use an absolute URL
ENDPOINT_BASE_URL = server; ENDPOINT_BASE_URL = httpServer;
ENDPOINT_BASE_HTTPS_URL = httpsServer;
console.log(`Using SignalR Server: ${ENDPOINT_BASE_URL}`); console.log(`Using SignalR Server: ${ENDPOINT_BASE_URL}`);
} else if (typeof document !== "undefined") { } else if (typeof document !== "undefined") {
ENDPOINT_BASE_URL = `${document.location.protocol}//${document.location.host}`; ENDPOINT_BASE_URL = `${document.location.protocol}//${document.location.host}`;
} else if (process && process.env && process.env.SERVER_URL) { } else if (process && process.env && process.env.SERVER_URL) {
ENDPOINT_BASE_URL = process.env.SERVER_URL; const urls = process.env.SERVER_URL.split(";");
ENDPOINT_BASE_HTTPS_URL = urls[0];
ENDPOINT_BASE_URL = urls[1];
} else { } else {
throw new Error("The server could not be found."); throw new Error("The server could not be found.");
} }

View File

@ -7,11 +7,12 @@
import { AbortError, DefaultHttpClient, HttpClient, HttpRequest, HttpResponse, HttpTransportType, HubConnectionBuilder, IHttpConnectionOptions, JsonHubProtocol, NullLogger } from "@aspnet/signalr"; import { AbortError, DefaultHttpClient, HttpClient, HttpRequest, HttpResponse, HttpTransportType, HubConnectionBuilder, IHttpConnectionOptions, JsonHubProtocol, NullLogger } from "@aspnet/signalr";
import { MessagePackHubProtocol } from "@aspnet/signalr-protocol-msgpack"; import { MessagePackHubProtocol } from "@aspnet/signalr-protocol-msgpack";
import { eachTransport, eachTransportAndProtocol, ENDPOINT_BASE_URL } from "./Common"; import { eachTransport, eachTransportAndProtocol, ENDPOINT_BASE_HTTPS_URL, ENDPOINT_BASE_URL } from "./Common";
import "./LogBannerReporter"; import "./LogBannerReporter";
import { TestLogger } from "./TestLogger"; import { TestLogger } from "./TestLogger";
const TESTHUBENDPOINT_URL = ENDPOINT_BASE_URL + "/testhub"; const TESTHUBENDPOINT_URL = ENDPOINT_BASE_URL + "/testhub";
const TESTHUBENDPOINT_HTTPS_URL = ENDPOINT_BASE_HTTPS_URL + "/testhub";
const TESTHUB_NOWEBSOCKETS_ENDPOINT_URL = ENDPOINT_BASE_URL + "/testhub-nowebsockets"; const TESTHUB_NOWEBSOCKETS_ENDPOINT_URL = ENDPOINT_BASE_URL + "/testhub-nowebsockets";
// On slower CI machines, these tests sometimes take longer than 5s // On slower CI machines, these tests sometimes take longer than 5s
@ -62,6 +63,35 @@ describe("hubConnection", () => {
}); });
}); });
// Run test in Node or Chrome, but not on macOS
if ((process && process.platform !== "darwin") && (typeof navigator === "undefined" || navigator.userAgent.search("Chrome") !== -1)) {
it("using https, can invoke server method and receive result", (done) => {
const message = "你好,世界!";
const hubConnection = getConnectionBuilder(transportType, TESTHUBENDPOINT_HTTPS_URL)
.withHubProtocol(protocol)
.build();
hubConnection.onclose((error) => {
expect(error).toBeUndefined();
done();
});
hubConnection.start().then(() => {
hubConnection.invoke("Echo", message).then((result) => {
expect(result).toBe(message);
}).catch((e) => {
fail(e);
}).then(() => {
hubConnection.stop();
});
}).catch((e) => {
fail(e);
done();
});
});
}
it("can invoke server method non-blocking and not receive result", (done) => { it("can invoke server method non-blocking and not receive result", (done) => {
const message = "你好,世界!"; const message = "你好,世界!";