Skip to content
代码片段 群组 项目
提交 dd2e2186 编辑于 作者: Brennan's avatar Brennan 提交者: Nate McMaster
浏览文件

Fix typo in condition for Windows Auth with LongPolling (#11051)

上级 bc91bd03
No related branches found
No related tags found
无相关合并请求
......@@ -504,7 +504,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
// We specifically clone the identity on first poll if it's a windows identity
// If we swapped the new User here we'd have to dispose the old identities which could race with the application
// trying to access the identity.
if (context.User.Identity is WindowsIdentity)
if (!(context.User.Identity is WindowsIdentity))
{
existing.User = context.User;
}
......
......@@ -10,11 +10,10 @@ using System.Linq;
using System.Net;
using System.Net.WebSockets;
using System.Security.Claims;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Http.Connections.Internal;
......@@ -1347,6 +1346,55 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
}
}
[ConditionalFact]
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public async Task LongPollingKeepsWindowsIdentityBetweenRequests()
{
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = new DefaultHttpContext();
var services = new ServiceCollection();
services.AddOptions();
services.AddSingleton<TestConnectionHandler>();
services.AddLogging();
var sp = services.BuildServiceProvider();
context.Request.Path = "/foo";
context.Request.Method = "GET";
context.RequestServices = sp;
var values = new Dictionary<string, StringValues>();
values["id"] = connection.ConnectionId;
var qs = new QueryCollection(values);
context.Request.Query = qs;
var builder = new ConnectionBuilder(sp);
builder.UseConnectionHandler<TestConnectionHandler>();
var app = builder.Build();
var options = new HttpConnectionDispatcherOptions();
var windowsIdentity = WindowsIdentity.GetAnonymous();
context.User = new WindowsPrincipal(windowsIdentity);
// would get stuck if EndPoint was running
await dispatcher.ExecuteAsync(context, options, app).OrTimeout();
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
var currentUser = connection.User;
var connectionHandlerTask = dispatcher.ExecuteAsync(context, options, app);
await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Unblock")).AsTask().OrTimeout();
await connectionHandlerTask.OrTimeout();
// This is the important check
Assert.Same(currentUser, connection.User);
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
}
}
[Fact]
public async Task SetsInherentKeepAliveFeatureOnFirstLongPollingRequest()
{
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册