@@ -1639,7 +1639,7 @@ public async Task TransferModeSet(HttpTransportType transportType, TransferForma
1639
1639
1640
1640
[ ConditionalFact ]
1641
1641
[ OSSkipCondition ( OperatingSystems . Linux | OperatingSystems . MacOSX ) ]
1642
- public async Task LongPollingKeepsWindowsIdentityBetweenRequests ( )
1642
+ public async Task LongPollingKeepsWindowsPrincipalAndIdentityBetweenRequests ( )
1643
1643
{
1644
1644
using ( StartVerifiableLog ( ) )
1645
1645
{
@@ -1668,6 +1668,7 @@ public async Task LongPollingKeepsWindowsIdentityBetweenRequests()
1668
1668
1669
1669
var windowsIdentity = WindowsIdentity . GetAnonymous ( ) ;
1670
1670
context . User = new WindowsPrincipal ( windowsIdentity ) ;
1671
+ context . User . AddIdentity ( new ClaimsIdentity ( ) ) ;
1671
1672
1672
1673
// would get stuck if EndPoint was running
1673
1674
await dispatcher . ExecuteAsync ( context , options , app ) . OrTimeout ( ) ;
@@ -1681,6 +1682,60 @@ public async Task LongPollingKeepsWindowsIdentityBetweenRequests()
1681
1682
1682
1683
// This is the important check
1683
1684
Assert . Same ( currentUser , connection . User ) ;
1685
+ Assert . IsType < WindowsPrincipal > ( currentUser ) ;
1686
+ Assert . Equal ( 2 , connection . User . Identities . Count ( ) ) ;
1687
+
1688
+ Assert . Equal ( StatusCodes . Status200OK , context . Response . StatusCode ) ;
1689
+ }
1690
+ }
1691
+
1692
+ [ ConditionalFact ]
1693
+ [ OSSkipCondition ( OperatingSystems . Linux | OperatingSystems . MacOSX ) ]
1694
+ public async Task LongPollingKeepsWindowsIdentityWithoutWindowsPrincipalBetweenRequests ( )
1695
+ {
1696
+ using ( StartVerifiableLog ( ) )
1697
+ {
1698
+ var manager = CreateConnectionManager ( LoggerFactory ) ;
1699
+ var connection = manager . CreateConnection ( ) ;
1700
+ connection . TransportType = HttpTransportType . LongPolling ;
1701
+ var dispatcher = new HttpConnectionDispatcher ( manager , LoggerFactory ) ;
1702
+ var context = new DefaultHttpContext ( ) ;
1703
+ var services = new ServiceCollection ( ) ;
1704
+ services . AddOptions ( ) ;
1705
+ services . AddSingleton < TestConnectionHandler > ( ) ;
1706
+ services . AddLogging ( ) ;
1707
+ var sp = services . BuildServiceProvider ( ) ;
1708
+ context . Request . Path = "/foo" ;
1709
+ context . Request . Method = "GET" ;
1710
+ context . RequestServices = sp ;
1711
+ var values = new Dictionary < string , StringValues > ( ) ;
1712
+ values [ "id" ] = connection . ConnectionToken ;
1713
+ values [ "negotiateVersion" ] = "1" ;
1714
+ var qs = new QueryCollection ( values ) ;
1715
+ context . Request . Query = qs ;
1716
+ var builder = new ConnectionBuilder ( sp ) ;
1717
+ builder . UseConnectionHandler < TestConnectionHandler > ( ) ;
1718
+ var app = builder . Build ( ) ;
1719
+ var options = new HttpConnectionDispatcherOptions ( ) ;
1720
+
1721
+ var windowsIdentity = WindowsIdentity . GetAnonymous ( ) ;
1722
+ context . User = new ClaimsPrincipal ( windowsIdentity ) ;
1723
+ context . User . AddIdentity ( new ClaimsIdentity ( ) ) ;
1724
+
1725
+ // would get stuck if EndPoint was running
1726
+ await dispatcher . ExecuteAsync ( context , options , app ) . OrTimeout ( ) ;
1727
+
1728
+ Assert . Equal ( StatusCodes . Status200OK , context . Response . StatusCode ) ;
1729
+ var currentUser = connection . User ;
1730
+
1731
+ var connectionHandlerTask = dispatcher . ExecuteAsync ( context , options , app ) ;
1732
+ await connection . Transport . Output . WriteAsync ( Encoding . UTF8 . GetBytes ( "Unblock" ) ) . AsTask ( ) . OrTimeout ( ) ;
1733
+ await connectionHandlerTask . OrTimeout ( ) ;
1734
+
1735
+ // This is the important check
1736
+ Assert . Same ( currentUser , connection . User ) ;
1737
+ Assert . IsNotType < WindowsPrincipal > ( currentUser ) ;
1738
+ Assert . Equal ( 2 , connection . User . Identities . Count ( ) ) ;
1684
1739
1685
1740
Assert . Equal ( StatusCodes . Status200OK , context . Response . StatusCode ) ;
1686
1741
}
0 commit comments