6
6
7
7
use CrowdSec \Common \Client \RequestHandler \Curl ;
8
8
use CrowdSec \Common \Client \RequestHandler \FileGetContents ;
9
+ use CrowdSec \Common \Logger \ConsoleLog ;
9
10
use CrowdSec \Common \Logger \FileLog ;
10
11
use CrowdSec \LapiClient \Bouncer as BouncerClient ;
11
12
use CrowdSec \RemediationEngine \CacheStorage \AbstractCache ;
@@ -1186,9 +1187,12 @@ public function testCanVerifyIpInLiveMode(): void
1186
1187
1187
1188
/**
1188
1189
* @group integration
1190
+ * @group stream
1189
1191
*/
1190
1192
public function testCanVerifyIpInStreamMode (): void
1191
1193
{
1194
+
1195
+ $ this ->logger = new ConsoleLog ();
1192
1196
// Init context
1193
1197
$ this ->watcherClient ->setInitialState ();
1194
1198
// Init bouncer
@@ -1205,9 +1209,9 @@ public function testCanVerifyIpInStreamMode(): void
1205
1209
$ this ->addTlsConfig ($ bouncerConfigs , $ this ->useTls );
1206
1210
}
1207
1211
1208
- $ client = new BouncerClient ($ bouncerConfigs );
1212
+ $ client = new BouncerClient ($ bouncerConfigs, null , $ this -> logger );
1209
1213
$ cache = new PhpFiles ($ bouncerConfigs );
1210
- $ lapiRemediation = new LapiRemediation ($ bouncerConfigs , $ client , $ cache );
1214
+ $ lapiRemediation = new LapiRemediation ($ bouncerConfigs , $ client , $ cache, $ this -> logger );
1211
1215
$ bouncer = $ this ->getMockForAbstractClass (AbstractBouncer::class, [$ bouncerConfigs , $ lapiRemediation ]);
1212
1216
// Test cache adapter
1213
1217
$ cacheAdapter = $ bouncer ->getRemediationEngine ()->getCacheStorage ();
@@ -1225,16 +1229,16 @@ public function testCanVerifyIpInStreamMode(): void
1225
1229
1226
1230
// Reconfigure the bouncer to set maximum remediation level to "captcha"
1227
1231
$ bouncerConfigs ['bouncing_level ' ] = Constants::BOUNCING_LEVEL_FLEX ;
1228
- $ client = new BouncerClient ($ bouncerConfigs );
1232
+ $ client = new BouncerClient ($ bouncerConfigs, null , $ this -> logger );
1229
1233
$ cache = new PhpFiles ($ bouncerConfigs );
1230
- $ lapiRemediation = new LapiRemediation ($ bouncerConfigs , $ client , $ cache );
1234
+ $ lapiRemediation = new LapiRemediation ($ bouncerConfigs , $ client , $ cache, $ this -> logger );
1231
1235
$ bouncer = $ this ->getMockForAbstractClass (AbstractBouncer::class, [$ bouncerConfigs , $ lapiRemediation ]);
1232
1236
$ cappedRemediation = $ bouncer ->getRemediationForIp (TestHelpers::BAD_IP );
1233
1237
$ this ->assertEquals ('captcha ' , $ cappedRemediation , 'The remediation for the banned IP should now be "captcha" ' );
1234
1238
$ bouncerConfigs ['bouncing_level ' ] = Constants::BOUNCING_LEVEL_NORMAL ;
1235
- $ client = new BouncerClient ($ bouncerConfigs );
1239
+ $ client = new BouncerClient ($ bouncerConfigs, null , $ this -> logger );
1236
1240
$ cache = new PhpFiles ($ bouncerConfigs );
1237
- $ lapiRemediation = new LapiRemediation ($ bouncerConfigs , $ client , $ cache );
1241
+ $ lapiRemediation = new LapiRemediation ($ bouncerConfigs , $ client , $ cache, $ this -> logger );
1238
1242
$ bouncer = $ this ->getMockForAbstractClass (AbstractBouncer::class, [$ bouncerConfigs , $ lapiRemediation ]);
1239
1243
$ this ->assertEquals (
1240
1244
'bypass ' ,
@@ -1250,21 +1254,20 @@ public function testCanVerifyIpInStreamMode(): void
1250
1254
);
1251
1255
1252
1256
// Add and remove decision
1257
+ $ this ->logger ->info ('DEBUG ' , ['message ' => 'Start SecondState test ' ]);
1253
1258
$ this ->watcherClient ->setSecondState ();
1254
- // Wait to avoid false positive
1255
- sleep (2 );
1256
1259
1257
1260
// Pull updates
1258
1261
$ bouncer ->refreshBlocklistCache ();
1259
- // Wait to avoid false positive
1260
- sleep (2 );
1261
1262
1263
+ $ this ->logger ->info ('DEBUG ' , ['message ' => 'Will check 3.4.5.6 ' ]);
1262
1264
$ this ->assertEquals (
1263
1265
'ban ' ,
1264
1266
$ bouncer ->getRemediationForIp (TestHelpers::NEWLY_BAD_IP ),
1265
1267
'The new decision should now be added, so the previously clean IP should now be bad '
1266
1268
);
1267
1269
1270
+ $ this ->logger ->info ('DEBUG ' , ['message ' => 'Will check 1.2.3.4 ' ]);
1268
1271
$ this ->assertEquals (
1269
1272
'bypass ' ,
1270
1273
$ bouncer ->getRemediationForIp (TestHelpers::BAD_IP ),
@@ -1288,9 +1291,9 @@ public function testCanVerifyIpInStreamMode(): void
1288
1291
$ bouncerConfigs ['tls_verify_peer ' ] = true ;
1289
1292
}
1290
1293
1291
- $ client = new BouncerClient ($ bouncerConfigs );
1294
+ $ client = new BouncerClient ($ bouncerConfigs, null , $ this -> logger );
1292
1295
$ cache = new PhpFiles ($ bouncerConfigs );
1293
- $ lapiRemediation = new LapiRemediation ($ bouncerConfigs , $ client , $ cache );
1296
+ $ lapiRemediation = new LapiRemediation ($ bouncerConfigs , $ client , $ cache, $ this -> logger );
1294
1297
$ bouncer = $ this ->getMockForAbstractClass (AbstractBouncer::class, [$ bouncerConfigs , $ lapiRemediation ]);
1295
1298
1296
1299
$ this ->assertEquals (
0 commit comments