|
5 | 5 | namespace CrowdSecBouncer\Tests\Integration;
|
6 | 6 |
|
7 | 7 | use CrowdSec\Common\Logger\FileLog;
|
| 8 | +use CrowdSec\RemediationEngine\CacheStorage\CacheStorageException; |
8 | 9 | use CrowdSecBouncer\Bouncer;
|
9 | 10 | use CrowdSecBouncer\BouncerException;
|
10 | 11 | use CrowdSecBouncer\Constants;
|
@@ -186,6 +187,65 @@ private function addTlsConfig(&$bouncerConfigs, $tlsPath)
|
186 | 187 | $bouncerConfigs['tls_verify_peer'] = true;
|
187 | 188 | }
|
188 | 189 |
|
| 190 | + /** |
| 191 | + * @group integration |
| 192 | + * @dataProvider cacheAdapterConfigProvider |
| 193 | + */ |
| 194 | + public function testTestCacheConnexion($cacheAdapterName, $origCacheName) |
| 195 | + { |
| 196 | + $bouncer = new StandaloneBouncer(array_merge($this->configs, |
| 197 | + ['cache_system'=> $cacheAdapterName])); |
| 198 | + $error = ''; |
| 199 | + try { |
| 200 | + $bouncer->testCacheConnection(); |
| 201 | + } catch (\Exception $e){ |
| 202 | + $error = $e->getMessage(); |
| 203 | + } |
| 204 | + $this->assertEquals('', $error); |
| 205 | + |
| 206 | + // Test custom error handler for Memcached |
| 207 | + if($cacheAdapterName === 'memcached'){ |
| 208 | + $bouncer2 = new StandaloneBouncer(array_merge($this->configs, |
| 209 | + [ |
| 210 | + 'cache_system'=> $cacheAdapterName, |
| 211 | + 'memcached_dsn' => 'memcached://memcached:21', |
| 212 | + ])); |
| 213 | + |
| 214 | + $error = ''; |
| 215 | + try { |
| 216 | + $bouncer2->testCacheConnection(); |
| 217 | + } catch (BouncerException $e){ |
| 218 | + $error = $e->getMessage(); |
| 219 | + } |
| 220 | + PHPUnitUtil::assertRegExp( |
| 221 | + $this, |
| 222 | + '/Error while testing cache connection/', |
| 223 | + $error, |
| 224 | + 'Should have throw an error' |
| 225 | + ); |
| 226 | + } |
| 227 | + // Test bad dsn for redis |
| 228 | + if($cacheAdapterName === 'redis'){ |
| 229 | + $error = ''; |
| 230 | + try { |
| 231 | + $bouncer3 = new StandaloneBouncer(array_merge($this->configs, |
| 232 | + [ |
| 233 | + 'cache_system'=> $cacheAdapterName, |
| 234 | + 'redis_dsn' => 'redis://redis:21' |
| 235 | + ])); |
| 236 | + } catch (CacheStorageException $e){ |
| 237 | + $error = $e->getMessage(); |
| 238 | + } |
| 239 | + PHPUnitUtil::assertRegExp( |
| 240 | + $this, |
| 241 | + '/Error when creating/', |
| 242 | + $error, |
| 243 | + 'Should have throw an error' |
| 244 | + ); |
| 245 | + |
| 246 | + } |
| 247 | + } |
| 248 | + |
189 | 249 | public function testConstructAndSomeMethods()
|
190 | 250 | {
|
191 | 251 | unset($_SERVER['REMOTE_ADDR'] );
|
|
0 commit comments