Skip to content

Set JSON response type in ApiV2Controller::beforeRender and drop Forc… #36

Set JSON response type in ApiV2Controller::beforeRender and drop Forc…

Set JSON response type in ApiV2Controller::beforeRender and drop Forc… #36

name: COmanage Registry E2E SAML Enrollment Flow
on:
workflow_dispatch:
push:
pull_request:
jobs:
e2e-saml-tests:
name: e2e-saml-tests (php=8.4, db=${{ matrix.db.engine }})
runs-on:
- codebuild-comanage-pipeline-${{ github.run_id }}-${{ github.run_attempt }}
strategy:
fail-fast: false
matrix:
db:
- engine: postgres
image: postgres:16-alpine
port: 5432
health_cmd: 'pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB"'
# - engine: mysql
# image: mysql:8.0
# port: 3306
# health_cmd: 'mysqladmin ping -h 127.0.0.1 -uroot -p"$MYSQL_ROOT_PASSWORD" --silent'
# - engine: mariadb
# image: mariadb:11
# port: 3306
# health_cmd: 'mariadb-admin ping -h 127.0.0.1 -uroot -p"$MARIADB_ROOT_PASSWORD" --silent'
services:
mail:
image: axllent/mailpit:v1.20
ports:
- 1025:1025
- 8025:8025
db:
image: ${{ matrix.db.image }}
ports:
- ${{ matrix.db.port }}:${{ matrix.db.port }}
env:
POSTGRES_DB: registry_test
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_password
MYSQL_DATABASE: registry_test
MYSQL_USER: test_user
MYSQL_PASSWORD: test_password
MYSQL_ROOT_PASSWORD: root_password
MARIADB_DATABASE: registry_test
MARIADB_USER: test_user
MARIADB_PASSWORD: test_password
MARIADB_ROOT_PASSWORD: root_password
options: >-
--health-cmd "${{ matrix.db.health_cmd }}"
--health-interval 10s
--health-timeout 5s
--health-retries 20
env:
COMANAGE_E2E_ALLOW_SYSTEM_SETUP: "1"
COMANAGE_BASE_URL: "https://localhost"
COMANAGE_REGISTRY_DIR: /srv/comanage-registry
DB_ENGINE: ${{ matrix.db.engine }}
E2E_A11Y_MODE: "report"
# Values used by setup / bootstrap
COMANAGE_REGISTRY_ADMIN_GIVEN_NAME_TEST: Admin
COMANAGE_REGISTRY_ADMIN_FAMILY_NAME_TEST: User
COMANAGE_REGISTRY_ADMIN_USERNAME_TEST: admin
COMANAGE_REGISTRY_SECURITY_SALT_TEST: phpunit-security-salt
# DB creds
COMANAGE_REGISTRY_DATABASE_TEST: registry_test
COMANAGE_REGISTRY_DATABASE_USER_TEST: test_user
COMANAGE_REGISTRY_DATABASE_USER_PASSWORD_TEST: test_password
COMANAGE_REGISTRY_DATABASE_PERSISTENT_TEST: "false"
# SAML Mock IdP config
COMANAGE_REGISTRY_SAML_IDP_HOST: "127.0.0.1"
COMANAGE_REGISTRY_SAML_IDP_PORT: "8080"
COMANAGE_REGISTRY_SAML_IDP_ENTITYID: "http://localhost:8080/simplesaml/saml2/idp/metadata.php"
steps:
- name: Checkout repository at the exact commit
shell: bash
run: |
set -euxo pipefail
git clone "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" "${COMANAGE_REGISTRY_DIR}"
cd "${COMANAGE_REGISTRY_DIR}"
git fetch --no-tags --prune --depth=1 origin "${GITHUB_SHA}"
git checkout --force "${GITHUB_SHA}"
git rev-parse HEAD
- name: Upgrade OS packages
shell: bash
run: |
set -euxo pipefail
sudo apt-get update
sudo apt-get upgrade -y
- name: Install PHP 8.4 and extensions
shell: bash
run: |
set -euxo pipefail
sudo apt-get install -y --no-install-recommends \
software-properties-common ca-certificates gnupg
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update
PHP_VER="8.4"
sudo apt-get install -y --no-install-recommends \
libapache2-mod-php${PHP_VER} \
php${PHP_VER}-cli \
php${PHP_VER}-mbstring \
php${PHP_VER}-intl \
php${PHP_VER}-ldap \
php${PHP_VER}-xml \
php${PHP_VER}-zip \
php${PHP_VER}-pdo \
php${PHP_VER}-mysql \
php${PHP_VER}-pgsql \
php${PHP_VER}-gd \
php${PHP_VER}-xsl \
php${PHP_VER}-memcached \
php${PHP_VER}-curl
sudo update-alternatives --set php /usr/bin/php${PHP_VER}
sudo ln -sf /usr/bin/php${PHP_VER} /usr/local/bin/php
echo "/usr/local/bin" >> "$GITHUB_PATH"
- name: Install OS packages needed for E2E tests
shell: bash
run: |
set -euxo pipefail
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
wget curl tar ca-certificates \
git unzip openssl socat acl \
libicu-dev \
libxml2 \
zlib1g \
tree \
apache2 \
shibboleth-sp-utils \
libapache2-mod-shib
- name: Wait for DB to be ready (inside the service container)
shell: bash
run: |
set -euxo pipefail
case "${DB_ENGINE}" in
postgres)
docker exec "${{ job.services.db.id }}" sh -lc 'for i in $(seq 1 60); do pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB" && exit 0; sleep 1; done; exit 1'
;;
mysql)
docker exec "${{ job.services.db.id }}" sh -lc 'for i in $(seq 1 60); do mysqladmin ping -h 127.0.0.1 -uroot -p"$MYSQL_ROOT_PASSWORD" --silent && exit 0; sleep 1; done; exit 1'
;;
mariadb)
docker exec "${{ job.services.db.id }}" sh -lc 'for i in $(seq 1 60); do mariadb-admin ping -h 127.0.0.1 -uroot -p"$MARIADB_ROOT_PASSWORD" --silent && exit 0; sleep 1; done; exit 1'
;;
*)
echo "Unknown DB_ENGINE=${DB_ENGINE}"
exit 1
;;
esac
- name: Determine DB host/port for published ports
shell: bash
run: |
set -euxo pipefail
if [ -f /.dockerenv ]; then
DB_HOST="$(ip route | awk '/default/ {print $3; exit}')"
else
DB_HOST="127.0.0.1"
fi
DB_PORT="${{ matrix.db.port }}"
{
echo "COMANAGE_REGISTRY_DATABASE_HOST_TEST=${DB_HOST}"
echo "COMANAGE_REGISTRY_DATABASE_PORT_TEST=${DB_PORT}"
} >> "$GITHUB_ENV"
- name: Smoke test DB TCP connectivity (from the job environment)
shell: bash
run: |
set -euxo pipefail
php -r '
$h=getenv("COMANAGE_REGISTRY_DATABASE_HOST_TEST"); $p=(int)getenv("COMANAGE_REGISTRY_DATABASE_PORT_TEST");
$fp=@fsockopen($h,$p,$errno,$errstr,5);
if(!$fp){fwrite(STDERR,"TCP connect failed to $h:$p: $errno $errstr\n"); exit(1);}
fclose($fp);
echo "TCP connect OK to $h:$p\n";
'
- name: Create local/config database and security configurations
shell: bash
run: |
set -euxo pipefail
sudo mkdir -p "${COMANAGE_REGISTRY_DIR}/local/config"
sudo chown -R "$(id -un)" "${COMANAGE_REGISTRY_DIR}/local/config"
php "${COMANAGE_REGISTRY_DIR}/app/tests/e2e/enrollmentflows/scripts/create-ci-config.php"
- name: Composer update phpunit only
shell: bash
working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app
run: |
set -euxo pipefail
composer update phpunit/phpunit --with-all-dependencies
- name: Bootstrap SAML IdP (Cirrus SimpleSAMLphp)
shell: bash
working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app
run: |
set -euxo pipefail
bash tests/e2e/enrollmentflows/scripts/bootstrap-idp.sh
- name: Bootstrap Shibboleth SP and Apache
shell: bash
working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app
run: |
set -euxo pipefail
bash tests/e2e/enrollmentflows/scripts/bootstrap-shibboleth.sh
bash tests/e2e/enrollmentflows/scripts/bootstrap-apache.sh
- name: Bootstrap COmanage Data (Platform Admin, CO, EnvSource, Flow)
shell: bash
working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app
run: |
set -euxo pipefail
php tests/e2e/enrollmentflows/scripts/bootstrap-comanage.php
- name: Hand CakePHP runtime directories back to Apache
shell: bash
working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app
run: |
set -euxo pipefail
bash tests/e2e/enrollmentflows/scripts/fix-runtime-permissions.sh
- name: Verify Web Server, Shibboleth SP, IdP, and SMTP Health
shell: bash
working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app
run: |
set -euxo pipefail
bash tests/e2e/enrollmentflows/scripts/verify-ci-services.sh
- name: Setup Node.js for Playwright E2E Tests
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Playwright Dependencies & Browsers
shell: bash
working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app/tests/e2e
run: |
set -euxo pipefail
npm ci
node --test checks/configuration.test.js
npx playwright install --with-deps chromium
- name: Run Playwright SAML E2E Browser Suite
shell: bash
working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app/tests/e2e
run: |
set -euxo pipefail
npx playwright test
- name: Collect E2E Service Diagnostics
if: always()
shell: bash
run: |
set -uo pipefail
DIAGNOSTICS="${COMANAGE_REGISTRY_DIR}/app/tests/e2e/diagnostics"
mkdir -p "${DIAGNOSTICS}"
sudo apache2ctl -S > "${DIAGNOSTICS}/apache-vhosts.txt" 2>&1 || true
sudo tail -n 200 /var/log/apache2/comanage_e2e_ssl_error.log > "${DIAGNOSTICS}/apache-error.log" 2>&1 || true
sudo tail -n 200 /var/log/shibboleth/shibd.log > "${DIAGNOSTICS}/shibd.log" 2>&1 || true
tail -n 200 "${COMANAGE_REGISTRY_DIR}/local/logs/error.log" > "${DIAGNOSTICS}/application-error.log" 2>&1 || true
docker logs saml-idp > "${DIAGNOSTICS}/idp.log" 2>&1 || true
- name: Upload Playwright Test Report Artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: |
${{ env.COMANAGE_REGISTRY_DIR }}/app/tests/e2e/playwright-report/
${{ env.COMANAGE_REGISTRY_DIR }}/app/tests/e2e/test-results/
${{ env.COMANAGE_REGISTRY_DIR }}/app/tests/e2e/diagnostics/
retention-days: 7
- name: Run PHPUnit E2E Validation Tests
shell: bash
working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app
run: |
set -euxo pipefail
echo "Running PHPUnit E2E SAML Enrollment flow validation suite..."
vendor/bin/phpunit --group e2e-saml --testdox
- name: Stop Mock SAML IdP
if: always()
shell: bash
run: |
set -euxo pipefail
if [ "$(docker inspect -f '{{index .Config.Labels "comanage.e2e"}}' saml-idp 2>/dev/null || true)" = "true" ]; then
docker rm -f saml-idp
fi