Skip to content

Commit 2948249

Browse files
Merge pull request #115 from julienloizelet/feat/use-remediation-engine
Feat/use remediation engine
2 parents ed00473 + 5a77c5e commit 2948249

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3122
-4397
lines changed

.github/workflows/coding-standards.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ on:
66
paths-ignore:
77
- '**.md'
88
workflow_dispatch:
9+
inputs:
10+
coverage_report:
11+
type: boolean
12+
description: Generate PHPUNIT Code Coverage report
13+
default: false
914

1015
jobs:
1116
coding-standards:
@@ -80,3 +85,27 @@ jobs:
8085

8186
- name: Run PSALM
8287
run: ddev psalm ./${{env.EXTENSION_PATH}}/tools/coding-standards ./${{env.EXTENSION_PATH}}/tools/coding-standards/psalm
88+
89+
- name: Prepare for Code Coverage
90+
if: github.event.inputs.coverage_report == 'true'
91+
run: |
92+
cp .ddev/additional_docker_compose/docker-compose.crowdsec.yaml .ddev/docker-compose.crowdsec.yaml
93+
mkdir ${{ github.workspace }}/cfssl
94+
cp -r .ddev/custom_files/crowdsec/cfssl/* ${{ github.workspace }}/cfssl
95+
ddev restart
96+
ddev maxmind-download DEFAULT GeoLite2-City /var/www/html/${{env.EXTENSION_PATH}}/tests
97+
ddev maxmind-download DEFAULT GeoLite2-Country /var/www/html/${{env.EXTENSION_PATH}}/tests
98+
cd ${{env.EXTENSION_PATH}}/tests
99+
sha256sum -c GeoLite2-Country.tar.gz.sha256.txt
100+
sha256sum -c GeoLite2-City.tar.gz.sha256.txt
101+
tar -xf GeoLite2-Country.tar.gz
102+
tar -xf GeoLite2-City.tar.gz
103+
rm GeoLite2-Country.tar.gz GeoLite2-Country.tar.gz.sha256.txt GeoLite2-City.tar.gz GeoLite2-City.tar.gz.sha256.txt
104+
echo "BOUNCER_KEY=$(ddev create-bouncer)" >> $GITHUB_ENV
105+
106+
- name: Run PHPUNIT Code Coverage
107+
if: github.event.inputs.coverage_report == 'true'
108+
run: |
109+
ddev xdebug
110+
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
111+
cat ${{env.EXTENSION_PATH}}/coding-standards/phpunit/code-coverage/report.txt

.github/workflows/test-suite.yml

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ jobs:
5757
cp .ddev/additional_docker_compose/docker-compose.playwright.yaml .ddev/docker-compose.playwright.yaml
5858
mkdir ${{ github.workspace }}/cfssl
5959
cp -r .ddev/custom_files/crowdsec/cfssl/* ${{ github.workspace }}/cfssl
60-
ls -l ${{ github.workspace }}/cfssl
6160
ddev start
6261
6362
- name: Set BOUNCER_KEY and PROXY_IP env
@@ -84,7 +83,11 @@ jobs:
8483
run: |
8584
ddev composer update --working-dir ./${{env.EXTENSION_PATH}}
8685
87-
- name: Prepare PHP UNIT tests
86+
- name: Run "Unit Tests"
87+
run: |
88+
ddev exec /usr/bin/php ./${{env.EXTENSION_PATH}}/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./${{env.EXTENSION_PATH}}/tests/Unit
89+
90+
- name: Prepare PHP Integration and end-to-end tests
8891
run: |
8992
ddev maxmind-download DEFAULT GeoLite2-City /var/www/html/${{env.EXTENSION_PATH}}/tests
9093
ddev maxmind-download DEFAULT GeoLite2-Country /var/www/html/${{env.EXTENSION_PATH}}/tests
@@ -120,8 +123,6 @@ jobs:
120123
cd ${{ github.workspace }}/.ddev
121124
ddev nginx-config custom_files/crowdsec-prepend-nginx-site.conf
122125
cd ${{ github.workspace }}
123-
cp ${{env.EXTENSION_PATH}}/tests/end-to-end/php-scripts/cache-actions.php.dist ${{env.EXTENSION_PATH}}/scripts/public/cache-actions.php
124-
cp ${{env.EXTENSION_PATH}}/tests/end-to-end/php-scripts/geolocation-test.php.dist ${{env.EXTENSION_PATH}}/scripts/public/geolocation-test.php
125126
cp ${{env.EXTENSION_PATH}}/tests/end-to-end/settings/base.php.dist crowdsec-lib-settings.php
126127
sed -i -e 's/REPLACE_API_KEY/${{ env.BOUNCER_KEY }}/g' crowdsec-lib-settings.php
127128
sed -i -e 's/REPLACE_PROXY_IP/${{ env.PROXY_IP }}/g' crowdsec-lib-settings.php
@@ -163,10 +164,77 @@ jobs:
163164
exit 1
164165
fi
165166
167+
- name: Run "Display error with bad settings" test
168+
run: |
169+
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
170+
sed -i 's/\x27cache_system\x27 => Constants::CACHE_SYSTEM_PHPFS/\x27cache_system\x27 => 1/g' scripts/auto-prepend/settings.php
171+
cat scripts/auto-prepend/settings.php
172+
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
173+
./__scripts__/run-tests.sh ci "./__tests__/6-display-error-on.js"
174+
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
175+
if [[ $PENDING_TESTS == "0" ]]
176+
then
177+
echo "No pending tests: OK"
178+
else
179+
echo "There are pending tests: $PENDING_TESTS (KO)"
180+
exit 1
181+
fi
182+
183+
- name: Run "No display error with bad settings" test
184+
run: |
185+
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
186+
sed -i 's/\x27cache_system\x27 => Constants::CACHE_SYSTEM_PHPFS/\x27cache_system\x27 => 1/g' scripts/auto-prepend/settings.php
187+
sed -i 's/\x27display_errors\x27 => true/\x27display_errors\x27 => false/g' scripts/auto-prepend/settings.php
188+
cat scripts/auto-prepend/settings.php
189+
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
190+
./__scripts__/run-tests.sh ci "./__tests__/5-display-error-off.js"
191+
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
192+
if [[ $PENDING_TESTS == "0" ]]
193+
then
194+
echo "No pending tests: OK"
195+
else
196+
echo "There are pending tests: $PENDING_TESTS (KO)"
197+
exit 1
198+
fi
199+
200+
- name: Run "No display error with error while bouncing" test
201+
run: |
202+
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
203+
sed -i 's/\x27cache_system\x27 => 1/\x27cache_system\x27 => Constants::CACHE_SYSTEM_PHPFS/g' scripts/auto-prepend/settings.php
204+
sed -i 's/\x27forced_test_ip\x27 => \x27\x27/\x27forced_test_ip\x27 => \x27bad-ip\x27/g' scripts/auto-prepend/settings.php
205+
cat scripts/auto-prepend/settings.php
206+
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
207+
./__scripts__/run-tests.sh ci "./__tests__/5-display-error-off.js"
208+
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
209+
if [[ $PENDING_TESTS == "0" ]]
210+
then
211+
echo "No pending tests: OK"
212+
else
213+
echo "There are pending tests: $PENDING_TESTS (KO)"
214+
exit 1
215+
fi
216+
217+
- name: Run "Display error with error while bouncing" test
218+
run: |
219+
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
220+
sed -i 's/\x27display_errors\x27 => false/\x27display_errors\x27 => true/g' scripts/auto-prepend/settings.php
221+
cat scripts/auto-prepend/settings.php
222+
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
223+
./__scripts__/run-tests.sh ci "./__tests__/6-display-error-on.js"
224+
PENDING_TESTS=$(grep -oP '"numPendingTests":\K(.*),"numRuntimeErrorTestSuites"' .test-results.json | sed 's/,"numRuntimeErrorTestSuites"//g')
225+
if [[ $PENDING_TESTS == "0" ]]
226+
then
227+
echo "No pending tests: OK"
228+
else
229+
echo "There are pending tests: $PENDING_TESTS (KO)"
230+
exit 1
231+
fi
232+
166233
- name: Run "live mode with cURL and without geolocation" test
167234
run: |
168235
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
169236
sed -i 's/\x27use_curl\x27 => false/\x27use_curl\x27 => true/g' scripts/auto-prepend/settings.php
237+
sed -i 's/\x27forced_test_ip\x27 => \x27bad-ip\x27/\x27forced_test_ip\x27 => \x27\x27/g' scripts/auto-prepend/settings.php
170238
cat scripts/auto-prepend/settings.php
171239
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/
172240
./__scripts__/run-tests.sh ci "./__tests__/1-live-mode.js"
@@ -201,7 +269,6 @@ jobs:
201269
run: |
202270
cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
203271
sed -i 's/\x27use_curl\x27 => false/\x27use_curl\x27 => true/g' scripts/auto-prepend/settings.php
204-
sed -i 's/\x27use_curl\x27 => true/\x27use_curl\x27 => false/g' scripts/auto-prepend/settings.php
205272
sed -i 's/\x27enabled\x27 => false/\x27enabled\x27 => true/g' scripts/auto-prepend/settings.php
206273
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
207274
cat scripts/auto-prepend/settings.php
@@ -332,7 +399,6 @@ jobs:
332399
echo "There are pending tests: $PENDING_TESTS (KO)"
333400
exit 1
334401
fi
335-
336402
337403
- name: Run "stream mode with TLS auth and cURL and Memcached" test
338404
run: |

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Composer
22
vendor
33
composer.lock
4+
composer-dev.*
45

56
# Systems
67
.DS_Store
@@ -13,18 +14,14 @@ tools/php-cs-fixer/composer.lock
1314

1415
# App
1516
var/
16-
.bouncer-key
1717
.cache
18+
.logs
1819

1920
# Auto prepend demo
2021
scripts/auto-prepend/settings.php
2122
scripts/auto-prepend/.logs
2223
scripts/auto-prepend/.cache
2324
scripts/**/*.log
2425

25-
# Public scripts
26-
scripts/public/cache-actions.php
27-
scripts/public/geolocation-test.php
28-
2926
# MaxMind databases
3027
*.mmdb

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77

8+
## [0.36.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v0.36.0) - 2023-01-26
9+
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v0.35.0...v0.36.0)
10+
11+
### Changed
12+
- *Breaking changes*: All the code has been refactored to use `crowdsec/remediation-engine` package:
13+
- Lot of public methods have been deleted or replaced by others
14+
- A bouncer should now extend an `AbstractBouncer` class and implements some abstract methods
15+
- Some settings names have been changed
16+
17+
18+
---
19+
20+
821
## [0.35.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v0.35.0) - 2022-12-16
922
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v0.34.0...v0.35.0)
1023

composer.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,16 @@
4040
],
4141
"require": {
4242
"php": ">=7.2.5",
43+
"crowdsec/remediation-engine": "0.6.1",
4344
"symfony/config": "^4.4.27 || ^5.2 || ^6.0",
44-
"symfony/cache": "^5.4.11 || ^6.0.11",
4545
"twig/twig": "^3.4.2",
46-
"monolog/monolog": "^1.17 || ^2.1",
4746
"gregwar/captcha": "^1.1",
4847
"mlocati/ip-lib": "^1.18",
49-
"geoip2/geoip2": "^2.12.2",
50-
"ext-json": "*"
48+
"ext-json": "*",
49+
"ext-gd": "*"
5150
},
5251
"require-dev": {
5352
"phpunit/phpunit": "^8.5.30 || ^9.3",
54-
"ext-curl": "*"
55-
},
56-
"suggest": {
57-
"ext-curl": "*"
53+
"mikey179/vfsstream": "^1.6.11"
5854
}
5955
}

0 commit comments

Comments
 (0)