1717 name : Test suite
1818 runs-on : ubuntu-latest
1919 if : ${{ !contains(github.event.head_commit.message, 'chore(') }}
20+ env :
21+ EXTENSION_PATH : " my-own-modules/crowdsec-php-lib"
22+ JP_TEST_IP : " 210.249.74.42"
23+ IPV6_TEST_IP : " 2001:0db8:0000:85a3:0000:0000:ac1f:8001"
24+ IPV6_TEST_PROXY_IP : " 2345:0425:2CA1:0000:0000:0567:5673:23b5"
2025
2126 steps :
2227 - name : Clone DDEV files
@@ -70,18 +75,18 @@ jobs:
7075 path : my-own-modules/crowdsec-php-lib
7176
7277 - name : Validate composer.json
73- run : ddev composer validate --strict --working-dir ./my-own-modules/crowdsec-php-lib
78+ run : ddev composer validate --strict --working-dir ./${{env.EXTENSION_PATH}}
7479
7580 - name : Install CrowdSec lib dependencies
7681 run : |
77- ddev composer update --working-dir ./my-own-modules/crowdsec-php-lib
82+ ddev composer update --working-dir ./${{env.EXTENSION_PATH}}
7883
7984 - name : Prepare PHP UNIT tests
8085 run : |
8186 ddev create-watcher PhpUnitTestMachine PhpUnitTestMachinePassword
82- ddev maxmind-download DEFAULT GeoLite2-City /var/www/html/my-own-modules/crowdsec-php-lib /tests
83- ddev maxmind-download DEFAULT GeoLite2-Country /var/www/html/my-own-modules/crowdsec-php-lib /tests
84- cd my-own-modules/crowdsec-php-lib /tests
87+ ddev maxmind-download DEFAULT GeoLite2-City /var/www/html/${{env.EXTENSION_PATH}} /tests
88+ ddev maxmind-download DEFAULT GeoLite2-Country /var/www/html/${{env.EXTENSION_PATH}} /tests
89+ cd ${{env.EXTENSION_PATH}} /tests
8590 sha256sum -c GeoLite2-Country.tar.gz.sha256.txt
8691 sha256sum -c GeoLite2-City.tar.gz.sha256.txt
8792 tar -xf GeoLite2-Country.tar.gz
@@ -90,36 +95,38 @@ jobs:
9095
9196 - name : Run PHP UNIT tests (IP verification)
9297 run : |
93- ddev exec BOUNCER_KEY=${{ env.BOUNCER_KEY }} LAPI_URL=http://crowdsec:8080 MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-own-modules/crowdsec-php-lib/ vendor/bin/phpunit --testdox --colors --exclude-group ignore ./my-own-modules/crowdsec-php-lib /tests/Integration/IpVerificationTest.php
98+ ddev exec BOUNCER_KEY=${{ env.BOUNCER_KEY }} LAPI_URL=http://crowdsec:8080 MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./${{env.EXTENSION_PATH}}/ vendor/bin/phpunit --testdox --colors --exclude-group ignore ./${{env.EXTENSION_PATH}} /tests/Integration/IpVerificationTest.php
9499
95100 - name : Run PHP UNIT tests (Geolocation)
96101 run : |
97- ddev exec BOUNCER_KEY=${{ env.BOUNCER_KEY }} LAPI_URL=http://crowdsec:8080 /usr/bin/php ./my-own-modules/crowdsec-php-lib/ vendor/bin/phpunit --testdox --colors --exclude-group ignore ./my-own-modules/crowdsec-php-lib /tests/Integration/GeolocationTest.php
102+ ddev exec BOUNCER_KEY=${{ env.BOUNCER_KEY }} LAPI_URL=http://crowdsec:8080 /usr/bin/php ./${{env.EXTENSION_PATH}}/ vendor/bin/phpunit --testdox --colors --exclude-group ignore ./${{env.EXTENSION_PATH}} /tests/Integration/GeolocationTest.php
98103
99104 - name : Prepare Standalone Bouncer end-to-end tests
100105 run : |
101106 ddev create-watcher
102107 cd ${{ github.workspace }}/.ddev
103108 ddev nginx-config custom_files/crowdsec-prepend-nginx-site.conf
104109 cd ${{ github.workspace }}
105- cp .ddev/custom_files/crowdsec/ cache-actions.php my-own-modules/crowdsec-php-lib /scripts/public/cache-actions.php
106- cp .ddev/custom_files/crowdsec/ geolocation-test.php my-own-modules/crowdsec-php-lib /scripts/public/geolocation-test.php
107- cp .ddev/custom_files/crowdsec-lib- settings.php crowdsec-lib-settings.php
110+ cp ${{env.EXTENSION_PATH}}/tests/end-to-end/php-scripts/ cache-actions.php.dist ${{env.EXTENSION_PATH}} /scripts/public/cache-actions.php
111+ cp ${{env.EXTENSION_PATH}}/tests/end-to-end/php-scripts/ geolocation-test.php.dist ${{env.EXTENSION_PATH}} /scripts/public/geolocation-test.php
112+ cp ${{env.EXTENSION_PATH}}/tests/end-to-end/ settings/base .php.dist crowdsec-lib-settings.php
108113 sed -i -e 's/REPLACE_API_KEY/${{ env.BOUNCER_KEY }}/g' crowdsec-lib-settings.php
109114 sed -i -e 's/REPLACE_PROXY_IP/${{ env.PROXY_IP }}/g' crowdsec-lib-settings.php
110- mv crowdsec-lib-settings.php my-own-modules/crowdsec-php-lib/scripts/auto-prepend/settings.php
111- cd ${{ github.workspace }}/my-own-modules/crowdsec-php-lib/tests/end-to-end/__scripts__
115+ sed -i -e 's/REPLACE_FORCED_IP//g' crowdsec-lib-settings.php
116+ sed -i -e 's/REPLACE_FORCED_FORWARDED_IP//g' crowdsec-lib-settings.php
117+ mv crowdsec-lib-settings.php ${{env.EXTENSION_PATH}}/scripts/auto-prepend/settings.php
118+ cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/__scripts__
112119 chmod +x test-init.sh
113120 ./test-init.sh
114121 chmod +x run-tests.sh
115122
116123 - name : Verify auto_prepend_file directive
117124 run : |
118125 cd ${{ github.workspace }}
119- cp .ddev/custom_files/phpinfo.php my-own-modules/crowdsec-php-lib /scripts/public/phpinfo.php
120- curl -v https://${{ env.PHP_VERSION_CODE }}.ddev.site/my-own-modules/crowdsec-php-lib /scripts/public/phpinfo.php
121- PREPENDVERIF=$(curl https://${{ env.PHP_VERSION_CODE }}.ddev.site/my-own-modules/crowdsec-php-lib /scripts/public/phpinfo.php | grep -o -E "auto_prepend_file=(.*)php(.*)" | sed 's/<\/tr>//g; s/<\/td>//g;' | tr '\n' '#')
122- if [[ $PREPENDVERIF == "auto_prepend_file=/var/www/html/my-own-modules/crowdsec-php-lib /scripts/auto-prepend/bounce.php#auto_prepend_file=/var/www/html/my-own-modules/crowdsec-php-lib/scripts/auto-prepend/bounce.php#" ]]
126+ cp .ddev/custom_files/phpinfo.php ${{env.EXTENSION_PATH}} /scripts/public/phpinfo.php
127+ curl -v https://${{ env.PHP_VERSION_CODE }}.ddev.site/${{env.EXTENSION_PATH}} /scripts/public/phpinfo.php
128+ PREPENDVERIF=$(curl https://${{ env.PHP_VERSION_CODE }}.ddev.site/${{env.EXTENSION_PATH}} /scripts/public/phpinfo.php | grep -o -E "auto_prepend_file=(.*)php(.*)" | sed 's/<\/tr>//g; s/<\/td>//g;' | tr '\n' '#')
129+ if [[ $PREPENDVERIF == "auto_prepend_file=/var/www/html/${{env.EXTENSION_PATH}} /scripts/auto-prepend/bounce.php#auto_prepend_file=/var/www/html/my-own-modules/crowdsec-php-lib/scripts/auto-prepend/bounce.php#" ]]
123130 then
124131 echo "AUTO PREPEND FILE OK"
125132 else
@@ -130,27 +137,42 @@ jobs:
130137
131138 - name : Run Standalone Bouncer end-to-end test (live mode without geolocation)
132139 run : |
133- cd ${{ github.workspace }}/my-own-modules/crowdsec-php-lib/tests/end-to-end/__scripts__
140+ cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
141+ cat scripts/auto-prepend/settings.php
142+ cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/__scripts__
134143 ./run-tests.sh ci "./__tests__/1-live-mode.js"
135144
136145 - name : Run Standalone Bouncer end-to-end test (live mode with geolocation)
137146 run : |
138- cd ${{ github.workspace }}/my-own-modules/crowdsec-php-lib
147+ cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
139148 sed -i 's/\x27enabled\x27 => false/\x27enabled\x27 => true/g' scripts/auto-prepend/settings.php
140- sed -i 's/\x27forced_test_ip\x27 => \x27\x27/\x27forced_test_ip\x27 => \x27210.249.74.42\x27/g' scripts/auto-prepend/settings.php
141- cd ${{ github.workspace }}/my-own-modules/crowdsec-php-lib/tests/end-to-end/__scripts__
149+ 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
150+ cat scripts/auto-prepend/settings.php
151+ cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/__scripts__
142152 ./run-tests.sh ci "./__tests__/2-live-mode-with-geolocation.js"
143153
144154 - name : Run Standalone Bouncer end-to-end test (stream mode without geolocation)
145155 run : |
146- cd ${{ github.workspace }}/my-own-modules/crowdsec-php-lib
156+ cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
147157 sed -i 's/\x27enabled\x27 => true/\x27enabled\x27 => false/g' scripts/auto-prepend/settings.php
148- sed -i 's/\x27forced_test_ip \x27 => \x27210.249.74.42 \x27/\x27forced_test_ip \x27 => \x27\x27/g' scripts/auto-prepend/settings.php
158+ sed -i 's/\x27forced_test_forwarded_ip \x27 => \x27${{env.JP_TEST_IP}} \x27/\x27forced_test_forwarded_ip \x27 => \x27\x27/g' scripts/auto-prepend/settings.php
149159 sed -i 's/\x27stream_mode\x27 => false/\x27stream_mode\x27 => true/g' scripts/auto-prepend/settings.php
150- cd ${{ github.workspace }}/my-own-modules/crowdsec-php-lib/tests/end-to-end/__scripts__
160+ cat scripts/auto-prepend/settings.php
161+ cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/__scripts__
151162 ./run-tests.sh ci "./__tests__/3-stream-mode.js"
152163
153164 - name : Run Standalone Bouncer end-to-end test (standalone geolocation)
154165 run : |
155- cd ${{ github.workspace }}/my-own-modules/crowdsec-php-lib/tests/end-to-end/__scripts__
156- ./run-tests.sh ci "./__tests__/4-geolocation.js"
166+ cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/__scripts__
167+ ./run-tests.sh ci "./__tests__/4-geolocation.js"
168+
169+ - name : Run Standalone Bouncer end-to-end test (live mode with IPv6)
170+ run : |
171+ cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
172+ sed -i 's/\x27forced_test_forwarded_ip\x27 => \x27\x27/\x27forced_test_forwarded_ip\x27 => \x27${{env.IPV6_TEST_IP}}\x27/g' scripts/auto-prepend/settings.php
173+ sed -i 's/\x27forced_test_ip\x27 => \x27\x27/\x27forced_test_ip\x27 => \x27${{env.IPV6_TEST_PROXY_IP}}\x27/g' scripts/auto-prepend/settings.php
174+ sed -i -e 's/${{ env.PROXY_IP }}/${{env.IPV6_TEST_PROXY_IP}}/g' scripts/auto-prepend/settings.php
175+ sed -i 's/\x27stream_mode\x27 => true/\x27stream_mode\x27 => false/g' scripts/auto-prepend/settings.php
176+ cat scripts/auto-prepend/settings.php
177+ cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}/tests/end-to-end/__scripts__
178+ ./run-tests.sh ci "./__tests__/1-live-mode.js"
0 commit comments