diff --git a/eng/Versions.props b/eng/Versions.props index 7e03a6be800b..d306e8b29253 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -8,8 +8,8 @@ 5 0 - 14 - true + 15 + false diff --git a/src/Security/Authentication/test/CertificateTests.cs b/src/Security/Authentication/test/CertificateTests.cs index e924fabe5de2..789487179255 100644 --- a/src/Security/Authentication/test/CertificateTests.cs +++ b/src/Security/Authentication/test/CertificateTests.cs @@ -306,7 +306,7 @@ public async Task VerifyClientCertWithUntrustedRootAndTrustedChainEndsUpInForbid Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); } - [Fact] + [Fact(Skip = "https://github.com/dotnet/aspnetcore/issues/39669")] public async Task VerifyValidClientCertWithTrustedChainAuthenticates() { using var host = await CreateHost( diff --git a/src/SignalR/clients/ts/FunctionalTests/EchoConnectionHandler.cs b/src/SignalR/clients/ts/FunctionalTests/EchoConnectionHandler.cs index 8dbdfd28f883..646d328a5b6f 100644 --- a/src/SignalR/clients/ts/FunctionalTests/EchoConnectionHandler.cs +++ b/src/SignalR/clients/ts/FunctionalTests/EchoConnectionHandler.cs @@ -4,7 +4,6 @@ using System.Buffers; using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; -using Microsoft.AspNetCore.Http.Connections; namespace FunctionalTests { @@ -12,13 +11,6 @@ public class EchoConnectionHandler : ConnectionHandler { public async override Task OnConnectedAsync(ConnectionContext connection) { - var context = connection.GetHttpContext(); - // The 'withCredentials' tests wont send a cookie for cross-site requests - if (!context.WebSockets.IsWebSocketRequest && !context.Request.Cookies.ContainsKey("testCookie")) - { - return; - } - while (true) { var result = await connection.Transport.Input.ReadAsync(); diff --git a/src/SignalR/clients/ts/FunctionalTests/ts/ConnectionTests.ts b/src/SignalR/clients/ts/FunctionalTests/ts/ConnectionTests.ts index b377c98112c6..8209d66a43b6 100644 --- a/src/SignalR/clients/ts/FunctionalTests/ts/ConnectionTests.ts +++ b/src/SignalR/clients/ts/FunctionalTests/ts/ConnectionTests.ts @@ -176,8 +176,8 @@ describe("connection", () => { withCredentials: false, }); - connection.onreceive = (data: any) => { - fail(new Error(`Unexpected messaged received '${data}'.`)); + connection.onreceive = (_: any) => { + connection.stop(); }; // @ts-ignore: We don't use the error parameter intentionally. diff --git a/src/SignalR/clients/ts/FunctionalTests/ts/HubConnectionTests.ts b/src/SignalR/clients/ts/FunctionalTests/ts/HubConnectionTests.ts index e15b576fae94..aea8004a72b5 100644 --- a/src/SignalR/clients/ts/FunctionalTests/ts/HubConnectionTests.ts +++ b/src/SignalR/clients/ts/FunctionalTests/ts/HubConnectionTests.ts @@ -43,16 +43,17 @@ function getConnectionBuilder(transportType?: HttpTransportType, url?: string, o describe("hubConnection", () => { eachTransportAndProtocolAndHttpClient((transportType, protocol, httpClient) => { describe("using " + protocol.name + " over " + HttpTransportType[transportType] + " transport", () => { - it("can invoke server method and receive result", async (done) => { + it("can invoke server method and receive result", async () => { const message = "你好,世界!"; const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); + const closePromise = new PromiseSource(); hubConnection.onclose((error) => { expect(error).toBeUndefined(); - done(); + closePromise.resolve(); }); await hubConnection.start(); @@ -60,20 +61,21 @@ describe("hubConnection", () => { expect(result).toBe(message); await hubConnection.stop(); - done(); + await closePromise; }); if (shouldRunHttpsTests) { - it("using https, can invoke server method and receive result", async (done) => { + it("using https, can invoke server method and receive result", async () => { const message = "你好,世界!"; const hubConnection = getConnectionBuilder(transportType, TESTHUBENDPOINT_HTTPS_URL, { httpClient }) .withHubProtocol(protocol) .build(); + const closePromise = new PromiseSource(); hubConnection.onclose((error) => { expect(error).toBeUndefined(); - done(); + closePromise.resolve(); }); await hubConnection.start(); @@ -81,30 +83,31 @@ describe("hubConnection", () => { expect(result).toBe(message); await hubConnection.stop(); - done(); + await closePromise; }); } - it("can invoke server method non-blocking and not receive result", async (done) => { + it("can invoke server method non-blocking and not receive result", async () => { const message = "你好,世界!"; const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); + const closePromise = new PromiseSource(); hubConnection.onclose((error) => { expect(error).toBe(undefined); - done(); + closePromise.resolve(); }); await hubConnection.start(); await hubConnection.send("Echo", message); await hubConnection.stop(); - done(); + await closePromise; }); - it("can invoke server method structural object and receive structural result", async (done) => { + it("can invoke server method structural object and receive structural result", async () => { const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); @@ -115,23 +118,26 @@ describe("hubConnection", () => { hubConnection.stop(); }); + const closePromise = new PromiseSource(); hubConnection.onclose((error) => { expect(error).toBe(undefined); - done(); + closePromise.resolve(); }); await hubConnection.start(); await hubConnection.send("SendCustomObject", { Name: "test", Value: 42 }); + await closePromise; }); - it("can stream server method and receive result", async (done) => { + it("can stream server method and receive result", async () => { const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); + const closePromise = new PromiseSource(); hubConnection.onclose((error) => { expect(error).toBe(undefined); - done(); + closePromise.resolve(); }); const received: string[] = []; @@ -149,16 +155,18 @@ describe("hubConnection", () => { received.push(item); }, }); + await closePromise; }); - it("can stream server method and cancel stream", async (done) => { + it("can stream server method and cancel stream", async () => { const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); + const closePromise = new PromiseSource(); hubConnection.onclose((error) => { expect(error).toBe(undefined); - done(); + closePromise.resolve(); }); hubConnection.on("StreamCanceled", async () => { @@ -178,9 +186,10 @@ describe("hubConnection", () => { }); subscription.dispose(); + await closePromise; }); - it("rethrows an exception from the server when invoking", async (done) => { + it("rethrows an exception from the server when invoking", async () => { const errorMessage = "An unexpected error occurred invoking 'ThrowException' on the server. InvalidOperationException: An error occurred."; const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) @@ -196,10 +205,9 @@ describe("hubConnection", () => { } await hubConnection.stop(); - done(); }); - it("throws an exception when invoking streaming method with invoke", async (done) => { + it("throws an exception when invoking streaming method with invoke", async () => { const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); @@ -215,10 +223,9 @@ describe("hubConnection", () => { } await hubConnection.stop(); - done(); }); - it("throws an exception when receiving a streaming result for method called with invoke", async (done) => { + it("throws an exception when receiving a streaming result for method called with invoke", async () => { const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); @@ -234,15 +241,15 @@ describe("hubConnection", () => { } await hubConnection.stop(); - done(); }); - it("rethrows an exception from the server when streaming", async (done) => { + it("rethrows an exception from the server when streaming", async () => { const errorMessage = "An unexpected error occurred invoking 'StreamThrowException' on the server. InvalidOperationException: An error occurred."; const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); + const closePromise = new PromiseSource(); await hubConnection.start(); hubConnection.stream("StreamThrowException", "An error occurred.").subscribe({ async complete() { @@ -252,20 +259,22 @@ describe("hubConnection", () => { async error(err) { expect(err.message).toEqual(errorMessage); await hubConnection.stop(); - done(); + closePromise.resolve(); }, async next() { await hubConnection.stop(); fail(); }, }); + await closePromise; }); - it("throws an exception when invoking hub method with stream", async (done) => { + it("throws an exception when invoking hub method with stream", async () => { const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); + const closePromise = new PromiseSource(); await hubConnection.start(); hubConnection.stream("Echo", "42").subscribe({ async complete() { @@ -275,16 +284,18 @@ describe("hubConnection", () => { async error(err) { expect(err.message).toEqual("The client attempted to invoke the non-streaming 'Echo' method with a streaming invocation."); await hubConnection.stop(); - done(); + closePromise.resolve(); }, async next() { await hubConnection.stop(); fail(); }, }); + + await closePromise; }); - it("can receive server calls", async (done) => { + it("can receive server calls", async () => { const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); @@ -308,10 +319,9 @@ describe("hubConnection", () => { expect(receiveMsg).toBe(message); await hubConnection.stop(); - done(); }); - it("can receive server calls without rebinding handler when restarted", async (done) => { + it("can receive server calls without rebinding handler when restarted", async () => { const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); @@ -326,6 +336,7 @@ describe("hubConnection", () => { let closeCount = 0; let invocationCount = 0; + const closePromise = new PromiseSource(); hubConnection.onclose(async (e) => { expect(e).toBeUndefined(); closeCount += 1; @@ -336,7 +347,7 @@ describe("hubConnection", () => { await hubConnection.stop(); } else { expect(invocationCount).toBe(2); - done(); + closePromise.resolve(); } }); @@ -348,37 +359,41 @@ describe("hubConnection", () => { await hubConnection.start(); await hubConnection.invoke("InvokeWithString", message); await hubConnection.stop(); + await closePromise; }); - it("closed with error or start fails if hub cannot be created", async (done) => { + it("closed with error or start fails if hub cannot be created", async () => { const hubConnection = getConnectionBuilder(transportType, ENDPOINT_BASE_URL + "/uncreatable", { httpClient }) .withHubProtocol(protocol) .build(); const expectedErrorMessage = "Server returned an error on close: Connection closed with an error. InvalidOperationException: Unable to resolve service for type 'System.Object' while attempting to activate 'FunctionalTests.UncreatableHub'."; + const closePromise = new PromiseSource(); // Either start will fail or onclose will be called. Never both. hubConnection.onclose((error) => { expect(error!.message).toEqual(expectedErrorMessage); - done(); + closePromise.resolve(); }); try { await hubConnection.start(); } catch (error) { expect(error!.message).toEqual(expectedErrorMessage); - done(); + closePromise.resolve(); } + await closePromise; }); - it("can handle different types", async (done) => { + it("can handle different types", async () => { const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); + const closePromise = new PromiseSource(); hubConnection.onclose((error) => { expect(error).toBe(undefined); - done(); + closePromise.resolve(); }); const complexObject = { @@ -403,16 +418,18 @@ describe("hubConnection", () => { expect(value).toEqual(complexObject); await hubConnection.stop(); + await closePromise; }); - it("can receive different types", async (done) => { + it("can receive different types", async () => { const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); + const closePromise = new PromiseSource(); hubConnection.onclose((error) => { expect(error).toBe(undefined); - done(); + closePromise.resolve(); }); const complexObject = { @@ -437,9 +454,10 @@ describe("hubConnection", () => { expect(value).toEqual(complexObject); await hubConnection.stop(); + await closePromise; }); - it("can be restarted", async (done) => { + it("can be restarted", async () => { const message = "你好,世界!"; const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) @@ -447,6 +465,7 @@ describe("hubConnection", () => { .build(); let closeCount = 0; + const closePromise = new PromiseSource(); hubConnection.onclose(async (error) => { expect(error).toBe(undefined); @@ -458,7 +477,7 @@ describe("hubConnection", () => { expect(value).toBe(message); await hubConnection.stop(); } else { - done(); + closePromise.resolve(); } }); @@ -467,9 +486,10 @@ describe("hubConnection", () => { expect(result).toBe(message); await hubConnection.stop(); + await closePromise; }); - it("can stream from client to server with rxjs", async (done) => { + it("can stream from client to server with rxjs", async () => { const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); @@ -483,10 +503,9 @@ describe("hubConnection", () => { subject.complete(); expect(await resultPromise).toBe("Hello world!"); await hubConnection.stop(); - done(); }); - it("can stream from client to server and close with error with rxjs", async (done) => { + it("can stream from client to server and close with error with rxjs", async () => { const hubConnection = getConnectionBuilder(transportType, undefined, { httpClient }) .withHubProtocol(protocol) .build(); @@ -506,7 +525,6 @@ describe("hubConnection", () => { } finally { await hubConnection.stop(); } - done(); }); }); }); @@ -514,7 +532,7 @@ describe("hubConnection", () => { eachTransport((transportType) => { describe("over " + HttpTransportType[transportType] + " transport", () => { - it("can connect to hub with authorization", async (done) => { + it("can connect to hub with authorization", async () => { const message = "你好,世界!"; try { @@ -524,9 +542,10 @@ describe("hubConnection", () => { accessTokenFactory: () => jwtToken, }).build(); + const closePromise = new PromiseSource(); hubConnection.onclose((error) => { expect(error).toBe(undefined); - done(); + closePromise.resolve(); }); await hubConnection.start(); const response = await hubConnection.invoke("Echo", message); @@ -535,14 +554,13 @@ describe("hubConnection", () => { await hubConnection.stop(); - done(); + await closePromise; } catch (err) { fail(err); - done(); } }); - it("can connect to hub with authorization using async token factory", async (done) => { + it("can connect to hub with authorization using async token factory", async () => { const message = "你好,世界!"; try { @@ -550,9 +568,10 @@ describe("hubConnection", () => { accessTokenFactory: () => getJwtToken(ENDPOINT_BASE_URL + "/generateJwtToken"), }).build(); + const closePromise = new PromiseSource(); hubConnection.onclose((error) => { expect(error).toBe(undefined); - done(); + closePromise.resolve(); }); await hubConnection.start(); const response = await hubConnection.invoke("Echo", message); @@ -561,20 +580,20 @@ describe("hubConnection", () => { await hubConnection.stop(); - done(); + await closePromise; } catch (err) { fail(err); - done(); } }); if (transportType !== HttpTransportType.LongPolling) { - it("terminates if no messages received within timeout interval", async (done) => { + it("terminates if no messages received within timeout interval", async () => { const hubConnection = getConnectionBuilder(transportType).build(); + const closePromise = new PromiseSource(); hubConnection.onclose((error) => { expect(error).toEqual(new Error("Server timeout elapsed without receiving a message from the server.")); - done(); + closePromise.resolve(); }); await hubConnection.start(); @@ -584,30 +603,31 @@ describe("hubConnection", () => { // invoke a method with a response to reset the timeout using the new value await hubConnection.invoke("Echo", ""); + await closePromise; }); } - it("preserves cookies between requests", async (done) => { - const hubConnection = getConnectionBuilder(transportType, HTTPORHTTPS_TESTHUBENDPOINT_URL).build(); - await hubConnection.start(); - const cookieValue = await hubConnection.invoke("GetCookie", "testCookie"); - const cookieValue2 = await hubConnection.invoke("GetCookie", "testCookie2"); - expect(cookieValue).toEqual("testValue"); - expect(cookieValue2).toEqual("testValue2"); - await hubConnection.stop(); - done(); - }); + if (shouldRunHttpsTests) { + it("preserves cookies between requests", async () => { + const hubConnection = getConnectionBuilder(transportType, HTTPORHTTPS_TESTHUBENDPOINT_URL).build(); + await hubConnection.start(); + const cookieValue = await hubConnection.invoke("GetCookie", "testCookie"); + const cookieValue2 = await hubConnection.invoke("GetCookie", "testCookie2"); + expect(cookieValue).toEqual("testValue"); + expect(cookieValue2).toEqual("testValue2"); + await hubConnection.stop(); + }); + } - it("expired cookies are not preserved", async (done) => { + it("expired cookies are not preserved", async () => { const hubConnection = getConnectionBuilder(transportType, HTTPORHTTPS_TESTHUBENDPOINT_URL).build(); await hubConnection.start(); const cookieValue = await hubConnection.invoke("GetCookie", "expiredCookie"); expect(cookieValue).toBeNull(); await hubConnection.stop(); - done(); }); - it("can reconnect", async (done) => { + it("can reconnect", async () => { try { const reconnectingPromise = new PromiseSource(); const reconnectedPromise = new PromiseSource(); @@ -640,16 +660,13 @@ describe("hubConnection", () => { expect(response).toEqual("test"); await hubConnection.stop(); - - done(); } catch (err) { fail(err); - done(); } }); }); - it("can change url in reconnecting state", async (done) => { + it("can change url in reconnecting state", async () => { try { const reconnectingPromise = new PromiseSource(); const hubConnection = getConnectionBuilder(transportType) @@ -671,16 +688,13 @@ describe("hubConnection", () => { expect(hubConnection.baseUrl).toBe("http://example123.com"); await hubConnection.stop(); - - done(); } catch (err) { fail(err); - done(); } }); }); - it("can reconnect after negotiate redirect", async (done) => { + it("can reconnect after negotiate redirect", async () => { try { const reconnectingPromise = new PromiseSource(); const reconnectedPromise = new PromiseSource(); @@ -718,15 +732,12 @@ describe("hubConnection", () => { expect(postReconnectRedirects).toBeGreaterThan(preReconnectRedirects); await hubConnection.stop(); - - done(); } catch (err) { fail(err); - done(); } }); - it("can reconnect after skipping negotiation", async (done) => { + it("can reconnect after skipping negotiation", async () => { try { const reconnectingPromise = new PromiseSource(); const reconnectedPromise = new PromiseSource(); @@ -761,15 +772,12 @@ describe("hubConnection", () => { expect(response).toEqual("test"); await hubConnection.stop(); - - done(); } catch (err) { fail(err); - done(); } }); - it("connection id matches server side connection id", async (done) => { + it("connection id matches server side connection id", async () => { try { const reconnectingPromise = new PromiseSource(); const reconnectedPromise = new PromiseSource(); @@ -808,15 +816,12 @@ describe("hubConnection", () => { await hubConnection.stop(); expect(hubConnection.connectionId).toBeNull(); - - done(); } catch (err) { fail(err); - done(); } }); - it("connection id is alwys null is negotiation is skipped", async (done) => { + it("connection id is alwys null is negotiation is skipped", async () => { try { const hubConnection = getConnectionBuilder( HttpTransportType.WebSockets, @@ -834,16 +839,13 @@ describe("hubConnection", () => { await hubConnection.stop(); expect(hubConnection.connectionId).toBeNull(); - - done(); } catch (err) { fail(err); - done(); } }); if (typeof EventSource !== "undefined") { - it("allows Server-Sent Events when negotiating for JSON protocol", async (done) => { + it("allows Server-Sent Events when negotiating for JSON protocol", async () => { const hubConnection = getConnectionBuilder(undefined, TESTHUB_NOWEBSOCKETS_ENDPOINT_URL) .withHubProtocol(new JsonHubProtocol()) .build(); @@ -855,14 +857,13 @@ describe("hubConnection", () => { expect(await hubConnection.invoke("GetActiveTransportName")).toEqual("ServerSentEvents"); await hubConnection.stop(); - done(); } catch (e) { fail(e); } }); } - it("skips Server-Sent Events when negotiating for MessagePack protocol", async (done) => { + it("skips Server-Sent Events when negotiating for MessagePack protocol", async () => { const hubConnection = getConnectionBuilder(undefined, TESTHUB_NOWEBSOCKETS_ENDPOINT_URL) .withHubProtocol(new MessagePackHubProtocol()) .build(); @@ -874,16 +875,14 @@ describe("hubConnection", () => { expect(await hubConnection.invoke("GetActiveTransportName")).toEqual("LongPolling"); await hubConnection.stop(); - done(); } catch (e) { fail(e); } }); - it("transport falls back from WebSockets to SSE or LongPolling", async (done) => { + it("transport falls back from WebSockets to SSE or LongPolling", async () => { // Skip test on Node as there will always be a WebSockets implementation on Node if (typeof window === "undefined") { - done(); return; } @@ -909,11 +908,10 @@ describe("hubConnection", () => { fail(e); } finally { (window as any).WebSocket = oldWebSocket; - done(); } }); - it("over LongPolling it sends DELETE request and waits for poll to terminate", async (done) => { + it("over LongPolling it sends DELETE request and waits for poll to terminate", async () => { // Create an HTTP client to capture the poll const defaultClient = new DefaultHttpClient(TestLogger.instance); @@ -961,14 +959,12 @@ describe("hubConnection", () => { } catch (e) { fail(e); } finally { - done(); } }); - it("populates the Content-Type header when sending XMLHttpRequest", async (done) => { + it("populates the Content-Type header when sending XMLHttpRequest", async () => { // Skip test on Node as this header isn't set (it was added for React-Native) if (typeof window === "undefined") { - done(); return; } const hubConnection = getConnectionBuilder(HttpTransportType.LongPolling, TESTHUB_NOWEBSOCKETS_ENDPOINT_URL) @@ -984,14 +980,13 @@ describe("hubConnection", () => { expect(await hubConnection.invoke("GetContentTypeHeader")).toEqual("text/plain;charset=UTF-8"); await hubConnection.stop(); - done(); } catch (e) { fail(e); } }); eachTransport((t) => { - it("sets the user agent header", async (done) => { + it("sets the user agent header", async () => { const hubConnection = getConnectionBuilder(t, TESTHUBENDPOINT_URL) .withHubProtocol(new JsonHubProtocol()) .build(); @@ -1010,13 +1005,12 @@ describe("hubConnection", () => { } await hubConnection.stop(); - done(); } catch (e) { fail(e); } }); - it("overwrites library headers with user headers", async (done) => { + it("overwrites library headers with user headers", async () => { const [name] = getUserAgentHeader(); const headers = { [name]: "Custom Agent", "X-HEADER": "VALUE" }; const hubConnection = getConnectionBuilder(t, TESTHUBENDPOINT_URL, { headers }) @@ -1038,7 +1032,6 @@ describe("hubConnection", () => { } await hubConnection.stop(); - done(); } catch (e) { fail(e); }