17
17
name : Test suite
18
18
runs-on : ubuntu-latest
19
19
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"
20
25
21
26
steps :
22
27
- name : Clone DDEV files
@@ -70,18 +75,18 @@ jobs:
70
75
path : my-own-modules/crowdsec-php-lib
71
76
72
77
- 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}}
74
79
75
80
- name : Install CrowdSec lib dependencies
76
81
run : |
77
- ddev composer update --working-dir ./my-own-modules/crowdsec-php-lib
82
+ ddev composer update --working-dir ./${{env.EXTENSION_PATH}}
78
83
79
84
- name : Prepare PHP UNIT tests
80
85
run : |
81
86
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
85
90
sha256sum -c GeoLite2-Country.tar.gz.sha256.txt
86
91
sha256sum -c GeoLite2-City.tar.gz.sha256.txt
87
92
tar -xf GeoLite2-Country.tar.gz
@@ -90,36 +95,38 @@ jobs:
90
95
91
96
- name : Run PHP UNIT tests (IP verification)
92
97
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
94
99
95
100
- name : Run PHP UNIT tests (Geolocation)
96
101
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
98
103
99
104
- name : Prepare Standalone Bouncer end-to-end tests
100
105
run : |
101
106
ddev create-watcher
102
107
cd ${{ github.workspace }}/.ddev
103
108
ddev nginx-config custom_files/crowdsec-prepend-nginx-site.conf
104
109
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
108
113
sed -i -e 's/REPLACE_API_KEY/${{ env.BOUNCER_KEY }}/g' crowdsec-lib-settings.php
109
114
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__
112
119
chmod +x test-init.sh
113
120
./test-init.sh
114
121
chmod +x run-tests.sh
115
122
116
123
- name : Verify auto_prepend_file directive
117
124
run : |
118
125
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#" ]]
123
130
then
124
131
echo "AUTO PREPEND FILE OK"
125
132
else
@@ -130,27 +137,42 @@ jobs:
130
137
131
138
- name : Run Standalone Bouncer end-to-end test (live mode without geolocation)
132
139
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__
134
143
./run-tests.sh ci "./__tests__/1-live-mode.js"
135
144
136
145
- name : Run Standalone Bouncer end-to-end test (live mode with geolocation)
137
146
run : |
138
- cd ${{ github.workspace }}/my-own-modules/crowdsec-php-lib
147
+ cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
139
148
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__
142
152
./run-tests.sh ci "./__tests__/2-live-mode-with-geolocation.js"
143
153
144
154
- name : Run Standalone Bouncer end-to-end test (stream mode without geolocation)
145
155
run : |
146
- cd ${{ github.workspace }}/my-own-modules/crowdsec-php-lib
156
+ cd ${{ github.workspace }}/${{env.EXTENSION_PATH}}
147
157
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
149
159
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__
151
162
./run-tests.sh ci "./__tests__/3-stream-mode.js"
152
163
153
164
- name : Run Standalone Bouncer end-to-end test (standalone geolocation)
154
165
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