1
1
using QueueIT . KnownUserV3 . SDK . IntegrationConfig ;
2
+ using Rhino . Mocks ;
2
3
using System ;
3
4
using System . Collections . Generic ;
4
- using System . Linq ;
5
- using System . Text ;
6
- using System . Threading . Tasks ;
7
- using Rhino ;
8
- using Rhino . Mocks ;
5
+ using System . Collections . Specialized ;
9
6
using System . Web ;
10
7
using Xunit ;
11
8
@@ -45,7 +42,6 @@ public void Evaluate_StartsWith()
45
42
Assert . False ( ComparisonOperatorHelper . Evaluate ( ComparisonOperatorType . StartsWith , true , true , "test1_test1_test" , "Test1" ) ) ;
46
43
}
47
44
48
-
49
45
[ Fact ]
50
46
public void Evaluate_EndsWith ( )
51
47
{
@@ -64,6 +60,7 @@ public void Evaluate_MatchesWith()
64
60
Assert . False ( ComparisonOperatorHelper . Evaluate ( ComparisonOperatorType . MatchesWith , true , true , "test1_test1_testshop" , ".*Shop.*" ) ) ;
65
61
}
66
62
}
63
+
67
64
public class CookieValidatorHelperTest
68
65
{
69
66
[ Fact ]
@@ -135,7 +132,6 @@ public void Evaluate_Test()
135
132
}
136
133
}
137
134
138
-
139
135
public class UserAgentValidatorHelperTest
140
136
{
141
137
[ Fact ]
@@ -154,7 +150,7 @@ public void Evaluate_Test()
154
150
triggerPart . IsNegative = true ;
155
151
Assert . True ( UserAgentValidatorHelper . Evaluate ( triggerPart , "oglebot sample useraagent" ) ) ;
156
152
157
-
153
+
158
154
triggerPart . ValueToCompare = "googlebot" ;
159
155
triggerPart . Operator = ComparisonOperatorType . Contains ;
160
156
triggerPart . IsIgnoreCase = false ;
@@ -171,6 +167,40 @@ public void Evaluate_Test()
171
167
}
172
168
}
173
169
170
+ public class HttpHeaderValidatorTest
171
+ {
172
+ [ Fact ]
173
+ public void Evaluate_Test ( )
174
+ {
175
+ var triggerPart = new TriggerPart ( )
176
+ {
177
+ HttpHeaderName = "c1" ,
178
+ Operator = ComparisonOperatorType . Contains ,
179
+ ValueToCompare = "1"
180
+ } ;
181
+ var httpHeaders = new NameValueCollection ( ) { } ;
182
+ Assert . False ( HttpHeaderValidatorHelper . Evaluate ( triggerPart , httpHeaders ) ) ;
183
+
184
+ httpHeaders . Add ( "c5" , "5" ) ;
185
+ httpHeaders . Add ( "c1" , "1" ) ;
186
+ httpHeaders . Add ( "c2" , "test" ) ;
187
+ Assert . True ( HttpHeaderValidatorHelper . Evaluate ( triggerPart , httpHeaders ) ) ;
188
+
189
+ triggerPart . ValueToCompare = "5" ;
190
+ Assert . False ( HttpHeaderValidatorHelper . Evaluate ( triggerPart , httpHeaders ) ) ;
191
+
192
+ triggerPart . ValueToCompare = "Test" ;
193
+ triggerPart . IsIgnoreCase = true ;
194
+ triggerPart . HttpHeaderName = "c2" ;
195
+ Assert . True ( HttpHeaderValidatorHelper . Evaluate ( triggerPart , httpHeaders ) ) ;
196
+
197
+ triggerPart . ValueToCompare = "Test" ;
198
+ triggerPart . IsIgnoreCase = true ;
199
+ triggerPart . IsNegative = true ;
200
+ triggerPart . HttpHeaderName = "c2" ;
201
+ Assert . False ( HttpHeaderValidatorHelper . Evaluate ( triggerPart , httpHeaders ) ) ;
202
+ }
203
+ }
174
204
175
205
public class IntegrationEvaluatorTest
176
206
{
@@ -196,7 +226,7 @@ public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched()
196
226
ValidatorType = ValidatorType . CookieValidator
197
227
} ,
198
228
new TriggerPart ( ) {
199
-
229
+
200
230
ValidatorType = ValidatorType . UserAgentValidator ,
201
231
ValueToCompare = "test" ,
202
232
Operator = ComparisonOperatorType . Contains
@@ -210,8 +240,13 @@ public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched()
210
240
211
241
var url = new Uri ( "http://test.tesdomain.com:8080/test?q=2" ) ;
212
242
213
- Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri , new HttpCookieCollection ( ) , string . Empty ) == null ) ;
243
+ var httpRequestMock = MockRepository . GenerateMock < HttpRequestBase > ( ) ;
244
+ httpRequestMock . Stub ( r => r . Cookies ) . Return ( new HttpCookieCollection ( ) ) ;
245
+ httpRequestMock . Stub ( r => r . UserAgent ) . Return ( string . Empty ) ;
246
+
247
+ Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri , httpRequestMock ) == null ) ;
214
248
}
249
+
215
250
[ Fact ]
216
251
public void GetMatchedIntegrationConfig_OneTrigger_And_Matched ( )
217
252
{
@@ -252,10 +287,12 @@ public void GetMatchedIntegrationConfig_OneTrigger_And_Matched()
252
287
253
288
254
289
var url = new Uri ( "http://test.tesdomain.com:8080/test?q=2" ) ;
255
-
256
290
257
- Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri ,
258
- new HttpCookieCollection ( ) { new HttpCookie ( "c1" , "Value1" ) } , string . Empty ) . Name == "integration1" ) ;
291
+ var httpRequestMock = MockRepository . GenerateMock < HttpRequestBase > ( ) ;
292
+ httpRequestMock . Stub ( r => r . Cookies ) . Return ( new HttpCookieCollection ( ) { new HttpCookie ( "c1" , "Value1" ) } ) ;
293
+ httpRequestMock . Stub ( r => r . UserAgent ) . Return ( string . Empty ) ;
294
+
295
+ Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri , httpRequestMock ) . Name == "integration1" ) ;
259
296
}
260
297
261
298
[ Fact ]
@@ -306,10 +343,71 @@ public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched_UserAgent()
306
343
307
344
var url = new Uri ( "http://test.tesdomain.com:8080/test?q=2" ) ;
308
345
346
+ var httpRequestMock = MockRepository . GenerateMock < HttpRequestBase > ( ) ;
347
+ httpRequestMock . Stub ( r => r . Cookies ) . Return ( new HttpCookieCollection ( ) { new HttpCookie ( "c1" , "Value1" ) } ) ;
348
+ httpRequestMock . Stub ( r => r . UserAgent ) . Return ( "bot.html google.com googlebot test" ) ;
309
349
310
- Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri ,
311
- new HttpCookieCollection ( ) { new HttpCookie ( "c1" , "Value1" ) } , "bot.html google.com googlebot test" ) == null ) ;
350
+ Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri , httpRequestMock ) == null ) ;
312
351
}
352
+
353
+ [ Fact ]
354
+ public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched_HttpHeader ( )
355
+ {
356
+ var testObject = new IntegrationEvaluator ( ) ;
357
+
358
+ var customerIntegration = new CustomerIntegration ( )
359
+ {
360
+
361
+ Integrations = new List < IntegrationConfigModel > {
362
+ new IntegrationConfigModel ( )
363
+ {
364
+ Name = "integration1" ,
365
+ Triggers = new List < TriggerModel > ( ) {
366
+ new TriggerModel ( ) {
367
+ LogicalOperator = LogicalOperatorType . And ,
368
+ TriggerParts = new List < TriggerPart > ( ) {
369
+ new TriggerPart ( ) {
370
+ CookieName = "c1" ,
371
+ Operator = ComparisonOperatorType . EqualS ,
372
+ IsIgnoreCase = true ,
373
+ ValueToCompare = "value1" ,
374
+ ValidatorType = ValidatorType . CookieValidator
375
+ } ,
376
+ new TriggerPart ( ) {
377
+ UrlPart = UrlPartType . PageUrl ,
378
+ ValidatorType = ValidatorType . UrlValidator ,
379
+ ValueToCompare = "test" ,
380
+ Operator = ComparisonOperatorType . Contains
381
+ } ,
382
+ new TriggerPart ( ) {
383
+ HttpHeaderName = "Akamai-bot" ,
384
+ ValidatorType = ValidatorType . HttpHeaderValidator ,
385
+ ValueToCompare = "bot" ,
386
+ Operator = ComparisonOperatorType . Contains ,
387
+ IsIgnoreCase = true ,
388
+ IsNegative = true
389
+ }
390
+
391
+ }
392
+ }
393
+ }
394
+ }
395
+
396
+ }
397
+ } ;
398
+
399
+
400
+ var url = new Uri ( "http://test.tesdomain.com:8080/test?q=2" ) ;
401
+
402
+ var httpRequestMock = MockRepository . GenerateMock < HttpRequestBase > ( ) ;
403
+ httpRequestMock . Stub ( r => r . Cookies ) . Return ( new HttpCookieCollection ( ) { new HttpCookie ( "c1" , "Value1" ) } ) ;
404
+ var httpHeaders = new NameValueCollection ( ) ;
405
+ httpHeaders . Add ( "Akamai-bot" , "bot" ) ;
406
+ httpRequestMock . Stub ( r => r . Headers ) . Return ( httpHeaders ) ;
407
+
408
+ Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri , httpRequestMock ) == null ) ;
409
+ }
410
+
313
411
[ Fact ]
314
412
public void GetMatchedIntegrationConfig_OneTrigger_Or_NotMatched ( )
315
413
{
@@ -348,14 +446,15 @@ public void GetMatchedIntegrationConfig_OneTrigger_Or_NotMatched()
348
446
349
447
} ;
350
448
351
-
352
449
var url = new Uri ( "http://test.tesdomain.com:8080/test?q=2" ) ;
353
-
354
450
451
+ var httpRequestMock = MockRepository . GenerateMock < HttpRequestBase > ( ) ;
452
+ httpRequestMock . Stub ( r => r . Cookies ) . Return ( new HttpCookieCollection ( ) { new HttpCookie ( "c2" , "value1" ) } ) ;
453
+ httpRequestMock . Stub ( r => r . UserAgent ) . Return ( string . Empty ) ;
355
454
356
- Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri ,
357
- new HttpCookieCollection ( ) { new HttpCookie ( "c2" , "value1" ) } , string . Empty ) == null ) ;
455
+ Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri , httpRequestMock ) == null ) ;
358
456
}
457
+
359
458
[ Fact ]
360
459
public void GetMatchedIntegrationConfig_OneTrigger_Or_Matched ( )
361
460
{
@@ -395,10 +494,10 @@ public void GetMatchedIntegrationConfig_OneTrigger_Or_Matched()
395
494
396
495
var url = new Uri ( "http://test.tesdomain.com:8080/test?q=2" ) ;
397
496
var httpRequestMock = MockRepository . GenerateMock < HttpRequestBase > ( ) ;
497
+ httpRequestMock . Stub ( r => r . Cookies ) . Return ( new HttpCookieCollection ( ) { new HttpCookie ( "c1" , "value1" ) } ) ;
498
+ httpRequestMock . Stub ( r => r . UserAgent ) . Return ( string . Empty ) ;
398
499
399
-
400
- Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri ,
401
- new HttpCookieCollection ( ) { new HttpCookie ( "c1" , "value1" ) } , string . Empty ) . Name == "integration1" ) ;
500
+ Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri , httpRequestMock ) . Name == "integration1" ) ;
402
501
}
403
502
404
503
[ Fact ]
@@ -445,12 +544,14 @@ public void GetMatchedIntegrationConfig_TwoTriggers_Matched()
445
544
446
545
} ;
447
546
448
-
547
+
449
548
var url = new Uri ( "http://test.tesdomain.com:8080/test?q=2" ) ;
450
549
550
+ var httpRequestMock = MockRepository . GenerateMock < HttpRequestBase > ( ) ;
551
+ httpRequestMock . Stub ( r => r . Cookies ) . Return ( new HttpCookieCollection ( ) ) ;
552
+ httpRequestMock . Stub ( r => r . UserAgent ) . Return ( string . Empty ) ;
451
553
452
- Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri ,
453
- new HttpCookieCollection ( ) { } , string . Empty ) . Name == "integration1" , string . Empty ) ;
554
+ Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri , httpRequestMock ) . Name == "integration1" , string . Empty ) ;
454
555
}
455
556
456
557
[ Fact ]
@@ -499,8 +600,11 @@ public void GetMatchedIntegrationConfig_TwoTriggers_NotMatched()
499
600
500
601
var url = new Uri ( "http://test.tesdomain.com:8080/test?q=2" ) ;
501
602
603
+ var httpRequestMock = MockRepository . GenerateMock < HttpRequestBase > ( ) ;
604
+ httpRequestMock . Stub ( r => r . Cookies ) . Return ( new HttpCookieCollection ( ) ) ;
605
+ httpRequestMock . Stub ( r => r . UserAgent ) . Return ( string . Empty ) ;
502
606
503
- Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri , new HttpCookieCollection ( ) { } , string . Empty ) == null ) ;
607
+ Assert . True ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri , httpRequestMock ) == null ) ;
504
608
}
505
609
506
610
[ Fact ]
@@ -574,11 +678,12 @@ public void GetMatchedIntegrationConfig_ThreeIntegrationsInOrder_SecondMatched()
574
678
} ;
575
679
576
680
var url = new Uri ( "http://test.tesdomain.com:8080/test?q=2" ) ;
681
+
577
682
var httpRequestMock = MockRepository . GenerateMock < HttpRequestBase > ( ) ;
683
+ httpRequestMock . Stub ( r => r . Cookies ) . Return ( new HttpCookieCollection ( ) { new HttpCookie ( "c1" ) { Value = "Value1" } } ) ;
684
+ httpRequestMock . Stub ( r => r . UserAgent ) . Return ( string . Empty ) ;
578
685
579
- Assert . False ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri ,
580
- new HttpCookieCollection ( ) { new HttpCookie ( "c1" ) { Value = "Value1" } } , string . Empty ) . Name == "integration2" ) ;
686
+ Assert . False ( testObject . GetMatchedIntegrationConfig ( customerIntegration , url . AbsoluteUri , httpRequestMock ) . Name == "integration2" ) ;
581
687
}
582
688
}
583
- }
584
-
689
+ }
0 commit comments