Skip to content

Commit 6ba2a18

Browse files
test(debug): Add log for debugging failing test
1 parent 848ef59 commit 6ba2a18

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

tests/Integration/AbstractBouncerTest.php

+15-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use CrowdSec\Common\Client\RequestHandler\Curl;
88
use CrowdSec\Common\Client\RequestHandler\FileGetContents;
9+
use CrowdSec\Common\Logger\ConsoleLog;
910
use CrowdSec\Common\Logger\FileLog;
1011
use CrowdSec\LapiClient\Bouncer as BouncerClient;
1112
use CrowdSec\RemediationEngine\CacheStorage\AbstractCache;
@@ -1186,9 +1187,12 @@ public function testCanVerifyIpInLiveMode(): void
11861187

11871188
/**
11881189
* @group integration
1190+
* @group stream
11891191
*/
11901192
public function testCanVerifyIpInStreamMode(): void
11911193
{
1194+
1195+
$this->logger = new ConsoleLog();
11921196
// Init context
11931197
$this->watcherClient->setInitialState();
11941198
// Init bouncer
@@ -1205,9 +1209,9 @@ public function testCanVerifyIpInStreamMode(): void
12051209
$this->addTlsConfig($bouncerConfigs, $this->useTls);
12061210
}
12071211

1208-
$client = new BouncerClient($bouncerConfigs);
1212+
$client = new BouncerClient($bouncerConfigs, null, $this->logger);
12091213
$cache = new PhpFiles($bouncerConfigs);
1210-
$lapiRemediation = new LapiRemediation($bouncerConfigs, $client, $cache);
1214+
$lapiRemediation = new LapiRemediation($bouncerConfigs, $client, $cache, $this->logger);
12111215
$bouncer = $this->getMockForAbstractClass(AbstractBouncer::class, [$bouncerConfigs, $lapiRemediation]);
12121216
// Test cache adapter
12131217
$cacheAdapter = $bouncer->getRemediationEngine()->getCacheStorage();
@@ -1225,16 +1229,16 @@ public function testCanVerifyIpInStreamMode(): void
12251229

12261230
// Reconfigure the bouncer to set maximum remediation level to "captcha"
12271231
$bouncerConfigs['bouncing_level'] = Constants::BOUNCING_LEVEL_FLEX;
1228-
$client = new BouncerClient($bouncerConfigs);
1232+
$client = new BouncerClient($bouncerConfigs, null, $this->logger);
12291233
$cache = new PhpFiles($bouncerConfigs);
1230-
$lapiRemediation = new LapiRemediation($bouncerConfigs, $client, $cache);
1234+
$lapiRemediation = new LapiRemediation($bouncerConfigs, $client, $cache, $this->logger);
12311235
$bouncer = $this->getMockForAbstractClass(AbstractBouncer::class, [$bouncerConfigs, $lapiRemediation]);
12321236
$cappedRemediation = $bouncer->getRemediationForIp(TestHelpers::BAD_IP);
12331237
$this->assertEquals('captcha', $cappedRemediation, 'The remediation for the banned IP should now be "captcha"');
12341238
$bouncerConfigs['bouncing_level'] = Constants::BOUNCING_LEVEL_NORMAL;
1235-
$client = new BouncerClient($bouncerConfigs);
1239+
$client = new BouncerClient($bouncerConfigs,null, $this->logger);
12361240
$cache = new PhpFiles($bouncerConfigs);
1237-
$lapiRemediation = new LapiRemediation($bouncerConfigs, $client, $cache);
1241+
$lapiRemediation = new LapiRemediation($bouncerConfigs, $client, $cache, $this->logger);
12381242
$bouncer = $this->getMockForAbstractClass(AbstractBouncer::class, [$bouncerConfigs, $lapiRemediation]);
12391243
$this->assertEquals(
12401244
'bypass',
@@ -1250,21 +1254,20 @@ public function testCanVerifyIpInStreamMode(): void
12501254
);
12511255

12521256
// Add and remove decision
1257+
$this->logger->info('DEBUG', ['message' => 'Start SecondState test']);
12531258
$this->watcherClient->setSecondState();
1254-
// Wait to avoid false positive
1255-
sleep(2);
12561259

12571260
// Pull updates
12581261
$bouncer->refreshBlocklistCache();
1259-
// Wait to avoid false positive
1260-
sleep(2);
12611262

1263+
$this->logger->info('DEBUG', ['message' => 'Will check 3.4.5.6']);
12621264
$this->assertEquals(
12631265
'ban',
12641266
$bouncer->getRemediationForIp(TestHelpers::NEWLY_BAD_IP),
12651267
'The new decision should now be added, so the previously clean IP should now be bad'
12661268
);
12671269

1270+
$this->logger->info('DEBUG', ['message' => 'Will check 1.2.3.4']);
12681271
$this->assertEquals(
12691272
'bypass',
12701273
$bouncer->getRemediationForIp(TestHelpers::BAD_IP),
@@ -1288,9 +1291,9 @@ public function testCanVerifyIpInStreamMode(): void
12881291
$bouncerConfigs['tls_verify_peer'] = true;
12891292
}
12901293

1291-
$client = new BouncerClient($bouncerConfigs);
1294+
$client = new BouncerClient($bouncerConfigs, null, $this->logger);
12921295
$cache = new PhpFiles($bouncerConfigs);
1293-
$lapiRemediation = new LapiRemediation($bouncerConfigs, $client, $cache);
1296+
$lapiRemediation = new LapiRemediation($bouncerConfigs, $client, $cache, $this->logger);
12941297
$bouncer = $this->getMockForAbstractClass(AbstractBouncer::class, [$bouncerConfigs, $lapiRemediation]);
12951298

12961299
$this->assertEquals(

0 commit comments

Comments
 (0)