Fix SignalR typescript tests with Chrome SameSite reaction (#25283)
* Fix Typescript tests * fixup
This commit is contained in:
parent
2916f4b09b
commit
f2b72b0511
|
|
@ -163,9 +163,21 @@ namespace FunctionalTests
|
||||||
{
|
{
|
||||||
if (context.Request.Path.Value.Contains("/negotiate"))
|
if (context.Request.Path.Value.Contains("/negotiate"))
|
||||||
{
|
{
|
||||||
context.Response.Cookies.Append("testCookie", "testValue");
|
var cookieOptions = new CookieOptions();
|
||||||
context.Response.Cookies.Append("testCookie2", "testValue2");
|
var expiredCookieOptions = new CookieOptions() { Expires = DateTimeOffset.Now.AddHours(-1) };
|
||||||
context.Response.Cookies.Append("expiredCookie", "doesntmatter", new CookieOptions() { Expires = DateTimeOffset.Now.AddHours(-1) });
|
if (context.Request.IsHttps)
|
||||||
|
{
|
||||||
|
cookieOptions.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.None;
|
||||||
|
cookieOptions.Secure = true;
|
||||||
|
|
||||||
|
expiredCookieOptions.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.None;
|
||||||
|
expiredCookieOptions.Secure = true;
|
||||||
|
}
|
||||||
|
context.Response.Cookies.Append("testCookie", "testValue", cookieOptions);
|
||||||
|
context.Response.Cookies.Append("testCookie2", "testValue2", cookieOptions);
|
||||||
|
|
||||||
|
cookieOptions.Expires = DateTimeOffset.Now.AddHours(-1);
|
||||||
|
context.Response.Cookies.Append("expiredCookie", "doesntmatter", expiredCookieOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
await next.Invoke();
|
await next.Invoke();
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ console.log(`Using SignalR HTTPS Server: '${ENDPOINT_BASE_HTTPS_URL}'`);
|
||||||
console.log(`Jasmine DEFAULT_TIMEOUT_INTERVAL: ${jasmine.DEFAULT_TIMEOUT_INTERVAL}`);
|
console.log(`Jasmine DEFAULT_TIMEOUT_INTERVAL: ${jasmine.DEFAULT_TIMEOUT_INTERVAL}`);
|
||||||
|
|
||||||
export const ECHOENDPOINT_URL = ENDPOINT_BASE_URL + "/echo";
|
export const ECHOENDPOINT_URL = ENDPOINT_BASE_URL + "/echo";
|
||||||
|
export const HTTPS_ECHOENDPOINT_URL = ENDPOINT_BASE_HTTPS_URL + "/echo";
|
||||||
|
|
||||||
export function getHttpTransportTypes(): HttpTransportType[] {
|
export function getHttpTransportTypes(): HttpTransportType[] {
|
||||||
const transportTypes = [];
|
const transportTypes = [];
|
||||||
|
|
@ -131,3 +132,14 @@ export function eachHttpClient(action: (transport: HttpClient) => void) {
|
||||||
return action(t);
|
return action(t);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run test in Node or Chrome, but not on macOS
|
||||||
|
export const shouldRunHttpsTests =
|
||||||
|
// Need to have an HTTPS URL
|
||||||
|
!!ENDPOINT_BASE_HTTPS_URL &&
|
||||||
|
|
||||||
|
// Run on Node, unless macOS
|
||||||
|
(process && process.platform !== "darwin") &&
|
||||||
|
|
||||||
|
// Only run under Chrome browser
|
||||||
|
(typeof navigator === "undefined" || navigator.userAgent.search("Chrome") !== -1);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
// tslint:disable:no-floating-promises
|
// tslint:disable:no-floating-promises
|
||||||
|
|
||||||
import { HttpTransportType, IHttpConnectionOptions, TransferFormat } from "@microsoft/signalr";
|
import { HttpTransportType, IHttpConnectionOptions, TransferFormat } from "@microsoft/signalr";
|
||||||
import { DEFAULT_TIMEOUT_INTERVAL, eachHttpClient, eachTransport, ECHOENDPOINT_URL } from "./Common";
|
import { DEFAULT_TIMEOUT_INTERVAL, eachHttpClient, eachTransport, ECHOENDPOINT_URL, HTTPS_ECHOENDPOINT_URL, shouldRunHttpsTests } from "./Common";
|
||||||
import { TestLogger } from "./TestLogger";
|
import { TestLogger } from "./TestLogger";
|
||||||
|
|
||||||
// We want to continue testing HttpConnection, but we don't export it anymore. So just pull it in directly from the source file.
|
// We want to continue testing HttpConnection, but we don't export it anymore. So just pull it in directly from the source file.
|
||||||
|
|
@ -15,6 +15,8 @@ import "./LogBannerReporter";
|
||||||
|
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = DEFAULT_TIMEOUT_INTERVAL;
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = DEFAULT_TIMEOUT_INTERVAL;
|
||||||
|
|
||||||
|
const USED_ECHOENDPOINT_URL = shouldRunHttpsTests ? HTTPS_ECHOENDPOINT_URL : ECHOENDPOINT_URL;
|
||||||
|
|
||||||
const commonOptions: IHttpConnectionOptions = {
|
const commonOptions: IHttpConnectionOptions = {
|
||||||
logMessageContent: true,
|
logMessageContent: true,
|
||||||
logger: TestLogger.instance,
|
logger: TestLogger.instance,
|
||||||
|
|
@ -23,7 +25,7 @@ const commonOptions: IHttpConnectionOptions = {
|
||||||
describe("connection", () => {
|
describe("connection", () => {
|
||||||
it("can connect to the server without specifying transport explicitly", (done) => {
|
it("can connect to the server without specifying transport explicitly", (done) => {
|
||||||
const message = "Hello World!";
|
const message = "Hello World!";
|
||||||
const connection = new HttpConnection(ECHOENDPOINT_URL, {
|
const connection = new HttpConnection(USED_ECHOENDPOINT_URL, {
|
||||||
...commonOptions,
|
...commonOptions,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -53,7 +55,7 @@ describe("connection", () => {
|
||||||
const message = "Hello World!";
|
const message = "Hello World!";
|
||||||
// the url should be resolved relative to the document.location.host
|
// the url should be resolved relative to the document.location.host
|
||||||
// and the leading '/' should be automatically added to the url
|
// and the leading '/' should be automatically added to the url
|
||||||
const connection = new HttpConnection(ECHOENDPOINT_URL, {
|
const connection = new HttpConnection(USED_ECHOENDPOINT_URL, {
|
||||||
...commonOptions,
|
...commonOptions,
|
||||||
httpClient,
|
httpClient,
|
||||||
transport: transportType,
|
transport: transportType,
|
||||||
|
|
@ -83,7 +85,7 @@ describe("connection", () => {
|
||||||
const message = "Hello World!";
|
const message = "Hello World!";
|
||||||
|
|
||||||
// DON'T use commonOptions because we want to specifically test the scenario where logMessageContent is not set.
|
// DON'T use commonOptions because we want to specifically test the scenario where logMessageContent is not set.
|
||||||
const connection = new HttpConnection(ECHOENDPOINT_URL, {
|
const connection = new HttpConnection(USED_ECHOENDPOINT_URL, {
|
||||||
httpClient,
|
httpClient,
|
||||||
logger: TestLogger.instance,
|
logger: TestLogger.instance,
|
||||||
transport: transportType,
|
transport: transportType,
|
||||||
|
|
@ -119,7 +121,7 @@ describe("connection", () => {
|
||||||
const message = "Hello World!";
|
const message = "Hello World!";
|
||||||
|
|
||||||
// DON'T use commonOptions because we want to specifically test the scenario where logMessageContent is set to true (even if commonOptions changes).
|
// DON'T use commonOptions because we want to specifically test the scenario where logMessageContent is set to true (even if commonOptions changes).
|
||||||
const connection = new HttpConnection(ECHOENDPOINT_URL, {
|
const connection = new HttpConnection(USED_ECHOENDPOINT_URL, {
|
||||||
httpClient,
|
httpClient,
|
||||||
logMessageContent: true,
|
logMessageContent: true,
|
||||||
logger: TestLogger.instance,
|
logger: TestLogger.instance,
|
||||||
|
|
@ -167,7 +169,7 @@ describe("connection", () => {
|
||||||
const message = "Hello World!";
|
const message = "Hello World!";
|
||||||
|
|
||||||
// The server will set some response headers for the '/negotiate' endpoint
|
// The server will set some response headers for the '/negotiate' endpoint
|
||||||
const connection = new HttpConnection(ECHOENDPOINT_URL, {
|
const connection = new HttpConnection(USED_ECHOENDPOINT_URL, {
|
||||||
...commonOptions,
|
...commonOptions,
|
||||||
httpClient,
|
httpClient,
|
||||||
transport: transportType,
|
transport: transportType,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import { AbortError, DefaultHttpClient, HttpClient, HttpRequest, HttpResponse, H
|
||||||
import { MessagePackHubProtocol } from "@microsoft/signalr-protocol-msgpack";
|
import { MessagePackHubProtocol } from "@microsoft/signalr-protocol-msgpack";
|
||||||
import { getUserAgentHeader, Platform } from "@microsoft/signalr/dist/esm/Utils";
|
import { getUserAgentHeader, Platform } from "@microsoft/signalr/dist/esm/Utils";
|
||||||
|
|
||||||
import { DEFAULT_TIMEOUT_INTERVAL, eachTransport, eachTransportAndProtocolAndHttpClient, ENDPOINT_BASE_HTTPS_URL, ENDPOINT_BASE_URL } from "./Common";
|
import { DEFAULT_TIMEOUT_INTERVAL, eachTransport, eachTransportAndProtocolAndHttpClient, ENDPOINT_BASE_HTTPS_URL, ENDPOINT_BASE_URL, shouldRunHttpsTests } from "./Common";
|
||||||
import "./LogBannerReporter";
|
import "./LogBannerReporter";
|
||||||
import { TestLogger } from "./TestLogger";
|
import { TestLogger } from "./TestLogger";
|
||||||
|
|
||||||
|
|
@ -18,6 +18,7 @@ import * as RX from "rxjs";
|
||||||
|
|
||||||
const TESTHUBENDPOINT_URL = ENDPOINT_BASE_URL + "/testhub";
|
const TESTHUBENDPOINT_URL = ENDPOINT_BASE_URL + "/testhub";
|
||||||
const TESTHUBENDPOINT_HTTPS_URL = ENDPOINT_BASE_HTTPS_URL ? (ENDPOINT_BASE_HTTPS_URL + "/testhub") : undefined;
|
const TESTHUBENDPOINT_HTTPS_URL = ENDPOINT_BASE_HTTPS_URL ? (ENDPOINT_BASE_HTTPS_URL + "/testhub") : undefined;
|
||||||
|
const HTTPORHTTPS_TESTHUBENDPOINT_URL = shouldRunHttpsTests ? TESTHUBENDPOINT_HTTPS_URL : TESTHUBENDPOINT_URL;
|
||||||
|
|
||||||
const TESTHUB_NOWEBSOCKETS_ENDPOINT_URL = ENDPOINT_BASE_URL + "/testhub-nowebsockets";
|
const TESTHUB_NOWEBSOCKETS_ENDPOINT_URL = ENDPOINT_BASE_URL + "/testhub-nowebsockets";
|
||||||
const TESTHUB_REDIRECT_ENDPOINT_URL = ENDPOINT_BASE_URL + "/redirect?numRedirects=0&baseUrl=" + ENDPOINT_BASE_URL;
|
const TESTHUB_REDIRECT_ENDPOINT_URL = ENDPOINT_BASE_URL + "/redirect?numRedirects=0&baseUrl=" + ENDPOINT_BASE_URL;
|
||||||
|
|
@ -28,17 +29,6 @@ const commonOptions: IHttpConnectionOptions = {
|
||||||
logMessageContent: true,
|
logMessageContent: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Run test in Node or Chrome, but not on macOS
|
|
||||||
const shouldRunHttpsTests =
|
|
||||||
// Need to have an HTTPS URL
|
|
||||||
!!TESTHUBENDPOINT_HTTPS_URL &&
|
|
||||||
|
|
||||||
// Run on Node, unless macOS
|
|
||||||
(process && process.platform !== "darwin") &&
|
|
||||||
|
|
||||||
// Only run under Chrome browser
|
|
||||||
(typeof navigator === "undefined" || navigator.userAgent.search("Chrome") !== -1);
|
|
||||||
|
|
||||||
function getConnectionBuilder(transportType?: HttpTransportType, url?: string, options?: IHttpConnectionOptions): HubConnectionBuilder {
|
function getConnectionBuilder(transportType?: HttpTransportType, url?: string, options?: IHttpConnectionOptions): HubConnectionBuilder {
|
||||||
let actualOptions: IHttpConnectionOptions = options || {};
|
let actualOptions: IHttpConnectionOptions = options || {};
|
||||||
if (transportType) {
|
if (transportType) {
|
||||||
|
|
@ -599,7 +589,7 @@ describe("hubConnection", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
it("preserves cookies between requests", async (done) => {
|
it("preserves cookies between requests", async (done) => {
|
||||||
const hubConnection = getConnectionBuilder(transportType).build();
|
const hubConnection = getConnectionBuilder(transportType, HTTPORHTTPS_TESTHUBENDPOINT_URL).build();
|
||||||
await hubConnection.start();
|
await hubConnection.start();
|
||||||
const cookieValue = await hubConnection.invoke<string>("GetCookie", "testCookie");
|
const cookieValue = await hubConnection.invoke<string>("GetCookie", "testCookie");
|
||||||
const cookieValue2 = await hubConnection.invoke<string>("GetCookie", "testCookie2");
|
const cookieValue2 = await hubConnection.invoke<string>("GetCookie", "testCookie2");
|
||||||
|
|
@ -610,7 +600,7 @@ describe("hubConnection", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("expired cookies are not preserved", async (done) => {
|
it("expired cookies are not preserved", async (done) => {
|
||||||
const hubConnection = getConnectionBuilder(transportType).build();
|
const hubConnection = getConnectionBuilder(transportType, HTTPORHTTPS_TESTHUBENDPOINT_URL).build();
|
||||||
await hubConnection.start();
|
await hubConnection.start();
|
||||||
const cookieValue = await hubConnection.invoke<string>("GetCookie", "expiredCookie");
|
const cookieValue = await hubConnection.invoke<string>("GetCookie", "expiredCookie");
|
||||||
expect(cookieValue).toBeNull();
|
expect(cookieValue).toBeNull();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue