Fix typo in condition for Windows Auth with LongPolling (#11051)
Co-Authored-By: Stephen Halter <halter73@gmail.com>
This commit is contained in:
parent
bc91bd0308
commit
dd2e2186db
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue