@@ -450,7 +450,6 @@ public async Task TransportEndingGracefullyWaitsOnApplication(HttpTransportType
450
450
var manager = CreateConnectionManager ( LoggerFactory ) ;
451
451
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
452
452
var connection = manager . CreateConnection ( ) ;
453
- connection . TransportType = transportType ;
454
453
455
454
using ( var strm = new MemoryStream ( ) )
456
455
{
@@ -1001,7 +1000,6 @@ public async Task CompletedEndPointEndsConnection()
1001
1000
{
1002
1001
var manager = CreateConnectionManager ( LoggerFactory ) ;
1003
1002
var connection = manager . CreateConnection ( ) ;
1004
- connection . TransportType = HttpTransportType . ServerSentEvents ;
1005
1003
1006
1004
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
1007
1005
@@ -1036,7 +1034,6 @@ bool ExpectedErrors(WriteContext writeContext)
1036
1034
{
1037
1035
var manager = CreateConnectionManager ( LoggerFactory ) ;
1038
1036
var connection = manager . CreateConnection ( ) ;
1039
- connection . TransportType = HttpTransportType . ServerSentEvents ;
1040
1037
1041
1038
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
1042
1039
var services = new ServiceCollection ( ) ;
@@ -1315,12 +1312,11 @@ public async Task SSEConnectionClosesWhenSendTimeoutReached()
1315
1312
{
1316
1313
var manager = CreateConnectionManager ( LoggerFactory ) ;
1317
1314
var connection = manager . CreateConnection ( ) ;
1318
- connection . TransportType = HttpTransportType . ServerSentEvents ;
1319
1315
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
1320
1316
var services = new ServiceCollection ( ) ;
1321
1317
services . AddSingleton < TestConnectionHandler > ( ) ;
1322
1318
var context = MakeRequest ( "/foo" , connection , services ) ;
1323
- SetTransport ( context , connection . TransportType ) ;
1319
+ SetTransport ( context , HttpTransportType . ServerSentEvents ) ;
1324
1320
var builder = new ConnectionBuilder ( services . BuildServiceProvider ( ) ) ;
1325
1321
builder . UseConnectionHandler < TestConnectionHandler > ( ) ;
1326
1322
var app = builder . Build ( ) ;
@@ -1352,13 +1348,12 @@ bool ExpectedErrors(WriteContext writeContext)
1352
1348
{
1353
1349
var manager = CreateConnectionManager ( LoggerFactory ) ;
1354
1350
var connection = manager . CreateConnection ( ) ;
1355
- connection . TransportType = HttpTransportType . WebSockets ;
1356
1351
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
1357
1352
var sync = new SyncPoint ( ) ;
1358
1353
var services = new ServiceCollection ( ) ;
1359
1354
services . AddSingleton < TestConnectionHandler > ( ) ;
1360
1355
var context = MakeRequest ( "/foo" , connection , services ) ;
1361
- SetTransport ( context , connection . TransportType , sync ) ;
1356
+ SetTransport ( context , HttpTransportType . WebSockets , sync ) ;
1362
1357
var builder = new ConnectionBuilder ( services . BuildServiceProvider ( ) ) ;
1363
1358
builder . UseConnectionHandler < TestConnectionHandler > ( ) ;
1364
1359
var app = builder . Build ( ) ;
@@ -1414,7 +1409,6 @@ public async Task RequestToActiveConnectionId409ForStreamingTransports(HttpTrans
1414
1409
{
1415
1410
var manager = CreateConnectionManager ( LoggerFactory ) ;
1416
1411
var connection = manager . CreateConnection ( ) ;
1417
- connection . TransportType = transportType ;
1418
1412
1419
1413
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
1420
1414
@@ -1434,7 +1428,10 @@ public async Task RequestToActiveConnectionId409ForStreamingTransports(HttpTrans
1434
1428
1435
1429
await dispatcher . ExecuteAsync ( context2 , options , app ) . DefaultTimeout ( ) ;
1436
1430
1431
+ Assert . False ( request1 . IsCompleted ) ;
1432
+
1437
1433
Assert . Equal ( StatusCodes . Status409Conflict , context2 . Response . StatusCode ) ;
1434
+ Assert . NotSame ( connection . HttpContext , context2 ) ;
1438
1435
1439
1436
var webSocketTask = Task . CompletedTask ;
1440
1437
@@ -1586,7 +1583,6 @@ public async Task RequestToDisposedConnectionIdReturns404(HttpTransportType tran
1586
1583
{
1587
1584
var manager = CreateConnectionManager ( LoggerFactory ) ;
1588
1585
var connection = manager . CreateConnection ( ) ;
1589
- connection . TransportType = transportType ;
1590
1586
connection . Status = HttpConnectionStatus . Disposed ;
1591
1587
1592
1588
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
@@ -1653,7 +1649,6 @@ public async Task BlockingConnectionWorksWithStreamingConnections()
1653
1649
{
1654
1650
var manager = CreateConnectionManager ( LoggerFactory ) ;
1655
1651
var connection = manager . CreateConnection ( ) ;
1656
- connection . TransportType = HttpTransportType . ServerSentEvents ;
1657
1652
1658
1653
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
1659
1654
@@ -1777,7 +1772,6 @@ public async Task TransferModeSet(HttpTransportType transportType, TransferForma
1777
1772
{
1778
1773
var manager = CreateConnectionManager ( LoggerFactory ) ;
1779
1774
var connection = manager . CreateConnection ( ) ;
1780
- connection . TransportType = transportType ;
1781
1775
1782
1776
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
1783
1777
@@ -2434,7 +2428,6 @@ public async Task DisableReconnectDisallowsReplacementConnection()
2434
2428
options . WebSockets . CloseTimeout = TimeSpan . FromMilliseconds ( 1 ) ;
2435
2429
// pretend negotiate occurred
2436
2430
var connection = manager . CreateConnection ( options , negotiateVersion : 1 , useStatefulReconnect : true ) ;
2437
- connection . TransportType = HttpTransportType . WebSockets ;
2438
2431
2439
2432
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
2440
2433
var services = new ServiceCollection ( ) ;
@@ -2800,12 +2793,11 @@ public async Task SSEConnectionClosingTriggersConnectionClosedToken()
2800
2793
{
2801
2794
var manager = CreateConnectionManager ( LoggerFactory ) ;
2802
2795
var connection = manager . CreateConnection ( ) ;
2803
- connection . TransportType = HttpTransportType . ServerSentEvents ;
2804
2796
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
2805
2797
var services = new ServiceCollection ( ) ;
2806
2798
services . AddSingleton < NeverEndingConnectionHandler > ( ) ;
2807
2799
var context = MakeRequest ( "/foo" , connection , services ) ;
2808
- SetTransport ( context , connection . TransportType ) ;
2800
+ SetTransport ( context , HttpTransportType . ServerSentEvents ) ;
2809
2801
2810
2802
var builder = new ConnectionBuilder ( services . BuildServiceProvider ( ) ) ;
2811
2803
builder . UseConnectionHandler < NeverEndingConnectionHandler > ( ) ;
@@ -2827,7 +2819,6 @@ public async Task WebSocketConnectionClosingTriggersConnectionClosedToken()
2827
2819
{
2828
2820
var manager = CreateConnectionManager ( LoggerFactory ) ;
2829
2821
var connection = manager . CreateConnection ( ) ;
2830
- connection . TransportType = HttpTransportType . WebSockets ;
2831
2822
2832
2823
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
2833
2824
var services = new ServiceCollection ( ) ;
@@ -2875,14 +2866,13 @@ public async Task AbortingConnectionAbortsHttpContextAndTriggersConnectionClosed
2875
2866
{
2876
2867
var manager = CreateConnectionManager ( LoggerFactory ) ;
2877
2868
var connection = manager . CreateConnection ( ) ;
2878
- connection . TransportType = HttpTransportType . ServerSentEvents ;
2879
2869
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
2880
2870
var services = new ServiceCollection ( ) ;
2881
2871
services . AddSingleton < NeverEndingConnectionHandler > ( ) ;
2882
2872
var context = MakeRequest ( "/foo" , connection , services ) ;
2883
2873
var lifetimeFeature = new CustomHttpRequestLifetimeFeature ( ) ;
2884
2874
context . Features . Set < IHttpRequestLifetimeFeature > ( lifetimeFeature ) ;
2885
- SetTransport ( context , connection . TransportType ) ;
2875
+ SetTransport ( context , HttpTransportType . ServerSentEvents ) ;
2886
2876
2887
2877
var builder = new ConnectionBuilder ( services . BuildServiceProvider ( ) ) ;
2888
2878
builder . UseConnectionHandler < NeverEndingConnectionHandler > ( ) ;
@@ -3062,7 +3052,6 @@ public async Task LongRunningActivityTagSetOnExecuteAsync()
3062
3052
{
3063
3053
var manager = CreateConnectionManager ( LoggerFactory ) ;
3064
3054
var connection = manager . CreateConnection ( ) ;
3065
- connection . TransportType = HttpTransportType . ServerSentEvents ;
3066
3055
3067
3056
var dispatcher = CreateDispatcher ( manager , LoggerFactory ) ;
3068
3057
var services = new ServiceCollection ( ) ;
@@ -3313,56 +3302,56 @@ public async Task AuthenticationExpirationUsesCorrectScheme(HttpTransportType tr
3313
3302
var JwtTokenHandler = new JwtSecurityTokenHandler ( ) ;
3314
3303
3315
3304
using var host = CreateHost ( services =>
3305
+ {
3306
+ // Set default to Cookie auth but use JWT auth for the endpoint
3307
+ // This makes sure we take the scheme into account when grabbing the token expiration
3308
+ services . AddAuthentication ( CookieAuthenticationDefaults . AuthenticationScheme )
3309
+ . AddCookie ( )
3310
+ . AddJwtBearer ( options =>
3316
3311
{
3317
- // Set default to Cookie auth but use JWT auth for the endpoint
3318
- // This makes sure we take the scheme into account when grabbing the token expiration
3319
- services . AddAuthentication ( CookieAuthenticationDefaults . AuthenticationScheme )
3320
- . AddCookie ( )
3321
- . AddJwtBearer ( options =>
3312
+ options . TokenValidationParameters =
3313
+ new TokenValidationParameters
3314
+ {
3315
+ LifetimeValidator = ( before , expires , token , parameters ) => expires > DateTime . UtcNow ,
3316
+ ValidateAudience = false ,
3317
+ ValidateIssuer = false ,
3318
+ ValidateActor = false ,
3319
+ ValidateLifetime = true ,
3320
+ IssuerSigningKey = SecurityKey
3321
+ } ;
3322
+
3323
+ options . Events = new JwtBearerEvents
3322
3324
{
3323
- options . TokenValidationParameters =
3324
- new TokenValidationParameters
3325
- {
3326
- LifetimeValidator = ( before , expires , token , parameters ) => expires > DateTime . UtcNow ,
3327
- ValidateAudience = false ,
3328
- ValidateIssuer = false ,
3329
- ValidateActor = false ,
3330
- ValidateLifetime = true ,
3331
- IssuerSigningKey = SecurityKey
3332
- } ;
3333
-
3334
- options . Events = new JwtBearerEvents
3325
+ OnMessageReceived = context =>
3335
3326
{
3336
- OnMessageReceived = context =>
3327
+ var accessToken = context . Request . Query [ "access_token" ] ;
3328
+
3329
+ if ( ! string . IsNullOrEmpty ( accessToken ) &&
3330
+ ( context . HttpContext . WebSockets . IsWebSocketRequest || context . Request . Headers [ "Accept" ] == "text/event-stream" ) )
3337
3331
{
3338
- var accessToken = context . Request . Query [ "access_token" ] ;
3339
-
3340
- if ( ! string . IsNullOrEmpty ( accessToken ) &&
3341
- ( context . HttpContext . WebSockets . IsWebSocketRequest || context . Request . Headers [ "Accept" ] == "text/event-stream" ) )
3342
- {
3343
- context . Token = context . Request . Query [ "access_token" ] ;
3344
- }
3345
- return Task . CompletedTask ;
3332
+ context . Token = context . Request . Query [ "access_token" ] ;
3346
3333
}
3347
- } ;
3348
- } ) ;
3349
- } , endpoints =>
3350
- {
3351
- endpoints . MapConnectionHandler < JwtConnectionHandler > ( "/foo" , o => o . CloseOnAuthenticationExpiration = true ) ;
3334
+ return Task . CompletedTask ;
3335
+ }
3336
+ } ;
3337
+ } ) ;
3338
+ } , endpoints =>
3339
+ {
3340
+ endpoints . MapConnectionHandler < JwtConnectionHandler > ( "/foo" , o => o . CloseOnAuthenticationExpiration = true ) ;
3352
3341
3353
- endpoints . MapGet ( "/generatetoken" , context =>
3354
- {
3355
- return context . Response . WriteAsync ( GenerateToken ( context ) ) ;
3356
- } ) ;
3342
+ endpoints . MapGet ( "/generatetoken" , context =>
3343
+ {
3344
+ return context . Response . WriteAsync ( GenerateToken ( context ) ) ;
3345
+ } ) ;
3357
3346
3358
- string GenerateToken ( HttpContext httpContext )
3359
- {
3360
- var claims = new [ ] { new Claim ( ClaimTypes . NameIdentifier , httpContext . Request . Query [ "user" ] ) } ;
3361
- var credentials = new SigningCredentials ( SecurityKey , SecurityAlgorithms . HmacSha256 ) ;
3362
- var token = new JwtSecurityToken ( "SignalRTestServer" , "SignalRTests" , claims , expires : DateTime . UtcNow . AddMinutes ( 1 ) , signingCredentials : credentials ) ;
3363
- return JwtTokenHandler . WriteToken ( token ) ;
3364
- }
3365
- } , LoggerFactory ) ;
3347
+ string GenerateToken ( HttpContext httpContext )
3348
+ {
3349
+ var claims = new [ ] { new Claim ( ClaimTypes . NameIdentifier , httpContext . Request . Query [ "user" ] ) } ;
3350
+ var credentials = new SigningCredentials ( SecurityKey , SecurityAlgorithms . HmacSha256 ) ;
3351
+ var token = new JwtSecurityToken ( "SignalRTestServer" , "SignalRTests" , claims , expires : DateTime . UtcNow . AddMinutes ( 1 ) , signingCredentials : credentials ) ;
3352
+ return JwtTokenHandler . WriteToken ( token ) ;
3353
+ }
3354
+ } , LoggerFactory ) ;
3366
3355
3367
3356
host . Start ( ) ;
3368
3357
@@ -3639,7 +3628,6 @@ private static async Task CheckTransportSupported(HttpTransportType supportedTra
3639
3628
{
3640
3629
var manager = CreateConnectionManager ( loggerFactory ) ;
3641
3630
var connection = manager . CreateConnection ( ) ;
3642
- connection . TransportType = transportType ;
3643
3631
3644
3632
var dispatcher = CreateDispatcher ( manager , loggerFactory ) ;
3645
3633
using ( var strm = new MemoryStream ( ) )
0 commit comments