* fixes #10756 by removing previously-obsoleted APIs in SignalR * update reference assemblies * missed a ref * think I fixed the test
This commit is contained in:
parent
ec10429430
commit
0d80ffa6cd
|
|
@ -138,6 +138,8 @@ namespace Microsoft.AspNetCore.Analyzers
|
||||||
throw new ArgumentNullException(nameof(symbol));
|
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) ||
|
if (string.Equals(symbol.Name, SymbolNames.SignalRAppBuilderExtensions.UseSignalRMethodName, StringComparison.Ordinal) ||
|
||||||
string.Equals(symbol.Name, SymbolNames.HubEndpointRouteBuilderExtensions.MapHubMethodName, StringComparison.Ordinal) ||
|
string.Equals(symbol.Name, SymbolNames.HubEndpointRouteBuilderExtensions.MapHubMethodName, StringComparison.Ordinal) ||
|
||||||
string.Equals(symbol.Name, SymbolNames.ComponentEndpointRouteBuilderExtensions.MapBlazorHubMethodName, StringComparison.Ordinal))
|
string.Equals(symbol.Name, SymbolNames.ComponentEndpointRouteBuilderExtensions.MapBlazorHubMethodName, StringComparison.Ordinal))
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ namespace Microsoft.AspNetCore.Analyzers
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(nameof(StartupWithUseSignalR))]
|
|
||||||
[InlineData(nameof(StartupWithMapHub))]
|
[InlineData(nameof(StartupWithMapHub))]
|
||||||
[InlineData(nameof(StartupWithMapBlazorHub))]
|
[InlineData(nameof(StartupWithMapBlazorHub))]
|
||||||
public async Task DetectFeaturesAsync_FindsSignalR(string source)
|
public async Task DetectFeaturesAsync_FindsSignalR(string source)
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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, 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 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
|
namespace Microsoft.AspNetCore.Http.Connections
|
||||||
{
|
{
|
||||||
|
|
@ -34,15 +29,6 @@ namespace Microsoft.AspNetCore.Http.Connections
|
||||||
public ConnectionOptionsSetup() { }
|
public ConnectionOptionsSetup() { }
|
||||||
public void Configure(Microsoft.AspNetCore.Http.Connections.ConnectionOptions options) { }
|
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 partial class HttpConnectionContextExtensions
|
||||||
{
|
{
|
||||||
public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.Connections.ConnectionContext connection) { throw null; }
|
public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.Connections.ConnectionContext connection) { throw 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -150,10 +150,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
|
||||||
public void MapConnectionHandlerEndPointRoutingFindsAttributesOnHub()
|
public void MapConnectionHandlerEndPointRoutingFindsAttributesOnHub()
|
||||||
{
|
{
|
||||||
var authCount = 0;
|
var authCount = 0;
|
||||||
using (var host = BuildWebHostWithEndPointRouting(routes => routes.MapConnectionHandler<AuthConnectionHandler>("/path", options =>
|
using (var host = BuildWebHost<AuthConnectionHandler>("/path", options =>
|
||||||
{
|
{
|
||||||
authCount += options.AuthorizationData.Count;
|
authCount += options.AuthorizationData.Count;
|
||||||
})))
|
}))
|
||||||
{
|
{
|
||||||
host.Start();
|
host.Start();
|
||||||
|
|
||||||
|
|
@ -179,11 +179,11 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
|
||||||
public void MapConnectionHandlerEndPointRoutingFindsAttributesFromOptions()
|
public void MapConnectionHandlerEndPointRoutingFindsAttributesFromOptions()
|
||||||
{
|
{
|
||||||
var authCount = 0;
|
var authCount = 0;
|
||||||
using (var host = BuildWebHostWithEndPointRouting(routes => routes.MapConnectionHandler<AuthConnectionHandler>("/path", options =>
|
using (var host = BuildWebHost<AuthConnectionHandler>("/path", options =>
|
||||||
{
|
{
|
||||||
authCount += options.AuthorizationData.Count;
|
authCount += options.AuthorizationData.Count;
|
||||||
options.AuthorizationData.Add(new AuthorizeAttribute());
|
options.AuthorizationData.Add(new AuthorizeAttribute());
|
||||||
})))
|
}))
|
||||||
{
|
{
|
||||||
host.Start();
|
host.Start();
|
||||||
|
|
||||||
|
|
@ -215,7 +215,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
|
||||||
.RequireAuthorization(new AuthorizeAttribute("Foo"));
|
.RequireAuthorization(new AuthorizeAttribute("Foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes))
|
using (var host = BuildWebHost(ConfigureRoutes))
|
||||||
{
|
{
|
||||||
host.Start();
|
host.Start();
|
||||||
|
|
||||||
|
|
@ -253,7 +253,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
|
||||||
endpoints.MapConnectionHandler<AuthConnectionHandler>("/path");
|
endpoints.MapConnectionHandler<AuthConnectionHandler>("/path");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes))
|
using (var host = BuildWebHost(ConfigureRoutes))
|
||||||
{
|
{
|
||||||
host.Start();
|
host.Start();
|
||||||
|
|
||||||
|
|
@ -281,7 +281,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
|
||||||
endpoints.MapConnectionHandler<CorsConnectionHandler>("/path");
|
endpoints.MapConnectionHandler<CorsConnectionHandler>("/path");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes))
|
using (var host = BuildWebHost(ConfigureRoutes))
|
||||||
{
|
{
|
||||||
host.Start();
|
host.Start();
|
||||||
|
|
||||||
|
|
@ -308,7 +308,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
|
||||||
var host = BuildWebHost<MyConnectionHandler>("/socket",
|
var host = BuildWebHost<MyConnectionHandler>("/socket",
|
||||||
options => options.WebSockets.SubProtocolSelector = subprotocols =>
|
options => options.WebSockets.SubProtocolSelector = subprotocols =>
|
||||||
{
|
{
|
||||||
Assert.Equal(new [] { "protocol1", "protocol2" }, subprotocols.ToArray());
|
Assert.Equal(new[] { "protocol1", "protocol2" }, subprotocols.ToArray());
|
||||||
return "protocol1";
|
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()
|
return new WebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
|
|
@ -405,12 +405,11 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
|
||||||
})
|
})
|
||||||
.Configure(app =>
|
.Configure(app =>
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
app.UseRouting();
|
||||||
app.UseConnections(routes =>
|
app.UseEndpoints(routes =>
|
||||||
{
|
{
|
||||||
routes.MapConnectionHandler<TConnectionHandler>(path, configureOptions);
|
routes.MapConnectionHandler<TConnectionHandler>(path, configureOptions);
|
||||||
});
|
});
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
|
||||||
})
|
})
|
||||||
.ConfigureLogging(factory =>
|
.ConfigureLogging(factory =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,6 @@ namespace Microsoft.AspNetCore.Builder
|
||||||
public partial interface IHubEndpointConventionBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder
|
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
|
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.HubCallerContext connection) { throw null; }
|
||||||
public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.SignalR.HubConnectionContext 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
|
namespace Microsoft.Extensions.DependencyInjection
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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>();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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]
|
[Fact]
|
||||||
[LogLevel(LogLevel.Trace)]
|
[LogLevel(LogLevel.Trace)]
|
||||||
public async Task UnauthorizedHubConnectionDoesNotConnect()
|
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]
|
[Fact]
|
||||||
[LogLevel(LogLevel.Trace)]
|
[LogLevel(LogLevel.Trace)]
|
||||||
public async Task AuthorizedHubConnectionCanConnect()
|
public async Task AuthorizedHubConnectionCanConnect()
|
||||||
|
|
|
||||||
|
|
@ -31,41 +31,6 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
var executedConfigure = false;
|
var executedConfigure = false;
|
||||||
var builder = new WebHostBuilder();
|
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
|
builder
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.ConfigureServices(services =>
|
.ConfigureServices(services =>
|
||||||
|
|
@ -189,7 +154,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
public void MapHubEndPointRoutingFindsAttributesOnHub()
|
public void MapHubEndPointRoutingFindsAttributesOnHub()
|
||||||
{
|
{
|
||||||
var authCount = 0;
|
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;
|
authCount += options.AuthorizationData.Count;
|
||||||
})))
|
})))
|
||||||
|
|
@ -219,7 +184,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
{
|
{
|
||||||
var authCount = 0;
|
var authCount = 0;
|
||||||
HttpConnectionDispatcherOptions configuredOptions = null;
|
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;
|
authCount += options.AuthorizationData.Count;
|
||||||
options.AuthorizationData.Add(new AuthorizeAttribute());
|
options.AuthorizationData.Add(new AuthorizeAttribute());
|
||||||
|
|
@ -256,7 +221,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
.RequireAuthorization(new AuthorizeAttribute("Foo"));
|
.RequireAuthorization(new AuthorizeAttribute("Foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes))
|
using (var host = BuildWebHost(ConfigureRoutes))
|
||||||
{
|
{
|
||||||
host.Start();
|
host.Start();
|
||||||
|
|
||||||
|
|
@ -295,7 +260,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
endpoints.MapHub<AuthHub>("/path");
|
endpoints.MapHub<AuthHub>("/path");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes))
|
using (var host = BuildWebHost(ConfigureRoutes))
|
||||||
{
|
{
|
||||||
host.Start();
|
host.Start();
|
||||||
|
|
||||||
|
|
@ -320,9 +285,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MapHubAppliesHubMetadata()
|
public void MapHubAppliesHubMetadata()
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
void ConfigureRoutes(IEndpointRouteBuilder routes)
|
||||||
void ConfigureRoutes(HubRouteBuilder routes)
|
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
|
||||||
{
|
{
|
||||||
// This "Foo" policy should override the default auth attribute
|
// This "Foo" policy should override the default auth attribute
|
||||||
routes.MapHub<AuthHub>("/path");
|
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()
|
return new WebHostBuilder()
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
|
|
@ -391,23 +354,5 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
.UseUrls("http://127.0.0.1:0")
|
.UseUrls("http://127.0.0.1:0")
|
||||||
.Build();
|
.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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,18 +71,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
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 =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
endpoints.MapHub<UncreatableHub>("/uncreatable");
|
endpoints.MapHub<UncreatableHub>("/uncreatable");
|
||||||
endpoints.MapHub<AuthHub>("/authHubEndpoints");
|
endpoints.MapHub<AuthHub>("/authHub");
|
||||||
|
|
||||||
endpoints.MapConnectionHandler<EchoConnectionHandler>("/echo");
|
endpoints.MapConnectionHandler<EchoConnectionHandler>("/echo");
|
||||||
endpoints.MapConnectionHandler<WriteThenCloseConnectionHandler>("/echoAndClose");
|
endpoints.MapConnectionHandler<WriteThenCloseConnectionHandler>("/echoAndClose");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue