Skip to content

Commit e62dce8

Browse files
test(metrics): Update test for new getRemediationForIp return
1 parent 07ab2e0 commit e62dce8

File tree

2 files changed

+26
-37
lines changed

2 files changed

+26
-37
lines changed

tests/Integration/GeolocationTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ public function testCanVerifyIpAndCountryWithMaxmindInLiveMode(array $maxmindCon
121121

122122
$this->assertEquals(
123123
'captcha',
124-
$bouncer->getRemediationForIp(TestHelpers::IP_JAPAN),
124+
$bouncer->getRemediationForIp(TestHelpers::IP_JAPAN)['remediation'],
125125
'Get decisions for a clean IP but bad country (captcha)'
126126
);
127127

128128
$this->assertEquals(
129129
'bypass',
130-
$bouncer->getRemediationForIp(TestHelpers::IP_FRANCE),
130+
$bouncer->getRemediationForIp(TestHelpers::IP_FRANCE)['remediation'],
131131
'Get decisions for a clean IP and clean country'
132132
);
133133

@@ -139,7 +139,7 @@ public function testCanVerifyIpAndCountryWithMaxmindInLiveMode(array $maxmindCon
139139

140140
$this->assertEquals(
141141
'bypass',
142-
$bouncer->getRemediationForIp(TestHelpers::IP_JAPAN),
142+
$bouncer->getRemediationForIp(TestHelpers::IP_JAPAN)['remediation'],
143143
'Get decisions for a clean IP and bad country but with geolocation disabled'
144144
);
145145

@@ -152,13 +152,13 @@ public function testCanVerifyIpAndCountryWithMaxmindInLiveMode(array $maxmindCon
152152

153153
$this->assertEquals(
154154
'ban',
155-
$bouncer->getRemediationForIp(TestHelpers::IP_JAPAN),
155+
$bouncer->getRemediationForIp(TestHelpers::IP_JAPAN)['remediation'],
156156
'Get decisions for a bad IP (ban) and bad country (captcha)'
157157
);
158158

159159
$this->assertEquals(
160160
'ban',
161-
$bouncer->getRemediationForIp(TestHelpers::IP_FRANCE),
161+
$bouncer->getRemediationForIp(TestHelpers::IP_FRANCE)['remediation'],
162162
'Get decisions for a bad IP (ban) and clean country'
163163
);
164164
}
@@ -198,7 +198,7 @@ public function testCanVerifyIpAndCountryWithMaxmindInStreamMode(array $maxmindC
198198

199199
$this->assertEquals(
200200
'captcha',
201-
$bouncer->getRemediationForIp(TestHelpers::IP_JAPAN),
201+
$bouncer->getRemediationForIp(TestHelpers::IP_JAPAN)['remediation'],
202202
'Should captcha a clean IP coming from a bad country (captcha)'
203203
);
204204

@@ -207,7 +207,7 @@ public function testCanVerifyIpAndCountryWithMaxmindInStreamMode(array $maxmindC
207207

208208
$this->assertEquals(
209209
'captcha',
210-
$bouncer->getRemediationForIp(TestHelpers::IP_JAPAN),
210+
$bouncer->getRemediationForIp(TestHelpers::IP_JAPAN)['remediation'],
211211
'Should still captcha a bad IP (ban) coming from a bad country (captcha) as cache has not been refreshed'
212212
);
213213

@@ -216,7 +216,7 @@ public function testCanVerifyIpAndCountryWithMaxmindInStreamMode(array $maxmindC
216216

217217
$this->assertEquals(
218218
'ban',
219-
$bouncer->getRemediationForIp(TestHelpers::IP_JAPAN),
219+
$bouncer->getRemediationForIp(TestHelpers::IP_JAPAN)['remediation'],
220220
'The new decision should now be added, so the previously captcha IP should now be ban'
221221
);
222222
}

tests/Integration/IpVerificationTest.php

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -305,25 +305,25 @@ public function testCanVerifyIpInLiveModeWithCacheSystem($cacheAdapterName, $ori
305305

306306
$this->assertEquals(
307307
'ban',
308-
$bouncer->getRemediationForIp(TestHelpers::BAD_IP),
308+
$bouncer->getRemediationForIp(TestHelpers::BAD_IP)['remediation'],
309309
'Get decisions for a bad IP (for the first time, it should be a cache miss)'
310310
);
311311

312312
$this->assertEquals(
313313
'ban',
314-
$bouncer->getRemediationForIp(TestHelpers::BAD_IP),
314+
$bouncer->getRemediationForIp(TestHelpers::BAD_IP)['remediation'],
315315
'Call the same thing for the second time (now it should be a cache hit)'
316316
);
317317

318-
$cleanRemediation1stCall = $bouncer->getRemediationForIp(TestHelpers::CLEAN_IP);
318+
$cleanRemediation1stCall = $bouncer->getRemediationForIp(TestHelpers::CLEAN_IP)['remediation'];
319319
$this->assertEquals(
320320
'bypass',
321321
$cleanRemediation1stCall,
322322
'Get decisions for a clean IP for the first time (it should be a cache miss)'
323323
);
324324

325325
// Call the same thing for the second time (now it should be a cache hit)
326-
$cleanRemediation2ndCall = $bouncer->getRemediationForIp(TestHelpers::CLEAN_IP);
326+
$cleanRemediation2ndCall = $bouncer->getRemediationForIp(TestHelpers::CLEAN_IP)['remediation'];
327327
$this->assertEquals('bypass', $cleanRemediation2ndCall);
328328

329329
// Prune cache
@@ -336,13 +336,13 @@ public function testCanVerifyIpInLiveModeWithCacheSystem($cacheAdapterName, $ori
336336

337337
// Call one more time (should miss as the cache has been cleared)
338338

339-
$remediation3rdCall = $bouncer->getRemediationForIp(TestHelpers::BAD_IP);
339+
$remediation3rdCall = $bouncer->getRemediationForIp(TestHelpers::BAD_IP)['remediation'];
340340
$this->assertEquals('ban', $remediation3rdCall);
341341

342342
// Reconfigure the bouncer to set maximum remediation level to "captcha"
343343
$bouncerConfigs['bouncing_level'] = Constants::BOUNCING_LEVEL_FLEX;
344344
$bouncer = new Bouncer($bouncerConfigs, $this->logger);
345-
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IP);
345+
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IP)['remediation'];
346346
$this->assertEquals('captcha', $cappedRemediation, 'The remediation for the banned IP should now be "captcha"');
347347
// Reset the max remediation level to its origin state
348348
$bouncerConfigs['bouncing_level'] = Constants::BOUNCING_LEVEL_NORMAL;
@@ -357,7 +357,7 @@ public function testCanVerifyIpInLiveModeWithCacheSystem($cacheAdapterName, $ori
357357
TestHelpers::BAD_IP . '/' . TestHelpers::LARGE_IPV4_RANGE,
358358
'ban'
359359
);
360-
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IP);
360+
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IP)['remediation'];
361361
$this->assertEquals(
362362
'ban',
363363
$cappedRemediation,
@@ -373,7 +373,7 @@ public function testCanVerifyIpInLiveModeWithCacheSystem($cacheAdapterName, $ori
373373
TestHelpers::BAD_IPV6 . '/' . TestHelpers::IPV6_RANGE,
374374
'ban'
375375
);
376-
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IPV6);
376+
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IPV6)['remediation'];
377377
$this->assertEquals(
378378
'ban',
379379
$cappedRemediation,
@@ -387,7 +387,7 @@ public function testCanVerifyIpInLiveModeWithCacheSystem($cacheAdapterName, $ori
387387
TestHelpers::BAD_IPV6,
388388
'ban'
389389
);
390-
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IPV6);
390+
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IPV6)['remediation'];
391391
$this->assertEquals(
392392
'ban',
393393
$cappedRemediation,
@@ -432,27 +432,27 @@ public function testCanVerifyIpInStreamModeWithCacheSystem($cacheAdapterName, $o
432432

433433
$this->assertEquals(
434434
'ban',
435-
$bouncer->getRemediationForIp(TestHelpers::BAD_IP),
435+
$bouncer->getRemediationForIp(TestHelpers::BAD_IP)['remediation'],
436436
'Get decisions for a bad IP for the first time (as the cache has been warmed up should be a cache hit)'
437437
);
438438

439439
// Reconfigure the bouncer to set maximum remediation level to "captcha"
440440
$bouncerConfigs['bouncing_level'] = Constants::BOUNCING_LEVEL_FLEX;
441441
$bouncer = new Bouncer($bouncerConfigs, $this->logger);
442-
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IP);
442+
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IP)['remediation'];
443443
$this->assertEquals('captcha', $cappedRemediation, 'The remediation for the banned IP should now be "captcha"');
444444
$bouncerConfigs['bouncing_level'] = Constants::BOUNCING_LEVEL_NORMAL;
445445
$bouncer = new Bouncer($bouncerConfigs, $this->logger);
446446
$this->assertEquals(
447447
'bypass',
448-
$bouncer->getRemediationForIp(TestHelpers::CLEAN_IP),
448+
$bouncer->getRemediationForIp(TestHelpers::CLEAN_IP)['remediation'],
449449
'Get decisions for a clean IP for the first time (as the cache has been warmed up should be a cache hit)'
450450
);
451451

452452
// Preload the remediation to prepare the next tests.
453453
$this->assertEquals(
454454
'bypass',
455-
$bouncer->getRemediationForIp(TestHelpers::NEWLY_BAD_IP),
455+
$bouncer->getRemediationForIp(TestHelpers::NEWLY_BAD_IP)['remediation'],
456456
'Preload the bypass remediation to prepare the next tests'
457457
);
458458

@@ -464,13 +464,13 @@ public function testCanVerifyIpInStreamModeWithCacheSystem($cacheAdapterName, $o
464464

465465
$this->assertEquals(
466466
'ban',
467-
$bouncer->getRemediationForIp(TestHelpers::NEWLY_BAD_IP),
467+
$bouncer->getRemediationForIp(TestHelpers::NEWLY_BAD_IP)['remediation'],
468468
'The new decision should now be added, so the previously clean IP should now be bad'
469469
);
470470

471471
$this->assertEquals(
472472
'bypass',
473-
$bouncer->getRemediationForIp(TestHelpers::BAD_IP),
473+
$bouncer->getRemediationForIp(TestHelpers::BAD_IP)['remediation'],
474474
'The old decisions should now be removed, so the previously bad IP should now be clean'
475475
);
476476

@@ -497,7 +497,7 @@ public function testCanVerifyIpInStreamModeWithCacheSystem($cacheAdapterName, $o
497497

498498
$this->assertEquals(
499499
'ban',
500-
$bouncer->getRemediationForIp(TestHelpers::NEWLY_BAD_IP),
500+
$bouncer->getRemediationForIp(TestHelpers::NEWLY_BAD_IP)['remediation'],
501501
'The cache warm up should be stored across each instantiation'
502502
);
503503

@@ -520,13 +520,13 @@ public function testCanVerifyIpInStreamModeWithCacheSystem($cacheAdapterName, $o
520520
// Pull updates
521521
$bouncer->refreshBlocklistCache();
522522

523-
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IP);
523+
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IP)['remediation'];
524524
$this->assertEquals(
525525
'ban',
526526
$cappedRemediation,
527527
'The remediation for the banned IP with a large range should be "ban" even in stream mode'
528528
);
529-
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IPV6);
529+
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IPV6)['remediation'];
530530
$this->assertEquals(
531531
'bypass',
532532
$cappedRemediation,
@@ -710,12 +710,6 @@ public function testAppSecFlow()
710710
);
711711
}
712712

713-
$this->assertEquals(
714-
['bypass' => 1],
715-
$originCountItem['clean'],
716-
'The origin count for clean should be 1'
717-
);
718-
719713
// Test 3: clean IP and clean request
720714
$bouncer->clearCache();
721715
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
@@ -743,11 +737,6 @@ public function testAppSecFlow()
743737
'The origin count for clean appsec should be 1'
744738
);
745739
}
746-
$this->assertEquals(
747-
['bypass' => 1],
748-
$originCountItem['clean'],
749-
'The origin count for clean should be 1'
750-
);
751740
}
752741

753742
/**

0 commit comments

Comments
 (0)