Test suite #115
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test suite | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- '**.md' | |
workflow_dispatch: | |
schedule: | |
- cron: '15 3 * * 4' | |
permissions: | |
contents: read | |
env: | |
# Allow ddev get to use a GitHub token to prevent rate limiting by tests | |
DDEV_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
jobs: | |
test-suite: | |
strategy: | |
fail-fast: false | |
matrix: | |
php-version: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] | |
name: Test suite | |
runs-on: ubuntu-latest | |
if: ${{ !contains(github.event.head_commit.message, 'chore(') }} | |
env: | |
EXTENSION_PATH: "my-code/crowdsec-bouncer-lib" | |
DDEV_PROJECT: "crowdsec-bouncer-lib" | |
JP_TEST_IP: "210.249.74.42" | |
IPV6_TEST_IP: "2001:0db8:0000:85a3:0000:0000:ac1f:8001" | |
IPV6_TEST_PROXY_IP: "2345:0425:2CA1:0000:0000:0567:5673:23b5" | |
steps: | |
- name: Install DDEV | |
# @see https://ddev.readthedocs.io/en/stable/#installationupgrade-script-linux-and-macos-armarm64-and-amd64-architectures | |
run: | | |
curl -fsSL https://apt.fury.io/drud/gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/ddev.gpg > /dev/null | |
echo "deb [signed-by=/etc/apt/trusted.gpg.d/ddev.gpg] https://apt.fury.io/drud/ * *" | sudo tee /etc/apt/sources.list.d/ddev.list | |
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=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 }} | |
- name: Add Redis, Memcached and Crowdsec | |
run: | | |
ddev get ddev/ddev-redis | |
ddev get ddev/ddev-memcached | |
# override redis.conf | |
ddev get julienloizelet/ddev-tools | |
ddev get julienloizelet/ddev-crowdsec-php | |
- name: Start DDEV | |
run: ddev start | |
- name: Set BOUNCER_KEY and PROXY_IP env | |
run: | | |
echo "BOUNCER_KEY=$(ddev create-bouncer)" >> $GITHUB_ENV | |
echo "PROXY_IP=$(ddev find-ip ddev-router)" >> $GITHUB_ENV | |
- name: Some DEBUG information | |
run: | | |
ddev --version | |
ddev exec php -v | |
ddev exec -s crowdsec crowdsec -version | |
ddev php -r "echo phpversion('memcached');" | |
- name: Clone PHP lib Crowdsec files | |
uses: actions/checkout@v4 | |
with: | |
path: my-code/crowdsec-bouncer-lib | |
- name: Validate composer.json | |
run: ddev composer validate --strict --working-dir ./${{env.EXTENSION_PATH}} | |
- name: Install CrowdSec lib dependencies | |
run: | | |
ddev composer update --working-dir ./${{env.EXTENSION_PATH}} | |
- name: Set excluded groups | |
id: set-excluded-groups | |
if: contains(fromJson('["7.2","7.3"]'),matrix.php-version) | |
run: echo "exclude_group=$(echo --exclude-group up-to-php74 )" >> $GITHUB_OUTPUT | |
- name: Run "Unit Tests" | |
run: | | |
ddev exec /usr/bin/php ./${{env.EXTENSION_PATH}}/vendor/bin/phpunit --testdox ${{ steps.set-excluded-groups.outputs.exclude_group }} ./${{env.EXTENSION_PATH}}/tests/Unit | |
- name: Prepare PHP Integration tests | |
run: | | |
mkdir ${{ github.workspace }}/cfssl | |
cp -r .ddev/okaeli-add-on/custom_files/crowdsec/cfssl/* ${{ github.workspace }}/cfssl | |
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 | |
- name: Run "IP verification" test | |
run: | | |
ddev exec BOUNCER_KEY=${{ env.BOUNCER_KEY }} AGENT_TLS_PATH=/var/www/html/cfssl APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://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/AbstractBouncerTest.php | |
- name: Run "IP verification with TLS" test | |
run: | | |
ddev exec BOUNCER_KEY=${{ env.BOUNCER_KEY }} AGENT_TLS_PATH=/var/www/html/cfssl BOUNCER_TLS_PATH=/var/www/html/cfssl APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://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/AbstractBouncerTest.php | |
- name: Run "Geolocation with cURL" test | |
run: | | |
ddev exec BOUNCER_KEY=${{ env.BOUNCER_KEY }} AGENT_TLS_PATH=/var/www/html/cfssl APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 /usr/bin/php ./${{env.EXTENSION_PATH}}/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./${{env.EXTENSION_PATH}}/tests/Integration/GeolocationTest.php |