|
10 | 10 | using System.Net;
|
11 | 11 | using System.Net.WebSockets;
|
12 | 12 | using System.Security.Claims;
|
| 13 | +using System.Security.Principal; |
13 | 14 | using System.Text;
|
14 | 15 | using System.Threading;
|
15 | 16 | using System.Threading.Tasks;
|
16 |
| -using Microsoft.AspNetCore.Authentication; |
17 |
| -using Microsoft.AspNetCore.Authorization; |
18 | 17 | using Microsoft.AspNetCore.Connections;
|
19 | 18 | using Microsoft.AspNetCore.Connections.Features;
|
20 | 19 | using Microsoft.AspNetCore.Http.Connections.Internal;
|
@@ -1347,6 +1346,55 @@ public async Task TransferModeSet(HttpTransportType transportType, TransferForma
|
1347 | 1346 | }
|
1348 | 1347 | }
|
1349 | 1348 |
|
| 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 | + |
1350 | 1398 | [Fact]
|
1351 | 1399 | public async Task SetsInherentKeepAliveFeatureOnFirstLongPollingRequest()
|
1352 | 1400 | {
|
|
0 commit comments