Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ on:
paths-ignore:
- '**.md'
workflow_dispatch:
inputs:
coverage_report:
type: boolean
description: Generate PHPUNIT Code Coverage report
default: false

jobs:
coding-standards:
Expand Down Expand Up @@ -80,3 +85,27 @@ jobs:

- name: Run PSALM
run: ddev psalm ./${{env.EXTENSION_PATH}}/tools/coding-standards ./${{env.EXTENSION_PATH}}/tools/coding-standards/psalm

- name: Prepare for Code Coverage
if: github.event.inputs.coverage_report == 'true'
run: |
cp .ddev/additional_docker_compose/docker-compose.crowdsec.yaml .ddev/docker-compose.crowdsec.yaml
mkdir ${{ github.workspace }}/cfssl
cp -r .ddev/custom_files/crowdsec/cfssl/* ${{ github.workspace }}/cfssl
ddev restart
ddev maxmind-download DEFAULT GeoLite2-City /var/www/html/${{env.EXTENSION_PATH}}/tests
ddev maxmind-download DEFAULT GeoLite2-Country /var/www/html/${{env.EXTENSION_PATH}}/tests
cd ${{env.EXTENSION_PATH}}/tests
sha256sum -c GeoLite2-Country.tar.gz.sha256.txt
sha256sum -c GeoLite2-City.tar.gz.sha256.txt
tar -xf GeoLite2-Country.tar.gz
tar -xf GeoLite2-City.tar.gz
rm GeoLite2-Country.tar.gz GeoLite2-Country.tar.gz.sha256.txt GeoLite2-City.tar.gz GeoLite2-City.tar.gz.sha256.txt
echo "BOUNCER_KEY=$(ddev create-bouncer)" >> $GITHUB_ENV

- name: Run PHPUNIT Code Coverage
if: github.event.inputs.coverage_report == 'true'
run: |
ddev xdebug
ddev exec XDEBUG_MODE=coverage BOUNCER_KEY=${{ env.BOUNCER_KEY }} AGENT_TLS_PATH=/var/www/html/cfssl LAPI_URL=https://crowdsec:8080 MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./${{env.EXTENSION_PATH}}/tools/coding-standards/vendor/bin/phpunit --configuration ./${{env.EXTENSION_PATH}}/tools/coding-standards/phpunit/phpunit.xml --coverage-text=./${{env.EXTENSION_PATH}}/coding-standards/phpunit/code-coverage/report.txt
cat ${{env.EXTENSION_PATH}}/coding-standards/phpunit/code-coverage/report.txt
78 changes: 72 additions & 6 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ jobs:
cp .ddev/additional_docker_compose/docker-compose.playwright.yaml .ddev/docker-compose.playwright.yaml
mkdir ${{ github.workspace }}/cfssl
cp -r .ddev/custom_files/crowdsec/cfssl/* ${{ github.workspace }}/cfssl
ls -l ${{ github.workspace }}/cfssl
ddev start

- name: Set BOUNCER_KEY and PROXY_IP env
Expand All @@ -84,7 +83,11 @@ jobs:
run: |
ddev composer update --working-dir ./${{env.EXTENSION_PATH}}

- name: Prepare PHP UNIT tests
- name: Run "Unit Tests"
run: |
ddev exec /usr/bin/php ./${{env.EXTENSION_PATH}}/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./${{env.EXTENSION_PATH}}/tests/Unit

- name: Prepare PHP Integration and end-to-end tests
run: |
ddev maxmind-download DEFAULT GeoLite2-City /var/www/html/${{env.EXTENSION_PATH}}/tests
ddev maxmind-download DEFAULT GeoLite2-Country /var/www/html/${{env.EXTENSION_PATH}}/tests
Expand Down Expand Up @@ -120,8 +123,6 @@ jobs:
cd ${{ github.workspace }}/.ddev
ddev nginx-config custom_files/crowdsec-prepend-nginx-site.conf
cd ${{ github.workspace }}
cp ${{env.EXTENSION_PATH}}/tests/end-to-end/php-scripts/cache-actions.php.dist ${{env.EXTENSION_PATH}}/scripts/public/cache-actions.php
cp ${{env.EXTENSION_PATH}}/tests/end-to-end/php-scripts/geolocation-test.php.dist ${{env.EXTENSION_PATH}}/scripts/public/geolocation-test.php
cp ${{env.EXTENSION_PATH}}/tests/end-to-end/settings/base.php.dist crowdsec-lib-settings.php
sed -i -e 's/REPLACE_API_KEY/${{ env.BOUNCER_KEY }}/g' crowdsec-lib-settings.php
sed -i -e 's/REPLACE_PROXY_IP/${{ env.PROXY_IP }}/g' crowdsec-lib-settings.php
Expand Down Expand Up @@ -163,10 +164,77 @@ jobs:
exit 1
fi

- name: Run "Display error with bad settings" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
sed -i 's/\x27cache_system\x27 => Constants::CACHE_SYSTEM_PHPFS/\x27cache_system\x27 => 1/g' scripts/auto-prepend/settings.php
cat scripts/auto-prepend/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/6-display-error-on.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi

- name: Run "No display error with bad settings" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
sed -i 's/\x27cache_system\x27 => Constants::CACHE_SYSTEM_PHPFS/\x27cache_system\x27 => 1/g' scripts/auto-prepend/settings.php
sed -i 's/\x27display_errors\x27 => true/\x27display_errors\x27 => false/g' scripts/auto-prepend/settings.php
cat scripts/auto-prepend/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/5-display-error-off.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi

- name: Run "No display error with error while bouncing" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
sed -i 's/\x27cache_system\x27 => 1/\x27cache_system\x27 => Constants::CACHE_SYSTEM_PHPFS/g' scripts/auto-prepend/settings.php
sed -i 's/\x27forced_test_ip\x27 => \x27\x27/\x27forced_test_ip\x27 => \x27bad-ip\x27/g' scripts/auto-prepend/settings.php
cat scripts/auto-prepend/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/5-display-error-off.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi

- name: Run "Display error with error while bouncing" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
sed -i 's/\x27display_errors\x27 => false/\x27display_errors\x27 => true/g' scripts/auto-prepend/settings.php
cat scripts/auto-prepend/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/6-display-error-on.js"
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
if [[ $PENDING_TESTS == "0" ]]
then
echo "No pending tests: OK"
else
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi

- name: Run "live mode with cURL and without geolocation" test
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
sed -i 's/\x27use_curl\x27 => false/\x27use_curl\x27 => true/g' scripts/auto-prepend/settings.php
sed -i 's/\x27forced_test_ip\x27 => \x27bad-ip\x27/\x27forced_test_ip\x27 => \x27\x27/g' scripts/auto-prepend/settings.php
cat scripts/auto-prepend/settings.php
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
./__scripts__/run-tests.sh ci "./__tests__/1-live-mode.js"
Expand Down Expand Up @@ -201,7 +269,6 @@ jobs:
run: |
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
sed -i 's/\x27use_curl\x27 => false/\x27use_curl\x27 => true/g' scripts/auto-prepend/settings.php
sed -i 's/\x27use_curl\x27 => true/\x27use_curl\x27 => false/g' scripts/auto-prepend/settings.php
sed -i 's/\x27enabled\x27 => false/\x27enabled\x27 => true/g' scripts/auto-prepend/settings.php
sed -i 's/\x27forced_test_forwarded_ip\x27 => \x27\x27/\x27forced_test_forwarded_ip\x27 => \x27${{env.JP_TEST_IP}}\x27/g' scripts/auto-prepend/settings.php
cat scripts/auto-prepend/settings.php
Expand Down Expand Up @@ -332,7 +399,6 @@ jobs:
echo "There are pending tests: $PENDING_TESTS (KO)"
exit 1
fi


- name: Run "stream mode with TLS auth and cURL and Memcached" test
run: |
Expand Down
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Composer
vendor
composer.lock
composer-dev.*

# Systems
.DS_Store
Expand All @@ -13,18 +14,14 @@ tools/php-cs-fixer/composer.lock

# App
var/
.bouncer-key
.cache
.logs

# Auto prepend demo
scripts/auto-prepend/settings.php
scripts/auto-prepend/.logs
scripts/auto-prepend/.cache
scripts/**/*.log

# Public scripts
scripts/public/cache-actions.php
scripts/public/geolocation-test.php

# MaxMind databases
*.mmdb
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).


## [0.36.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v0.36.0) - 2023-01-26
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v0.35.0...v0.36.0)

### Changed
- *Breaking changes*: All the code has been refactored to use `crowdsec/remediation-engine` package:
- Lot of public methods have been deleted or replaced by others
- A bouncer should now extend an `AbstractBouncer` class and implements some abstract methods
- Some settings names have been changed


---


## [0.35.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v0.35.0) - 2022-12-16
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v0.34.0...v0.35.0)

Expand Down
12 changes: 4 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,16 @@
],
"require": {
"php": ">=7.2.5",
"crowdsec/remediation-engine": "0.6.1",
"symfony/config": "^4.4.27 || ^5.2 || ^6.0",
"symfony/cache": "^5.4.11 || ^6.0.11",
"twig/twig": "^3.4.2",
"monolog/monolog": "^1.17 || ^2.1",
"gregwar/captcha": "^1.1",
"mlocati/ip-lib": "^1.18",
"geoip2/geoip2": "^2.12.2",
"ext-json": "*"
"ext-json": "*",
"ext-gd": "*"
},
"require-dev": {
"phpunit/phpunit": "^8.5.30 || ^9.3",
"ext-curl": "*"
},
"suggest": {
"ext-curl": "*"
"mikey179/vfsstream": "^1.6.11"
}
}
Loading