Skip to content

Commit

Permalink
feat(*): Update Gregwar Captcha and add PHP 8.3 tests (#130)
Browse files Browse the repository at this point in the history
* feat(captcha): Update Gregwar/Captcha to 1.2.1 and remove fixes

* docs(user guide): Add api_connect_timeout mention

* test(8.3): Add tests for PHP 8.3

* test(fix): Fix ddev install

* test(*): Add PHP 8.3 test

* docs(user guide): Mention PHP 8.3
  • Loading branch information
julienloizelet authored Dec 7, 2023
1 parent 2920637 commit 247949f
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 80 deletions.
4 changes: 2 additions & 2 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if [ -z "$1" ]; then
exit 1
fi

commitTitle="$(cat $1 | head -n1)"
commitTitle="$(head -n 1 < "$1")"

# ignore merge
if echo "$commitTitle" | grep -qE "^Merge"; then
Expand All @@ -15,7 +15,7 @@ fi

# check commit message
REGEX='^(feat|fix|docs|style|refactor|ci|test|chore|comment)\(.*\)\:.*'
if ! echo "$commitTitle" | grep -qE ${REGEX}; then
if ! echo "$commitTitle" | grep -qE "${REGEX}"; then
echo "Your commit title '$commitTitle' did not follow conventional commit message rules:"
echo "Please comply with the regex ${REGEX}"
exit 1
Expand Down
11 changes: 8 additions & 3 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
runs-on: ubuntu-latest
Expand All @@ -42,7 +42,7 @@ jobs:
sudo apt-get -q update
sudo apt-get -q -y install libnss3-tools ddev
mkcert -install
ddev config global --instrumentation-opt-in=false --omit-containers=dba,ddev-ssh-agent
ddev config global --instrumentation-opt-in=false --omit-containers=ddev-ssh-agent
- name: Create empty PHP DDEV project
run: ddev config --project-type=php --project-name=crowdsec-bouncer-lib --php-version=${{ matrix.php-version }}
Expand All @@ -53,7 +53,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
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Create Release
# example: gh workflow run release.yml -f tag_name=v1.1.4 -f draft=true
on:
workflow_dispatch:
branches:
- main
inputs:
tag_name:
type: string
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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: Test suite
runs-on: ubuntu-latest
Expand All @@ -40,7 +40,7 @@ jobs:
sudo apt-get -q update
sudo apt-get -q -y install libnss3-tools ddev
mkcert -install
ddev config global --instrumentation-opt-in=false --omit-containers=dba,ddev-ssh-agent
ddev config global --instrumentation-opt-in=false --omit-containers=ddev-ssh-agent
- name: Create empty PHP DDEV project
run: ddev config --project-type=php --project-name=${{env.DDEV_PROJECT}} --php-version=${{ matrix.php-version }}
Expand All @@ -53,6 +53,11 @@ jobs:
ddev get julienloizelet/ddev-tools
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: ddev start

Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/) and th

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.

---


## [2.1.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v2.1.0) - 202?-??-??
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v2.0.0...v2.1.0)


### Changed

- Update `gregwar/captcha` from `1.2.0` to `1.2.1` and remove override fixes
- Update `crowdsec/common` dependency to `v2.2.0` (`api_connect_timeout` setting)
- Update `crowdsec/remediation-engine` dependency to `v3.2.0` (`api_connect_timeout` setting)


---

## [2.0.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v2.0.0) - 2023-04-13
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"require": {
"php": ">=7.2.5",
"crowdsec/remediation-engine": "^3.1.1",
"crowdsec/common": "^2.1.0",
"crowdsec/common": "^2.2.0",
"symfony/config": "^4.4.27 || ^5.2 || ^6.0",
"twig/twig": "^3.4.2",
"gregwar/captcha": "^1.2.0",
"gregwar/captcha": "^1.2.1",
"mlocati/ip-lib": "^1.18",
"ext-json": "*",
"ext-gd": "*"
Expand Down
10 changes: 7 additions & 3 deletions docs/USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Please note that first and foremost a CrowdSec agent must be installed on a serv
- Handle `ip`, `range` and `country` scoped decisions
- `Live mode` or `Stream mode`
- Support IpV4 and Ipv6 (Ipv6 range decisions are yet only supported in `Live mode`)
- Large PHP matrix compatibility: 7.2, 7.3, 7.4, 8.0, 8.1 and 8.2
- Large PHP matrix compatibility: 7.2, 7.3, 7.4, 8.0, 8.1, 8.2 and 8.3
- Built-in support for the most known cache systems Redis, Memcached and PhpFiles
- Clear, prune and refresh the bouncer cache
- Cap remediation level (ex: for sensitives websites: ban will be capped to captcha)
Expand Down Expand Up @@ -240,8 +240,12 @@ Below is the list of available settings:
- `api_url`: Define the URL to your Local API server, default to `http://localhost:8080`.


- `api_timeout`: In seconds. The timeout when calling Local API. Default to 120 sec. If set to a negative value,
timeout will be unlimited.
- `api_timeout`: In seconds. The global timeout when calling Local API. Default to 120 sec. If set to a negative value
or 0, timeout will be unlimited.


- `api_connect_timeout`: In seconds. **Only for curl**. The timeout for the connection phase when calling Local API.
Default to 300 sec. If set to a 0, timeout will be unlimited.


### Cache
Expand Down
4 changes: 1 addition & 3 deletions src/AbstractBouncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use CrowdSec\RemediationEngine\CacheStorage\Memcached;
use CrowdSec\RemediationEngine\CacheStorage\PhpFiles;
use CrowdSec\RemediationEngine\CacheStorage\Redis;
use CrowdSecBouncer\Fixes\Gregwar\Captcha\CaptchaBuilder;
use Gregwar\Captcha\CaptchaBuilder;
use Gregwar\Captcha\PhraseBuilder;
use IPLib\Factory;
use Monolog\Handler\NullHandler;
Expand Down Expand Up @@ -108,8 +108,6 @@ public function clearCache(): bool

/**
* Retrieve Bouncer configuration by name.
*
* @return mixed
*/
public function getConfig(string $name)
{
Expand Down
3 changes: 0 additions & 3 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class Configuration extends AbstractConfiguration
];

/**
* {@inheritdoc}
*
* @throws \InvalidArgumentException
*/
public function getConfigTreeBuilder(): TreeBuilder
Expand Down Expand Up @@ -157,7 +155,6 @@ private function addDebugNodes($rootNode)
}

/**
* @param $rootNode
* @return void
*/
private function addTemplateNodes($rootNode)
Expand Down
58 changes: 0 additions & 58 deletions src/Fixes/Gregwar/Captcha/CaptchaBuilder.php

This file was deleted.

1 change: 1 addition & 0 deletions tests/Integration/WatcherClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ protected function getFinalScope($scope, $value)
{
$scope = (Constants::SCOPE_IP === $scope && 2 === count(explode('/', $value))) ? Constants::SCOPE_RANGE :
$scope;

/**
* Must use capital first letter as the crowdsec agent seems to query with first capital letter
* during getStreamDecisions.
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/AbstractBouncerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
* @covers \CrowdSecBouncer\AbstractBouncer::shouldBounceCurrentIp
* @covers \CrowdSecBouncer\AbstractBouncer::checkCaptcha
* @covers \CrowdSecBouncer\AbstractBouncer::buildCaptchaCouple
* @covers \CrowdSecBouncer\Fixes\Gregwar\Captcha\CaptchaBuilder::writePhrase
* @covers \CrowdSecBouncer\AbstractBouncer::getCache
* @covers \CrowdSecBouncer\AbstractBouncer::getBanHtml
* @covers \CrowdSecBouncer\Template::__construct
Expand Down
1 change: 0 additions & 1 deletion tools/coding-standards/psalm/psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<directory name="../../../src" />
<ignoreFiles>
<directory name="../../../vendor" />
<directory name="../../../src/Fixes" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
Expand Down

0 comments on commit 247949f

Please sign in to comment.