@@ -29,7 +29,7 @@ public void ValidateRequest_ValidState_ExtendableCookie_NoCookieExtensionFromCon
29
29
} ;
30
30
31
31
cookieProviderMock . GetState ( "" , 0 , "" )
32
- . ReturnsForAnyArgs ( new StateInfo ( true , queueId , null , "idle" ) ) ;
32
+ . ReturnsForAnyArgs ( new StateInfo ( true , true , queueId , null , "idle" ) ) ;
33
33
34
34
35
35
UserInQueueService testObject = new UserInQueueService ( cookieProviderMock ) ;
@@ -60,7 +60,7 @@ public void ValidateRequest_ValidState_ExtendableCookie_CookieExtensionFromConfi
60
60
ActionName = "QueueAction"
61
61
} ;
62
62
63
- cookieProviderMock . GetState ( "" , 20 , "" ) . ReturnsForAnyArgs ( new StateInfo ( true , queueId , null , "disabled" ) ) ;
63
+ cookieProviderMock . GetState ( "" , 20 , "" ) . ReturnsForAnyArgs ( new StateInfo ( true , true , queueId , null , "disabled" ) ) ;
64
64
65
65
UserInQueueService testObject = new UserInQueueService ( cookieProviderMock ) ;
66
66
@@ -101,7 +101,7 @@ public void ValidateRequest_ValidState_NoExtendableCookie_DoNotRedirectDoNotStor
101
101
var customerKey = "4e1db821-a825-49da-acd0-5d376f2068db" ;
102
102
103
103
cookieProviderMock . GetState ( "" , 10 , "" )
104
- . ReturnsForAnyArgs ( new StateInfo ( true , queueId , 3 , "idle" ) ) ;
104
+ . ReturnsForAnyArgs ( new StateInfo ( true , true , queueId , 3 , "idle" ) ) ;
105
105
106
106
UserInQueueService testObject = new UserInQueueService ( cookieProviderMock ) ;
107
107
@@ -133,7 +133,7 @@ public void ValidateRequest_NoCookie_TampredToken_RedirectToErrorPageWithHashErr
133
133
var customerKey = "4e1db821-a825-49da-acd0-5d376f2068db" ;
134
134
var queueId = "iopdb821-a825-49da-acd0-5d376f2068db" ;
135
135
136
- cookieProviderMock . GetState ( "" , 10 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , "" , null , "" ) ) ;
136
+ cookieProviderMock . GetState ( "" , 10 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , false , "" , null , "" ) ) ;
137
137
var queueitToken = QueueITTokenGenerator . GenerateToken (
138
138
DateTime . UtcNow . AddHours ( 1 ) ,
139
139
"e1" ,
@@ -167,7 +167,7 @@ public void ValidateRequest_NoCookie_TampredToken_RedirectToErrorPageWithHashErr
167
167
Assert . True ( config . EventId == result . EventId ) ;
168
168
Assert . Equal ( config . ActionName , result . ActionName ) ;
169
169
cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . Store ( "" , "" , null , "" , "" , "" ) ;
170
- cookieProviderMock . ReceivedWithAnyArgs ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
170
+ cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
171
171
}
172
172
173
173
[ Fact ]
@@ -187,7 +187,7 @@ public void ValidateRequest_NoCookie_ExpiredTimeStampInToken_RedirectToErrorPage
187
187
var customerKey = "4e1db821-a825-49da-acd0-5d376f2068db" ;
188
188
var queueId = "iopdb821-a825-49da-acd0-5d376f2068db" ;
189
189
190
- cookieProviderMock . GetState ( "" , 10 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , "" , null , "" ) ) ;
190
+ cookieProviderMock . GetState ( "" , 10 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , false , "" , null , "" ) ) ;
191
191
string hash = null ;
192
192
var queueitToken = QueueITTokenGenerator . GenerateToken (
193
193
DateTime . UtcNow . AddHours ( - 1 ) ,
@@ -222,7 +222,7 @@ public void ValidateRequest_NoCookie_ExpiredTimeStampInToken_RedirectToErrorPage
222
222
Assert . True ( config . EventId == result . EventId ) ;
223
223
Assert . Equal ( config . ActionName , result . ActionName ) ;
224
224
cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . Store ( "" , "" , null , "" , null , "" ) ;
225
- cookieProviderMock . ReceivedWithAnyArgs ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
225
+ cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
226
226
}
227
227
228
228
[ Fact ]
@@ -240,7 +240,7 @@ public void ValidateRequest_NoCookie_EventIdMismatch_RedirectToErrorPageWithEven
240
240
} ;
241
241
var customerKey = "4e1db821-a825-49da-acd0-5d376f2068db" ;
242
242
var queueId = "iopdb821-a825-49da-acd0-5d376f2068db" ;
243
- cookieProviderMock . GetState ( "" , 10 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , "" , null , "" ) ) ;
243
+ cookieProviderMock . GetState ( "" , 10 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , false , "" , null , "" ) ) ;
244
244
string hash = "" ;
245
245
246
246
var queueitToken = QueueITTokenGenerator . GenerateToken (
@@ -276,7 +276,7 @@ public void ValidateRequest_NoCookie_EventIdMismatch_RedirectToErrorPageWithEven
276
276
Assert . True ( config . EventId == result . EventId ) ;
277
277
Assert . Equal ( config . ActionName , result . ActionName ) ;
278
278
cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . Store ( "" , "" , null , "" , null , "" ) ;
279
- cookieProviderMock . ReceivedWithAnyArgs ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
279
+ cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
280
280
}
281
281
282
282
[ Fact ]
@@ -295,7 +295,7 @@ public void ValidateRequest_NoCookie_ValidToken_ExtendableCookie_DoNotRedirect_S
295
295
var customerKey = "4e1db821-a825-49da-acd0-5d376f2068db" ;
296
296
297
297
var queueId = "iopdb821-a825-49da-acd0-5d376f2068db" ;
298
- cookieProviderMock . GetState ( "" , 10 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , "" , null , "" ) ) ;
298
+ cookieProviderMock . GetState ( "" , 10 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , false , "" , null , "" ) ) ;
299
299
string hash = "" ;
300
300
301
301
var queueitToken = QueueITTokenGenerator . GenerateToken (
@@ -343,7 +343,7 @@ public void ValidateRequest_NoCookie_ValidToken_CookieValidityMinuteFromToken_Do
343
343
var customerKey = "secretekeyofuser" ;
344
344
var queueId = "f8757c2d-34c2-4639-bef2-1736cdd30bbb" ;
345
345
346
- cookieProviderMock . GetState ( "" , 10 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , "" , null , "" ) ) ;
346
+ cookieProviderMock . GetState ( "" , 10 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , false , "" , null , "" ) ) ;
347
347
348
348
var queueitToken = "e_eventid~q_f8757c2d-34c2-4639-bef2-1736cdd30bbb~ri_34678c2d-34c2-4639-bef2-1736cdd30bbb~ts_1797033600~ce_False~cv_3~rt_DirectLink~h_5ee2babc3ac9fae9d80d5e64675710c371876386e77209f771007dc3e093e326" ;
349
349
@@ -386,7 +386,7 @@ public void ValidateRequest_NoCookie_WithoutToken_RedirectToQueue()
386
386
ActionName = "QueueAction"
387
387
} ;
388
388
389
- cookieProviderMock . GetState ( "" , 0 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , "" , null , "" ) ) ;
389
+ cookieProviderMock . GetState ( "" , 0 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , false , "" , null , "" ) ) ;
390
390
391
391
UserInQueueService testObject = new UserInQueueService ( cookieProviderMock ) ;
392
392
var targetUrl = "http://test.test.com?b=h" ;
@@ -405,7 +405,7 @@ public void ValidateRequest_NoCookie_WithoutToken_RedirectToQueue()
405
405
cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . Store ( null , null , null , null , null , null ) ;
406
406
Assert . True ( config . EventId == result . EventId ) ;
407
407
Assert . Equal ( config . ActionName , result . ActionName ) ;
408
- cookieProviderMock . ReceivedWithAnyArgs ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
408
+ cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
409
409
}
410
410
411
411
[ Fact ]
@@ -425,7 +425,7 @@ public void ValidateRequest_NoCookie_WithoutToken_RedirectToQueue_NotargetUrl()
425
425
ActionName = "QueueAction"
426
426
} ;
427
427
428
- cookieProviderMock . GetState ( "" , 0 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , "" , null , null ) ) ;
428
+ cookieProviderMock . GetState ( "" , 0 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , false , "" , null , null ) ) ;
429
429
430
430
UserInQueueService testObject = new UserInQueueService ( cookieProviderMock ) ;
431
431
@@ -443,7 +443,44 @@ public void ValidateRequest_NoCookie_WithoutToken_RedirectToQueue_NotargetUrl()
443
443
cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . Store ( null , null , null , null , null , null ) ;
444
444
Assert . True ( config . EventId == result . EventId ) ;
445
445
Assert . Equal ( config . ActionName , result . ActionName ) ;
446
- cookieProviderMock . ReceivedWithAnyArgs ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
446
+ cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
447
+ }
448
+
449
+ [ Fact ]
450
+ public void ValidateRequest_InvalidCookie_WithoutToken_RedirectToQueue_CancelCookie ( )
451
+ {
452
+ var cookieProviderMock = Substitute . For < IUserInQueueStateRepository > ( ) ;
453
+
454
+ var config = new QueueEventConfig ( )
455
+ {
456
+ EventId = "e1" ,
457
+ QueueDomain = "testDomain.com" ,
458
+ CookieValidityMinute = 10 ,
459
+ ExtendCookieValidity = false ,
460
+ Culture = null ,
461
+ LayoutName = "testlayout" ,
462
+ Version = 10 ,
463
+ ActionName = "QueueAction"
464
+ } ;
465
+
466
+ cookieProviderMock . GetState ( "" , 0 , "" ) . ReturnsForAnyArgs ( new StateInfo ( true , false , "" , null , null ) ) ;
467
+
468
+ UserInQueueService testObject = new UserInQueueService ( cookieProviderMock ) ;
469
+
470
+ var knownUserVersion = UserInQueueService . SDK_VERSION ;
471
+ var expectedUrl = $ "https://testDomain.com/?c=testCustomer&e=e1" +
472
+ $ "&ver={ knownUserVersion } " +
473
+ $ "&cver=10" +
474
+ $ "&man=QueueAction" +
475
+ $ "&l={ config . LayoutName } ";
476
+ var result = testObject . ValidateQueueRequest ( null , "" , config , "testCustomer" , "key" ) ;
477
+
478
+ Assert . True ( result . DoRedirect ) ;
479
+ Assert . True ( result . RedirectUrl . ToUpper ( ) == expectedUrl . ToUpper ( ) ) ;
480
+ cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . Store ( null , null , null , null , null , null ) ;
481
+ Assert . True ( config . EventId == result . EventId ) ;
482
+ Assert . Equal ( config . ActionName , result . ActionName ) ;
483
+ cookieProviderMock . Received ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
447
484
}
448
485
449
486
[ Fact ]
@@ -462,7 +499,7 @@ public void ValidateRequest_NoCookie_InValidToken()
462
499
Version = 10 ,
463
500
ActionName = "QueueAction"
464
501
} ;
465
- cookieProviderMock . GetState ( "" , 0 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , null , null , null ) ) ;
502
+ cookieProviderMock . GetState ( "" , 0 , "" ) . ReturnsForAnyArgs ( new StateInfo ( false , false , null , null , null ) ) ;
466
503
467
504
UserInQueueService testObject = new UserInQueueService ( cookieProviderMock ) ;
468
505
var targetUrl = "http://test.test.com?b=h" ;
@@ -475,7 +512,38 @@ public void ValidateRequest_NoCookie_InValidToken()
475
512
cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . Store ( null , null , null , null , null , null ) ;
476
513
Assert . True ( config . EventId == result . EventId ) ;
477
514
Assert . Equal ( config . ActionName , result . ActionName ) ;
478
- cookieProviderMock . ReceivedWithAnyArgs ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
515
+ cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
516
+ }
517
+
518
+ [ Fact ]
519
+ public void ValidateRequest_InvalidCookie_InvalidToken_CancelCookie ( )
520
+ {
521
+ var cookieProviderMock = Substitute . For < IUserInQueueStateRepository > ( ) ;
522
+
523
+ var config = new QueueEventConfig ( )
524
+ {
525
+ EventId = "e1" ,
526
+ QueueDomain = "testDomain.com" ,
527
+ CookieValidityMinute = 10 ,
528
+ ExtendCookieValidity = false ,
529
+ Culture = null ,
530
+ LayoutName = "testlayout" ,
531
+ Version = 10 ,
532
+ ActionName = "QueueAction"
533
+ } ;
534
+ cookieProviderMock . GetState ( "" , 0 , "" ) . ReturnsForAnyArgs ( new StateInfo ( true , false , null , null , null ) ) ;
535
+
536
+ UserInQueueService testObject = new UserInQueueService ( cookieProviderMock ) ;
537
+ var targetUrl = "http://test.test.com?b=h" ;
538
+ var knownUserVersion = UserInQueueService . SDK_VERSION ;
539
+ var result = testObject . ValidateQueueRequest ( targetUrl , "ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895" , config , "testCustomer" , "key" ) ;
540
+
541
+ Assert . True ( result . DoRedirect ) ;
542
+ Assert . StartsWith ( $ "https://testDomain.com/error/hash/?c=testCustomer&e=e1&ver={ knownUserVersion } &cver=10&man=QueueAction&l=testlayout&queueittoken=ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895&", result . RedirectUrl ) ;
543
+ cookieProviderMock . DidNotReceiveWithAnyArgs ( ) . Store ( null , null , null , null , null , null ) ;
544
+ Assert . True ( config . EventId == result . EventId ) ;
545
+ Assert . Equal ( config . ActionName , result . ActionName ) ;
546
+ cookieProviderMock . Received ( ) . CancelQueueCookie ( config . EventId , config . CookieDomain ) ;
479
547
}
480
548
481
549
[ Fact ]
@@ -497,7 +565,7 @@ public void ValidateCancelRequest()
497
565
$ "&ver={ knownUserVersion } "
498
566
+ $ "&cver=10&man=QueueAction&r=" + "url" ;
499
567
cookieProviderMock . GetState ( "" , 0 , "" , false )
500
- . ReturnsForAnyArgs ( new StateInfo ( true , queueId , 3 , "idle" ) ) ;
568
+ . ReturnsForAnyArgs ( new StateInfo ( true , true , queueId , 3 , "idle" ) ) ;
501
569
502
570
UserInQueueService testObject = new UserInQueueService ( cookieProviderMock ) ;
503
571
0 commit comments