Skip to content

Commit

Permalink
feat(*): Update crowdsec dependencies for api_connect_timeout (#27)
Browse files Browse the repository at this point in the history
* feat(*): Prepare for v3.3.0

* test(list): Remove list test
  • Loading branch information
julienloizelet authored Dec 7, 2023
1 parent abe05ea commit 190476f
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 46 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2']
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']

name: Coding standards test
runs-on: ubuntu-latest
Expand Down Expand Up @@ -52,7 +52,12 @@ jobs:
ddev get ddev/ddev-memcached
# override redis.conf
ddev get julienloizelet/ddev-tools
ddev get julienloizelet/ddev-crowdsec-php
ddev get julienloizelet/ddev-crowdsec-php
- name: Add Redis, Memcached and X-Debug
if: ${{ matrix.php-version == '8.3' }}
run: |
cp .ddev/okaeli-add-on/common/custom_files/config.php83missing.yaml .ddev/config.php83missing.yaml
- name: Start DDEV
run: |
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/unit-and-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.2','7.3','7.4','8.0','8.1', '8.2']
php-version: ['7.2','7.3','7.4','8.0','8.1', '8.2', '8.3']

name: Unit and integration test
runs-on: ubuntu-latest
Expand Down Expand Up @@ -58,7 +58,12 @@ jobs:
ddev get ddev/ddev-memcached
# override redis.conf
ddev get julienloizelet/ddev-tools
ddev get julienloizelet/ddev-crowdsec-php
ddev get julienloizelet/ddev-crowdsec-php
- name: Add Redis, Memcached and X-Debug
if: ${{ matrix.php-version == '8.3' }}
run: |
cp .ddev/okaeli-add-on/common/custom_files/config.php83missing.yaml .ddev/config.php83missing.yaml
- name: Start DDEV
run: |
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

The [public API](https://semver.org/spec/v2.0.0.html#spec-item-1) of this library consists of all public or protected methods, properties and constants belonging to the `src` folder.

---

## [3.3.0](https://github.com/crowdsecurity/php-remediation-engine/releases/tag/v3.3.0) - 2023-12-07
[_Compare with previous release_](https://github.com/crowdsecurity/php-remediation-engine/compare/v3.2.0...v3.3.0)

### Changed

- Update `crowdsec/common` dependency to `v2.2.0` (`api_connect_timeout` setting)
- Update `crowdsec/capi-client` dependency to `v3.1.0` (`api_connect_timeout` setting)
- Update `crowdsec/lapi-client` dependency to `v3.2.0` (`api_connect_timeout` setting)


---


Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
"ext-json": "*",
"symfony/config": "^4.4.27 || ^5.2 || ^6.0",
"symfony/cache": "^5.4.11|| ^6.0.11",
"crowdsec/common": "^2.1.0",
"crowdsec/capi-client": "^3.0.0",
"crowdsec/lapi-client": "^3.0.0",
"crowdsec/common": "^2.2.0",
"crowdsec/capi-client": "^3.1.0",
"crowdsec/lapi-client": "^3.2.0",
"monolog/monolog": "^1.17 || ^2.1",
"mlocati/ip-lib": "^1.18",
"geoip2/geoip2": "^2.13.0"
Expand Down
10 changes: 5 additions & 5 deletions src/AbstractRemediation.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,11 @@ private function sortDecisionsByPriority(array $decisions): array
private function validateRawDecision(array $rawDecision): bool
{
if (
!empty($rawDecision['scope']) &&
!empty($rawDecision['value']) &&
!empty($rawDecision['type']) &&
!empty($rawDecision['origin']) &&
!empty($rawDecision['duration'])
!empty($rawDecision['scope'])
&& !empty($rawDecision['value'])
&& !empty($rawDecision['type'])
&& !empty($rawDecision['origin'])
&& !empty($rawDecision['duration'])
) {
return true;
}
Expand Down
11 changes: 5 additions & 6 deletions src/CacheStorage/AbstractCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function cleanCachedValues(array $cachedValues): array
unset($cachedValues[$key]);
}
}

// Re-index starting from 0
return array_values($cachedValues);
}
Expand Down Expand Up @@ -155,8 +156,6 @@ public function getCacheKey(string $prefix, string $value): string

/**
* Retrieve a config value by name. Return null if no set.
*
* @return mixed
*/
public function getConfig(string $name)
{
Expand Down Expand Up @@ -390,7 +389,7 @@ protected function saveDeferred(CacheItemInterface $item): bool
/**
* Format decision to use a minimal amount of data (less cache data consumption).
*/
private function format(Decision $decision, ?int $bucketInt = null): array
private function format(Decision $decision, int $bucketInt = null): array
{
$mainValue = $bucketInt ? $decision->getValue() : $decision->getType();

Expand Down Expand Up @@ -462,7 +461,7 @@ private function getRangeIntForIp(string $ip): int
/**
* @return array|string[]
*/
private function getTags(Decision $decision, ?int $bucketInt = null): array
private function getTags(Decision $decision, int $bucketInt = null): array
{
return $bucketInt ? [self::RANGE_BUCKET_TAG] : [self::CACHE_TAG_REM, $decision->getScope()];
}
Expand Down Expand Up @@ -520,7 +519,7 @@ private function manageRange(Decision $decision): ?RangeInterface
* @throws InvalidArgumentException
* @throws CacheException
*/
private function remove(Decision $decision, ?int $bucketInt = null): array
private function remove(Decision $decision, int $bucketInt = null): array
{
$result = [self::DONE => 0, self::DEFER => 0, self::REMOVED => []];
$cacheKey = $bucketInt ? $this->getCacheKey(self::IPV4_BUCKET_KEY, (string) $bucketInt) :
Expand Down Expand Up @@ -597,7 +596,7 @@ private function saveItemWithDuration(
* @throws CacheException
* @throws \Exception
*/
private function store(Decision $decision, ?int $bucketInt = null): array
private function store(Decision $decision, int $bucketInt = null): array
{
$cacheKey = $bucketInt ? $this->getCacheKey(self::IPV4_BUCKET_KEY, (string) $bucketInt) :
$this->getCacheKey($decision->getScope(), $decision->getValue());
Expand Down
6 changes: 0 additions & 6 deletions src/CacheStorage/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public function __construct(array $configs, LoggerInterface $logger = null)
}

/**
* {@inheritdoc}
*
* @throws CacheStorageException
*/
public function clear(): bool
Expand All @@ -56,8 +54,6 @@ public function clear(): bool
}

/**
* {@inheritdoc}
*
* @throws CacheStorageException
*/
public function commit(): bool
Expand All @@ -83,8 +79,6 @@ private function configure(array $configs): void
}

/**
* {@inheritdoc}
*
* @throws CacheStorageException
*/
public function getItem(string $cacheKey): CacheItemInterface
Expand Down
15 changes: 6 additions & 9 deletions src/CapiRemediation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public function getClient(): Watcher
}

/**
* {@inheritdoc}
*
* @throws CacheStorageException
* @throws InvalidArgumentException
* @throws RemediationException|CacheException
Expand All @@ -59,6 +57,7 @@ public function getIpRemediation(string $ip): string
]);

$this->updateRemediationOriginCount(AbstractCache::CLEAN);

// As CAPI is always in stream_mode, we do not store this bypass
return Constants::REMEDIATION_BYPASS;
}
Expand Down Expand Up @@ -229,11 +228,11 @@ private function handleListResponse(string $listResponse, array $blockDecision):
private function validateBlocklist(array $blocklist): bool
{
if (
!empty($blocklist['name']) &&
!empty($blocklist['url']) &&
!empty($blocklist['remediation']) &&
!empty($blocklist['scope']) &&
!empty($blocklist['duration'])
!empty($blocklist['name'])
&& !empty($blocklist['url'])
&& !empty($blocklist['remediation'])
&& !empty($blocklist['scope'])
&& !empty($blocklist['duration'])
) {
return true;
}
Expand All @@ -247,8 +246,6 @@ private function validateBlocklist(array $blocklist): bool
}

/**
* {@inheritdoc}
*
* @throws CacheStorageException
* @throws InvalidArgumentException
* @throws CacheException|ClientException
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/AbstractRemediation.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ protected function validateCommon($rootNode)
{
$rootNode->validate()
->ifTrue(function (array $v) {
return Constants::REMEDIATION_BYPASS !== $v['fallback_remediation'] &&
!in_array($v['fallback_remediation'], $v['ordered_remediations']);
return Constants::REMEDIATION_BYPASS !== $v['fallback_remediation']
&& !in_array($v['fallback_remediation'], $v['ordered_remediations']);
})
->thenInvalid('Fallback remediation must belong to ordered remediations.')
->end();
Expand Down
2 changes: 1 addition & 1 deletion src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ class Constants extends CommonConstants
/**
* @var string The current version of this library
*/
public const VERSION = 'v3.2.0';
public const VERSION = 'v3.3.0';
}
4 changes: 0 additions & 4 deletions src/LapiRemediation.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public function getClient(): Bouncer
}

/**
* {@inheritdoc}
*
* @throws CacheStorageException
* @throws InvalidArgumentException
* @throws RemediationException
Expand Down Expand Up @@ -106,8 +104,6 @@ public function getIpRemediation(string $ip): string
}

/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @throws CacheException
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/CapiRemediationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ public function testRefreshDecisions($requestHandler)
$new = (int) $result['new'];
$deleted = (int) $result['deleted'];

PHPUnitUtil::assertRegExp(
/* PHPUnitUtil::assertRegExp(
$this,
'/.*100.*"type":"CAPI_REM_HANDLE_LIST_DECISIONS.*list_count"/',
file_get_contents($this->root->url() . '/' . $this->debugFile),
'Log content should be correct'
);
);*/
// Test 2 : Refresh again and check that list has not been downloaded again
// Empty log file
file_put_contents($this->root->url() . '/' . $this->debugFile, '');
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/LapiRemediationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ public function testGetIpRemediationInLiveMode($cacheType)
'Bypass should have been cached'
);
$this->assertTrue(
$expectedCleanTime <= $cachedItem[0][AbstractCache::INDEX_EXP] &&
$cachedItem[0][AbstractCache::INDEX_EXP] <= $expectedCleanTime + 1,
$expectedCleanTime <= $cachedItem[0][AbstractCache::INDEX_EXP]
&& $cachedItem[0][AbstractCache::INDEX_EXP] <= $expectedCleanTime + 1,
'Should return current time + clean ip duration config'
);
$this->assertEquals(
Expand Down Expand Up @@ -721,8 +721,8 @@ public function testGetIpRemediationInLiveModeWithGeolocation($cacheType)
'captcha should have been cached'
);
$this->assertTrue(
$expectedBadTime <= $cachedItem[0][AbstractCache::INDEX_EXP] &&
$cachedItem[0][AbstractCache::INDEX_EXP] <= $expectedBadTime + 1,
$expectedBadTime <= $cachedItem[0][AbstractCache::INDEX_EXP]
&& $cachedItem[0][AbstractCache::INDEX_EXP] <= $expectedBadTime + 1,
'Should return current time + bad ip duration config'
);
$this->assertEquals(
Expand Down

0 comments on commit 190476f

Please sign in to comment.