diff --git a/src/Analyzers/Analyzers/src/StartupFacts.cs b/src/Analyzers/Analyzers/src/StartupFacts.cs index 221e3ff4c4d3709858a0d73e463e984c02d9cf0b..f5f833429a6936b01c49d3740196b0b1f1b99ad5 100644 --- a/src/Analyzers/Analyzers/src/StartupFacts.cs +++ b/src/Analyzers/Analyzers/src/StartupFacts.cs @@ -138,6 +138,8 @@ namespace Microsoft.AspNetCore.Analyzers throw new ArgumentNullException(nameof(symbol)); } + // UseSignalR has been removed in 5.0, but we should probably still check for it in this analyzer in case the user + // installs it into a pre-5.0 app. if (string.Equals(symbol.Name, SymbolNames.SignalRAppBuilderExtensions.UseSignalRMethodName, StringComparison.Ordinal) || string.Equals(symbol.Name, SymbolNames.HubEndpointRouteBuilderExtensions.MapHubMethodName, StringComparison.Ordinal) || string.Equals(symbol.Name, SymbolNames.ComponentEndpointRouteBuilderExtensions.MapBlazorHubMethodName, StringComparison.Ordinal)) diff --git a/src/Analyzers/Analyzers/test/CompilationFeatureDetectorTest.cs b/src/Analyzers/Analyzers/test/CompilationFeatureDetectorTest.cs index 0669c7646462de5a4d4c9862310a0c8f0480a722..9fcc0ff16750dc1bdae52f1a29ae463374c90c12 100644 --- a/src/Analyzers/Analyzers/test/CompilationFeatureDetectorTest.cs +++ b/src/Analyzers/Analyzers/test/CompilationFeatureDetectorTest.cs @@ -29,7 +29,6 @@ namespace Microsoft.AspNetCore.Analyzers } [Theory] - [InlineData(nameof(StartupWithUseSignalR))] [InlineData(nameof(StartupWithMapHub))] [InlineData(nameof(StartupWithMapBlazorHub))] public async Task DetectFeaturesAsync_FindsSignalR(string source) diff --git a/src/Analyzers/Analyzers/test/TestFiles/CompilationFeatureDetectorTest/StartupWithUseSignalR.cs b/src/Analyzers/Analyzers/test/TestFiles/CompilationFeatureDetectorTest/StartupWithUseSignalR.cs deleted file mode 100644 index aa65f832580ac5886dce361ddfac1cce9169cd75..0000000000000000000000000000000000000000 --- a/src/Analyzers/Analyzers/test/TestFiles/CompilationFeatureDetectorTest/StartupWithUseSignalR.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Builder; - -namespace Microsoft.AspNetCore.Analyzers.TestFiles.CompilationFeatureDetectorTest -{ - public class StartupWithUseSignalR - { - public void Configure(IApplicationBuilder app) - { -#pragma warning disable CS0618 // Type or member is obsolete - app.UseSignalR(routes => - { - - }); -#pragma warning restore CS0618 // Type or member is obsolete - } - } -} diff --git a/src/SignalR/common/Http.Connections/ref/Microsoft.AspNetCore.Http.Connections.netcoreapp.cs b/src/SignalR/common/Http.Connections/ref/Microsoft.AspNetCore.Http.Connections.netcoreapp.cs index 9f70e9da9c1f35f6a65835b4481db8cfcc2f6307..130b8a4a42d691fdcdbbadef780dfe5b18153cbd 100644 --- a/src/SignalR/common/Http.Connections/ref/Microsoft.AspNetCore.Http.Connections.netcoreapp.cs +++ b/src/SignalR/common/Http.Connections/ref/Microsoft.AspNetCore.Http.Connections.netcoreapp.cs @@ -15,11 +15,6 @@ namespace Microsoft.AspNetCore.Builder public static Microsoft.AspNetCore.Builder.ConnectionEndpointRouteBuilder MapConnections(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions options, System.Action<Microsoft.AspNetCore.Connections.IConnectionBuilder> configure) { throw null; } public static Microsoft.AspNetCore.Builder.ConnectionEndpointRouteBuilder MapConnections(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, System.Action<Microsoft.AspNetCore.Connections.IConnectionBuilder> configure) { throw null; } } - public static partial class ConnectionsAppBuilderExtensions - { - [System.ObsoleteAttribute("This method is obsolete and will be removed in a future version. The recommended alternative is to use MapConnections or MapConnectionHandler<TConnectionHandler> inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public static Microsoft.AspNetCore.Builder.IApplicationBuilder UseConnections(this Microsoft.AspNetCore.Builder.IApplicationBuilder app, System.Action<Microsoft.AspNetCore.Http.Connections.ConnectionsRouteBuilder> configure) { throw null; } - } } namespace Microsoft.AspNetCore.Http.Connections { @@ -34,15 +29,6 @@ namespace Microsoft.AspNetCore.Http.Connections public ConnectionOptionsSetup() { } public void Configure(Microsoft.AspNetCore.Http.Connections.ConnectionOptions options) { } } - [System.ObsoleteAttribute("This class is obsolete and will be removed in a future version. The recommended alternative is to use MapConnection and MapConnectionHandler<TConnectionHandler> inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public partial class ConnectionsRouteBuilder - { - internal ConnectionsRouteBuilder() { } - public void MapConnectionHandler<TConnectionHandler>(Microsoft.AspNetCore.Http.PathString path) where TConnectionHandler : Microsoft.AspNetCore.Connections.ConnectionHandler { } - public void MapConnectionHandler<TConnectionHandler>(Microsoft.AspNetCore.Http.PathString path, System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions> configureOptions) where TConnectionHandler : Microsoft.AspNetCore.Connections.ConnectionHandler { } - public void MapConnections(Microsoft.AspNetCore.Http.PathString path, Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions options, System.Action<Microsoft.AspNetCore.Connections.IConnectionBuilder> configure) { } - public void MapConnections(Microsoft.AspNetCore.Http.PathString path, System.Action<Microsoft.AspNetCore.Connections.IConnectionBuilder> configure) { } - } public static partial class HttpConnectionContextExtensions { public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.Connections.ConnectionContext connection) { throw null; } diff --git a/src/SignalR/common/Http.Connections/src/ConnectionsAppBuilderExtensions.cs b/src/SignalR/common/Http.Connections/src/ConnectionsAppBuilderExtensions.cs deleted file mode 100644 index 05227d6f39636445cff579f490a78665ef42d5cd..0000000000000000000000000000000000000000 --- a/src/SignalR/common/Http.Connections/src/ConnectionsAppBuilderExtensions.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.Http.Connections; - -namespace Microsoft.AspNetCore.Builder -{ - /// <summary> - /// Extension methods for <see cref="IApplicationBuilder"/>. - /// </summary> - public static class ConnectionsAppBuilderExtensions - { - /// <summary> - /// Adds support for ASP.NET Core Connection Handlers to the <see cref="IApplicationBuilder"/> request execution pipeline. - /// <para> - /// This method is obsolete and will be removed in a future version. - /// The recommended alternative is to use MapConnections or MapConnectionHandler<TConnectionHandler> inside Microsoft.AspNetCore.Builder.UseEndpoints(...). - /// </para> - /// </summary> - /// <param name="app">The <see cref="IApplicationBuilder"/>.</param> - /// <param name="configure">A callback to configure connection routes.</param> - /// <returns>The same instance of the <see cref="IApplicationBuilder"/> for chaining.</returns> - [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to use MapConnections or MapConnectionHandler<TConnectionHandler> inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public static IApplicationBuilder UseConnections(this IApplicationBuilder app, Action<ConnectionsRouteBuilder> configure) - { - if (configure == null) - { - throw new ArgumentNullException(nameof(configure)); - } - - app.UseWebSockets(); - app.UseRouting(); - app.UseAuthorization(); - app.UseEndpoints(endpoints => - { - configure(new ConnectionsRouteBuilder(endpoints)); - }); - return app; - } - } -} diff --git a/src/SignalR/common/Http.Connections/src/ConnectionsRouteBuilder.cs b/src/SignalR/common/Http.Connections/src/ConnectionsRouteBuilder.cs deleted file mode 100644 index b76d5688f06537eff5338b23b98ad14a942dd092..0000000000000000000000000000000000000000 --- a/src/SignalR/common/Http.Connections/src/ConnectionsRouteBuilder.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Connections; -using Microsoft.AspNetCore.Routing; - -namespace Microsoft.AspNetCore.Http.Connections -{ - /// <summary> - /// Maps routes to ASP.NET Core Connection Handlers. - /// <para> - /// This class is obsolete and will be removed in a future version. - /// The recommended alternative is to use MapConnection and MapConnectionHandler<TConnectionHandler> inside Microsoft.AspNetCore.Builder.UseEndpoints(...). - /// </para> - /// </summary> - [Obsolete("This class is obsolete and will be removed in a future version. The recommended alternative is to use MapConnection and MapConnectionHandler<TConnectionHandler> inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public class ConnectionsRouteBuilder - { - private readonly IEndpointRouteBuilder _endpoints; - - internal ConnectionsRouteBuilder(IEndpointRouteBuilder endpoints) - { - _endpoints = endpoints; - } - - /// <summary> - /// Maps incoming requests with the specified path to the provided connection pipeline. - /// </summary> - /// <param name="path">The request path.</param> - /// <param name="configure">A callback to configure the connection.</param> - public void MapConnections(PathString path, Action<IConnectionBuilder> configure) => - MapConnections(path, new HttpConnectionDispatcherOptions(), configure); - - /// <summary> - /// Maps incoming requests with the specified path to the provided connection pipeline. - /// </summary> - /// <param name="path">The request path.</param> - /// <param name="options">Options used to configure the connection.</param> - /// <param name="configure">A callback to configure the connection.</param> - public void MapConnections(PathString path, HttpConnectionDispatcherOptions options, Action<IConnectionBuilder> configure) => - _endpoints.MapConnections(path, options, configure); - - /// <summary> - /// Maps incoming requests with the specified path to the provided connection pipeline. - /// </summary> - /// <typeparam name="TConnectionHandler">The <see cref="ConnectionHandler"/> type.</typeparam> - /// <param name="path">The request path.</param> - public void MapConnectionHandler<TConnectionHandler>(PathString path) where TConnectionHandler : ConnectionHandler => - MapConnectionHandler<TConnectionHandler>(path, configureOptions: null); - - /// <summary> - /// Maps incoming requests with the specified path to the provided connection pipeline. - /// </summary> - /// <typeparam name="TConnectionHandler">The <see cref="ConnectionHandler"/> type.</typeparam> - /// <param name="path">The request path.</param> - /// <param name="configureOptions">A callback to configure dispatcher options.</param> - public void MapConnectionHandler<TConnectionHandler>(PathString path, Action<HttpConnectionDispatcherOptions> configureOptions) where TConnectionHandler : ConnectionHandler => - _endpoints.MapConnectionHandler<TConnectionHandler>(path, configureOptions); - } -} diff --git a/src/SignalR/common/Http.Connections/test/MapConnectionHandlerTests.cs b/src/SignalR/common/Http.Connections/test/MapConnectionHandlerTests.cs index 68e086c560c2f74e005eb2731c23410cfea08ce4..d603c0d0830ce6edcc8ef70ed70ace5b53adf17b 100644 --- a/src/SignalR/common/Http.Connections/test/MapConnectionHandlerTests.cs +++ b/src/SignalR/common/Http.Connections/test/MapConnectionHandlerTests.cs @@ -150,10 +150,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests public void MapConnectionHandlerEndPointRoutingFindsAttributesOnHub() { var authCount = 0; - using (var host = BuildWebHostWithEndPointRouting(routes => routes.MapConnectionHandler<AuthConnectionHandler>("/path", options => + using (var host = BuildWebHost<AuthConnectionHandler>("/path", options => { authCount += options.AuthorizationData.Count; - }))) + })) { host.Start(); @@ -179,11 +179,11 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests public void MapConnectionHandlerEndPointRoutingFindsAttributesFromOptions() { var authCount = 0; - using (var host = BuildWebHostWithEndPointRouting(routes => routes.MapConnectionHandler<AuthConnectionHandler>("/path", options => + using (var host = BuildWebHost<AuthConnectionHandler>("/path", options => { authCount += options.AuthorizationData.Count; options.AuthorizationData.Add(new AuthorizeAttribute()); - }))) + })) { host.Start(); @@ -215,7 +215,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests .RequireAuthorization(new AuthorizeAttribute("Foo")); } - using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes)) + using (var host = BuildWebHost(ConfigureRoutes)) { host.Start(); @@ -253,7 +253,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests endpoints.MapConnectionHandler<AuthConnectionHandler>("/path"); } - using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes)) + using (var host = BuildWebHost(ConfigureRoutes)) { host.Start(); @@ -281,7 +281,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests endpoints.MapConnectionHandler<CorsConnectionHandler>("/path"); } - using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes)) + using (var host = BuildWebHost(ConfigureRoutes)) { host.Start(); @@ -308,7 +308,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests var host = BuildWebHost<MyConnectionHandler>("/socket", options => options.WebSockets.SubProtocolSelector = subprotocols => { - Assert.Equal(new [] { "protocol1", "protocol2" }, subprotocols.ToArray()); + Assert.Equal(new[] { "protocol1", "protocol2" }, subprotocols.ToArray()); return "protocol1"; }); @@ -377,7 +377,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests } } - private IWebHost BuildWebHostWithEndPointRouting(Action<IEndpointRouteBuilder> configure) + private IWebHost BuildWebHost(Action<IEndpointRouteBuilder> configure) { return new WebHostBuilder() .UseKestrel() @@ -405,12 +405,11 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests }) .Configure(app => { -#pragma warning disable CS0618 // Type or member is obsolete - app.UseConnections(routes => + app.UseRouting(); + app.UseEndpoints(routes => { routes.MapConnectionHandler<TConnectionHandler>(path, configureOptions); }); -#pragma warning restore CS0618 // Type or member is obsolete }) .ConfigureLogging(factory => { diff --git a/src/SignalR/server/SignalR/ref/Microsoft.AspNetCore.SignalR.netcoreapp.cs b/src/SignalR/server/SignalR/ref/Microsoft.AspNetCore.SignalR.netcoreapp.cs index 0021c03cbd8c9a2da0fe8d78f26ea210ef4b3eeb..de595a611b0d8ef6daa1d2f127e48a34f4d407e5 100644 --- a/src/SignalR/server/SignalR/ref/Microsoft.AspNetCore.SignalR.netcoreapp.cs +++ b/src/SignalR/server/SignalR/ref/Microsoft.AspNetCore.SignalR.netcoreapp.cs @@ -16,11 +16,6 @@ namespace Microsoft.AspNetCore.Builder public partial interface IHubEndpointConventionBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder { } - public static partial class SignalRAppBuilderExtensions - { - [System.ObsoleteAttribute("This method is obsolete and will be removed in a future version. The recommended alternative is to use MapHub<THub> inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public static Microsoft.AspNetCore.Builder.IApplicationBuilder UseSignalR(this Microsoft.AspNetCore.Builder.IApplicationBuilder app, System.Action<Microsoft.AspNetCore.SignalR.HubRouteBuilder> configure) { throw null; } - } } namespace Microsoft.AspNetCore.SignalR { @@ -29,13 +24,6 @@ namespace Microsoft.AspNetCore.SignalR public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.SignalR.HubCallerContext connection) { throw null; } public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.SignalR.HubConnectionContext connection) { throw null; } } - [System.ObsoleteAttribute("This class is obsolete and will be removed in a future version. The recommended alternative is to use MapHub<THub> inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public partial class HubRouteBuilder - { - public HubRouteBuilder(Microsoft.AspNetCore.Http.Connections.ConnectionsRouteBuilder routes) { } - public void MapHub<THub>(Microsoft.AspNetCore.Http.PathString path) where THub : Microsoft.AspNetCore.SignalR.Hub { } - public void MapHub<THub>(Microsoft.AspNetCore.Http.PathString path, System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions> configureOptions) where THub : Microsoft.AspNetCore.SignalR.Hub { } - } } namespace Microsoft.Extensions.DependencyInjection { diff --git a/src/SignalR/server/SignalR/src/HubRouteBuilder.cs b/src/SignalR/server/SignalR/src/HubRouteBuilder.cs deleted file mode 100644 index cf9f694bb35550c6641526411adfd7e8d9b1fb2a..0000000000000000000000000000000000000000 --- a/src/SignalR/server/SignalR/src/HubRouteBuilder.cs +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Reflection; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Connections; -using Microsoft.AspNetCore.Routing; - -namespace Microsoft.AspNetCore.SignalR -{ - /// <summary> - /// Maps incoming requests to <see cref="Hub"/> types. - /// <para> - /// This class is obsolete and will be removed in a future version. - /// The recommended alternative is to use MapHub<THub> inside Microsoft.AspNetCore.Builder.UseEndpoints(...). - /// </para> - /// </summary> - [Obsolete("This class is obsolete and will be removed in a future version. The recommended alternative is to use MapHub<THub> inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public class HubRouteBuilder - { - private readonly ConnectionsRouteBuilder _routes; - private readonly IEndpointRouteBuilder _endpoints; - - /// <summary> - /// Initializes a new instance of the <see cref="HubRouteBuilder"/> class. - /// </summary> - /// <param name="routes">The routes builder.</param> - public HubRouteBuilder(ConnectionsRouteBuilder routes) - { - _routes = routes; - } - - internal HubRouteBuilder(IEndpointRouteBuilder endpoints) - { - _endpoints = endpoints; - } - - /// <summary> - /// Maps incoming requests with the specified path to the specified <see cref="Hub"/> type. - /// </summary> - /// <typeparam name="THub">The <see cref="Hub"/> type to map requests to.</typeparam> - /// <param name="path">The request path.</param> - public void MapHub<THub>(PathString path) where THub : Hub - { - MapHub<THub>(path, configureOptions: null); - } - - /// <summary> - /// Maps incoming requests with the specified path to the specified <see cref="Hub"/> type. - /// </summary> - /// <typeparam name="THub">The <see cref="Hub"/> type to map requests to.</typeparam> - /// <param name="path">The request path.</param> - /// <param name="configureOptions">A callback to configure dispatcher options.</param> - public void MapHub<THub>(PathString path, Action<HttpConnectionDispatcherOptions> configureOptions) where THub : Hub - { - // This will be null if someone is manually using the HubRouteBuilder(ConnectionsRouteBuilder routes) constructor - // SignalR itself will only use the IEndpointRouteBuilder overload - if (_endpoints != null) - { - _endpoints.MapHub<THub>(path, configureOptions); - return; - } - - // find auth attributes - var authorizeAttributes = typeof(THub).GetCustomAttributes<AuthorizeAttribute>(inherit: true); - var options = new HttpConnectionDispatcherOptions(); - foreach (var attribute in authorizeAttributes) - { - options.AuthorizationData.Add(attribute); - } - configureOptions?.Invoke(options); - - _routes.MapConnections(path, options, builder => - { - builder.UseHub<THub>(); - }); - } - } -} diff --git a/src/SignalR/server/SignalR/src/SignalRAppBuilderExtensions.cs b/src/SignalR/server/SignalR/src/SignalRAppBuilderExtensions.cs deleted file mode 100644 index e01870193a52db20dcac4635bdf433c1716f7f65..0000000000000000000000000000000000000000 --- a/src/SignalR/server/SignalR/src/SignalRAppBuilderExtensions.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.SignalR; -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.AspNetCore.Builder -{ - /// <summary> - /// Extension methods for <see cref="IApplicationBuilder"/>. - /// </summary> - public static class SignalRAppBuilderExtensions - { - /// <summary> - /// Adds SignalR to the <see cref="IApplicationBuilder"/> request execution pipeline. - /// <para> - /// This method is obsolete and will be removed in a future version. - /// The recommended alternative is to use MapHub<THub> inside Microsoft.AspNetCore.Builder.UseEndpoints(...). - /// </para> - /// </summary> - /// <param name="app">The <see cref="IApplicationBuilder"/>.</param> - /// <param name="configure">A callback to configure hub routes.</param> - /// <returns>The same instance of the <see cref="IApplicationBuilder"/> for chaining.</returns> - [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to use MapHub<THub> inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public static IApplicationBuilder UseSignalR(this IApplicationBuilder app, Action<HubRouteBuilder> configure) - { - var marker = app.ApplicationServices.GetService<SignalRMarkerService>(); - if (marker == null) - { - throw new InvalidOperationException("Unable to find the required services. Please add all the required services by calling " + - "'IServiceCollection.AddSignalR' inside the call to 'ConfigureServices(...)' in the application startup code."); - } - - app.UseWebSockets(); - app.UseRouting(); - app.UseAuthorization(); - app.UseEndpoints(endpoints => - { - configure(new HubRouteBuilder(endpoints)); - }); - - return app; - } - } -} diff --git a/src/SignalR/server/SignalR/test/EndToEndTests.cs b/src/SignalR/server/SignalR/test/EndToEndTests.cs index e2b22a2d6e45c81b61fd1a1f8902222542a54047..c9f85fefbd116a839cc19465d10e07c000129c83 100644 --- a/src/SignalR/server/SignalR/test/EndToEndTests.cs +++ b/src/SignalR/server/SignalR/test/EndToEndTests.cs @@ -579,45 +579,6 @@ namespace Microsoft.AspNetCore.SignalR.Tests } } - [Fact] - [LogLevel(LogLevel.Trace)] - public async Task UnauthorizedHubConnectionDoesNotConnectWithEndpoints() - { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == typeof(HttpConnection).FullName && - writeContext.EventId.Name == "ErrorWithNegotiation"; - } - - using (var server = await StartServer<Startup>(ExpectedErrors)) - { - var logger = LoggerFactory.CreateLogger<EndToEndTests>(); - - var url = server.Url + "/authHubEndpoints"; - var connection = new HubConnectionBuilder() - .WithLoggerFactory(LoggerFactory) - .WithUrl(url, HttpTransportType.LongPolling) - .Build(); - - try - { - logger.LogInformation("Starting connection to {url}", url); - await connection.StartAsync().OrTimeout(); - Assert.True(false); - } - catch (Exception ex) - { - Assert.Equal("Response status code does not indicate success: 401 (Unauthorized).", ex.Message); - } - finally - { - logger.LogInformation("Disposing Connection"); - await connection.DisposeAsync().OrTimeout(); - logger.LogInformation("Disposed Connection"); - } - } - } - [Fact] [LogLevel(LogLevel.Trace)] public async Task UnauthorizedHubConnectionDoesNotConnect() @@ -657,53 +618,6 @@ namespace Microsoft.AspNetCore.SignalR.Tests } } - [Fact] - [LogLevel(LogLevel.Trace)] - public async Task AuthorizedHubConnectionCanConnectWithEndpoints() - { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == typeof(HttpConnection).FullName && - writeContext.EventId.Name == "ErrorWithNegotiation"; - } - - using (var server = await StartServer<Startup>(ExpectedErrors)) - { - var logger = LoggerFactory.CreateLogger<EndToEndTests>(); - - string token; - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(server.Url); - - var response = await client.GetAsync("generatetoken?user=bob"); - token = await response.Content.ReadAsStringAsync(); - } - - var url = server.Url + "/authHubEndpoints"; - var connection = new HubConnectionBuilder() - .WithLoggerFactory(LoggerFactory) - .WithUrl(url, HttpTransportType.LongPolling, o => - { - o.AccessTokenProvider = () => Task.FromResult(token); - }) - .Build(); - - try - { - logger.LogInformation("Starting connection to {url}", url); - await connection.StartAsync().OrTimeout(); - logger.LogInformation("Connected to {url}", url); - } - finally - { - logger.LogInformation("Disposing Connection"); - await connection.DisposeAsync().OrTimeout(); - logger.LogInformation("Disposed Connection"); - } - } - } - [Fact] [LogLevel(LogLevel.Trace)] public async Task AuthorizedHubConnectionCanConnect() diff --git a/src/SignalR/server/SignalR/test/MapSignalRTests.cs b/src/SignalR/server/SignalR/test/MapSignalRTests.cs index 01bc4d2e337039a9188780365283cff2c541fa2b..8f1a79dc4a22398581095d9f1479286e1f1fe23e 100644 --- a/src/SignalR/server/SignalR/test/MapSignalRTests.cs +++ b/src/SignalR/server/SignalR/test/MapSignalRTests.cs @@ -31,41 +31,6 @@ namespace Microsoft.AspNetCore.SignalR.Tests var executedConfigure = false; var builder = new WebHostBuilder(); - builder - .UseKestrel() - .Configure(app => - { - executedConfigure = true; - - var ex = Assert.Throws<InvalidOperationException>(() => - { -#pragma warning disable CS0618 // Type or member is obsolete - app.UseSignalR(routes => - { - routes.MapHub<AuthHub>("/overloads"); - }); -#pragma warning restore CS0618 // Type or member is obsolete - }); - - Assert.Equal("Unable to find the required services. Please add all the required services by calling " + - "'IServiceCollection.AddSignalR' inside the call to 'ConfigureServices(...)' in the application startup code.", ex.Message); - }) - .UseUrls("http://127.0.0.1:0"); - - using (var host = builder.Build()) - { - host.Start(); - } - - Assert.True(executedConfigure); - } - - [Fact] - public void NotAddingSignalRServiceThrowsWhenUsingEndpointRouting() - { - var executedConfigure = false; - var builder = new WebHostBuilder(); - builder .UseKestrel() .ConfigureServices(services => @@ -189,7 +154,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests public void MapHubEndPointRoutingFindsAttributesOnHub() { var authCount = 0; - using (var host = BuildWebHostWithEndPointRouting(routes => routes.MapHub<AuthHub>("/path", options => + using (var host = BuildWebHost(routes => routes.MapHub<AuthHub>("/path", options => { authCount += options.AuthorizationData.Count; }))) @@ -219,7 +184,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests { var authCount = 0; HttpConnectionDispatcherOptions configuredOptions = null; - using (var host = BuildWebHostWithEndPointRouting(routes => routes.MapHub<AuthHub>("/path", options => + using (var host = BuildWebHost(routes => routes.MapHub<AuthHub>("/path", options => { authCount += options.AuthorizationData.Count; options.AuthorizationData.Add(new AuthorizeAttribute()); @@ -256,7 +221,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests .RequireAuthorization(new AuthorizeAttribute("Foo")); } - using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes)) + using (var host = BuildWebHost(ConfigureRoutes)) { host.Start(); @@ -295,7 +260,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests endpoints.MapHub<AuthHub>("/path"); } - using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes)) + using (var host = BuildWebHost(ConfigureRoutes)) { host.Start(); @@ -320,9 +285,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public void MapHubAppliesHubMetadata() { -#pragma warning disable CS0618 // Type or member is obsolete - void ConfigureRoutes(HubRouteBuilder routes) -#pragma warning restore CS0618 // Type or member is obsolete + void ConfigureRoutes(IEndpointRouteBuilder routes) { // This "Foo" policy should override the default auth attribute routes.MapHub<AuthHub>("/path"); @@ -375,7 +338,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests { } - private IWebHost BuildWebHostWithEndPointRouting(Action<IEndpointRouteBuilder> configure) + private IWebHost BuildWebHost(Action<IEndpointRouteBuilder> configure) { return new WebHostBuilder() .UseKestrel() @@ -391,23 +354,5 @@ namespace Microsoft.AspNetCore.SignalR.Tests .UseUrls("http://127.0.0.1:0") .Build(); } - -#pragma warning disable CS0618 // Type or member is obsolete - private IWebHost BuildWebHost(Action<HubRouteBuilder> configure) - { - return new WebHostBuilder() - .UseKestrel() - .ConfigureServices(services => - { - services.AddSignalR(); - }) - .Configure(app => - { - app.UseSignalR(options => configure(options)); - }) - .UseUrls("http://127.0.0.1:0") - .Build(); - } -#pragma warning restore CS0618 // Type or member is obsolete } } diff --git a/src/SignalR/server/SignalR/test/Startup.cs b/src/SignalR/server/SignalR/test/Startup.cs index 25612f917f40f9d5e164afdf437877a5de8edc62..8ee6f7e53f826b94a01baa7f16f9ed8d2e3ce768 100644 --- a/src/SignalR/server/SignalR/test/Startup.cs +++ b/src/SignalR/server/SignalR/test/Startup.cs @@ -71,18 +71,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests app.UseAuthentication(); app.UseAuthorization(); - // Legacy routing, runs different code path for mapping hubs -#pragma warning disable CS0618 // Type or member is obsolete - app.UseSignalR(routes => - { - routes.MapHub<AuthHub>("/authHub"); - }); -#pragma warning restore CS0618 // Type or member is obsolete - app.UseEndpoints(endpoints => { endpoints.MapHub<UncreatableHub>("/uncreatable"); - endpoints.MapHub<AuthHub>("/authHubEndpoints"); + endpoints.MapHub<AuthHub>("/authHub"); endpoints.MapConnectionHandler<EchoConnectionHandler>("/echo"); endpoints.MapConnectionHandler<WriteThenCloseConnectionHandler>("/echoAndClose");