Skip to content

Commit dd2e218

Browse files
BrennanConroyhalter73
authored andcommitted
Fix typo in condition for Windows Auth with LongPolling (dotnet#11051)
Co-Authored-By: Stephen Halter <[email protected]>
1 parent bc91bd0 commit dd2e218

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ private async Task<bool> EnsureConnectionStateAsync(HttpConnectionContext connec
504504
// We specifically clone the identity on first poll if it's a windows identity
505505
// If we swapped the new User here we'd have to dispose the old identities which could race with the application
506506
// trying to access the identity.
507-
if (context.User.Identity is WindowsIdentity)
507+
if (!(context.User.Identity is WindowsIdentity))
508508
{
509509
existing.User = context.User;
510510
}

src/SignalR/common/Http.Connections/test/HttpConnectionDispatcherTests.cs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
using System.Net;
1111
using System.Net.WebSockets;
1212
using System.Security.Claims;
13+
using System.Security.Principal;
1314
using System.Text;
1415
using System.Threading;
1516
using System.Threading.Tasks;
16-
using Microsoft.AspNetCore.Authentication;
17-
using Microsoft.AspNetCore.Authorization;
1817
using Microsoft.AspNetCore.Connections;
1918
using Microsoft.AspNetCore.Connections.Features;
2019
using Microsoft.AspNetCore.Http.Connections.Internal;
@@ -1347,6 +1346,55 @@ public async Task TransferModeSet(HttpTransportType transportType, TransferForma
13471346
}
13481347
}
13491348

1349+
[ConditionalFact]
1350+
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
1351+
public async Task LongPollingKeepsWindowsIdentityBetweenRequests()
1352+
{
1353+
using (StartVerifiableLog())
1354+
{
1355+
var manager = CreateConnectionManager(LoggerFactory);
1356+
var connection = manager.CreateConnection();
1357+
connection.TransportType = HttpTransportType.LongPolling;
1358+
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
1359+
var context = new DefaultHttpContext();
1360+
var services = new ServiceCollection();
1361+
services.AddOptions();
1362+
services.AddSingleton<TestConnectionHandler>();
1363+
services.AddLogging();
1364+
var sp = services.BuildServiceProvider();
1365+
context.Request.Path = "/foo";
1366+
context.Request.Method = "GET";
1367+
context.RequestServices = sp;
1368+
var values = new Dictionary<string, StringValues>();
1369+
values["id"] = connection.ConnectionId;
1370+
var qs = new QueryCollection(values);
1371+
context.Request.Query = qs;
1372+
1373+
var builder = new ConnectionBuilder(sp);
1374+
builder.UseConnectionHandler<TestConnectionHandler>();
1375+
var app = builder.Build();
1376+
var options = new HttpConnectionDispatcherOptions();
1377+
1378+
var windowsIdentity = WindowsIdentity.GetAnonymous();
1379+
context.User = new WindowsPrincipal(windowsIdentity);
1380+
1381+
// would get stuck if EndPoint was running
1382+
await dispatcher.ExecuteAsync(context, options, app).OrTimeout();
1383+
1384+
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
1385+
var currentUser = connection.User;
1386+
1387+
var connectionHandlerTask = dispatcher.ExecuteAsync(context, options, app);
1388+
await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Unblock")).AsTask().OrTimeout();
1389+
await connectionHandlerTask.OrTimeout();
1390+
1391+
// This is the important check
1392+
Assert.Same(currentUser, connection.User);
1393+
1394+
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
1395+
}
1396+
}
1397+
13501398
[Fact]
13511399
public async Task SetsInherentKeepAliveFeatureOnFirstLongPollingRequest()
13521400
{

0 commit comments

Comments
 (0)