Skip to content

Add Identifiers API v2 tests.Added ci boilerplate for ldap testing. #1

Add Identifiers API v2 tests.Added ci boilerplate for ldap testing.

Add Identifiers API v2 tests.Added ci boilerplate for ldap testing. #1

name: COmanage Registry LDAP (LLDAP)
on:
workflow_dispatch:
inputs:
enable:
description: "Set to true to actually run LDAP/LLDAP CI"
required: true
default: "false"
type: choice
options:
- "false"
- "true"
push:
pull_request:
jobs:
ldap-tests:
name: ldap-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'
# DB service stays as a service container (you can also convert this to docker run later if desired)
services:
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_REGISTRY_DIR: /srv/comanage-registry
DB_ENGINE: ${{ matrix.db.engine }}
# Gate switch: only workflow_dispatch can enable it.
LDAP_CI_ENABLED: ${{ github.event_name == 'workflow_dispatch' && inputs.enable == 'true' }}
# 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"
# LDAP test config
COMANAGE_REGISTRY_LDAP_BASE_DN_TEST: "dc=example,dc=org"
COMANAGE_REGISTRY_LDAP_TLS_TEST: "false"
COMANAGE_REGISTRY_LDAP_USER_TEST: "test.user"
COMANAGE_REGISTRY_LDAP_PASSWORD_TEST: "test_password"
# LLDAP admin (for provisioning/seeding)
COMANAGE_REGISTRY_LLDAP_ADMIN_USER: "admin"
COMANAGE_REGISTRY_LLDAP_ADMIN_PASSWORD: "admin_password"
steps:
- name: CI disabled (skip LDAP pipeline, return success)
if: ${{ env.LDAP_CI_ENABLED != 'true' }}
shell: bash
run: |
set -euxo pipefail
echo "LDAP/LLDAP CI is currently disabled."
echo "To run it, use workflow_dispatch and set input 'enable' to 'true'."
exit 0
- name: Upgrade OS packages
if: ${{ env.LDAP_CI_ENABLED == 'true' }}
shell: bash
run: |
set -euxo pipefail
sudo apt-get update
sudo apt-get upgrade -y
- name: Checkout repository at the exact commit
if: ${{ env.LDAP_CI_ENABLED == 'true' }}
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: Install PHP 8.4 and extensions
if: ${{ env.LDAP_CI_ENABLED == 'true' }}
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 \
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}-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 LDAP tests
if: ${{ env.LDAP_CI_ENABLED == 'true' }}
shell: bash
run: |
set -euxo pipefail
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
git unzip curl ca-certificates \
ldap-utils
- name: Wait for DB to be ready (inside the service container)
if: ${{ env.LDAP_CI_ENABLED == 'true' }}
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
if: ${{ env.LDAP_CI_ENABLED == 'true' }}
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: Start LLDAP (docker run)
if: ${{ env.LDAP_CI_ENABLED == 'true' }}
shell: bash
run: |
set -euxo pipefail
docker rm -f lldap || true
docker run -d --name lldap \
-p 3890:3890 \
-p 17170:17170 \
-e LLDAP_LDAP_BASE_DN="dc=example,dc=org" \
-e LLDAP_ADMIN_USERNAME="${COMANAGE_REGISTRY_LLDAP_ADMIN_USER}" \
-e LLDAP_ADMIN_PASSWORD="${COMANAGE_REGISTRY_LLDAP_ADMIN_PASSWORD}" \
-e LLDAP_JWT_SECRET="change-me-in-ci" \
-e LLDAP_KEY_SEED="change-me-in-ci" \
lldap/lldap:stable
- name: Determine LDAP host/port for published ports
if: ${{ env.LDAP_CI_ENABLED == 'true' }}
shell: bash
run: |
set -euxo pipefail
if [ -f /.dockerenv ]; then
LDAP_HOST="$(ip route | awk '/default/ {print $3; exit}')"
else
LDAP_HOST="127.0.0.1"
fi
{
echo "COMANAGE_REGISTRY_LDAP_HOST_TEST=${LDAP_HOST}"
echo "COMANAGE_REGISTRY_LDAP_PORT_TEST=3890"
} >> "$GITHUB_ENV"
- name: Wait for LDAP to be ready (TCP)
if: ${{ env.LDAP_CI_ENABLED == 'true' }}
shell: bash
run: |
set -euxo pipefail
php -r '
$h=getenv("COMANAGE_REGISTRY_LDAP_HOST_TEST");
$p=(int)getenv("COMANAGE_REGISTRY_LDAP_PORT_TEST");
for ($i=0; $i<60; $i++) {
$fp=@fsockopen($h,$p,$errno,$errstr,1);
if ($fp) { fclose($fp); echo "LDAP TCP ready at $h:$p\n"; exit(0); }
sleep(1);
}
fwrite(STDERR,"LDAP not reachable at $h:$p\n");
exit(1);
'
- name: Create local/config/database.php placeholder (optional)
shell: bash
run: |
set -euxo pipefail
cd "${COMANAGE_REGISTRY_DIR}/local/config"
sudo mkdir -p .
sudo tee database.php > /dev/null <<'PHP'
<?php
// Intentionally empty for CI: tests/bootstrap.php configures the 'test' datasource via env vars.
return [];
PHP
sudo chown www-data:www-data database.php || true
- name: Composer update phpunit only
if: ${{ env.LDAP_CI_ENABLED == 'true' }}
shell: bash
working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app
run: |
set -euxo pipefail
composer update phpunit/phpunit --with-all-dependencies
- name: Run PHPUnit LDAP-only tests
if: ${{ env.LDAP_CI_ENABLED == 'true' }}
shell: bash
working-directory: ${{ env.COMANAGE_REGISTRY_DIR }}/app
run: |
set -euxo pipefail
vendor/bin/phpunit --group ldap --testdox
- name: Stop LLDAP
if: ${{ always() && env.LDAP_CI_ENABLED == 'true' }}
shell: bash
run: |
set -euxo pipefail
docker rm -f lldap || true