Skip to content

Commit 32a43a8

Browse files
committed
ci: add keycloak tests
1 parent 41fc853 commit 32a43a8

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ jobs:
9696
oidc_iframe: true
9797
- suite: smoke
9898
test_suites: smoke
99+
- suite: keycloak
100+
test_suites: journeys,keycloak
101+
keycloak: true
99102
env:
100103
BASE_URL_OCIS: localhost:9200
101104
HEADLESS: true
@@ -154,6 +157,9 @@ jobs:
154157
if [[ "${{ matrix.suites.oidc_iframe }}" == "true" ]]; then
155158
flags="$flags --oidc-iframe"
156159
fi
160+
if [[ "${{ matrix.suites.keycloak }}" == "true" ]]; then
161+
flags="$flags --keycloak"
162+
fi
157163
cd "${{ github.workspace }}/tests/actions"
158164
bash setup-services.sh $flags
159165

tests/actions/setup-services.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ OCIS_COMMIT=latest # `latest` or a specific commit SHA, e.g. `9ac0452d61f062572f
88

99
COLLABORA_CODE_IMAGE=collabora/code:25.04.7.3.1
1010
ONLYOFFICE_DOCUMENT_SERVER_IMAGE=onlyoffice/documentserver:9.2.1
11+
POSTGRES_ALPINE_IMAGE=postgres:alpine3.18
12+
KEYCLOAK_IMAGE=quay.io/keycloak/keycloak:26.5.6
1113

1214
TIKA_ENABLED=false
1315
FEDERATION_ENABLED=false
1416
COLLABORATION_ENABLED=false
1517
OIDC_ENABLED=false
1618
OIDC_IFRAME_ENABLED=false
19+
KEYCLOAK_ENABLED=false
1720

1821
while [[ $# -gt 0 ]]; do
1922
case "$1" in
@@ -37,6 +40,10 @@ while [[ $# -gt 0 ]]; do
3740
OIDC_IFRAME_ENABLED=true
3841
shift
3942
;;
43+
--keycloak)
44+
KEYCLOAK_ENABLED=true
45+
shift
46+
;;
4047
*)
4148
echo "Unknown argument: $1"
4249
exit 1
@@ -237,10 +244,69 @@ wait_for_app_providers() {
237244
exit 1
238245
}
239246

247+
generate_keycloak_certs() {
248+
echo "Generating keycloak certs"
249+
250+
mkdir -p "$GITHUB_WORKSPACE/keycloak-certs"
251+
openssl req -x509 -newkey rsa:2048 \
252+
-keyout "$GITHUB_WORKSPACE/keycloak-certs/keycloakkey.pem" \
253+
-out "$GITHUB_WORKSPACE/keycloak-certs/keycloakcrt.pem" \
254+
-nodes -days 365 -subj '/CN=keycloak'
255+
chmod -R 777 "$GITHUB_WORKSPACE/keycloak-certs"
256+
}
257+
258+
setup_postgres() {
259+
echo "Setting up postgres"
260+
261+
# GitHub runners ship PostgreSQL pre-started on 5432, but we need to stop it to avoid conflicts.
262+
sudo systemctl stop postgresql || true
263+
264+
docker run -d --name postgres --network host \
265+
-e POSTGRES_DB=keycloak \
266+
-e POSTGRES_USER=keycloak \
267+
-e POSTGRES_PASSWORD=keycloak \
268+
$POSTGRES_ALPINE_IMAGE
269+
timeout 30 bash -c 'until docker exec postgres pg_isready -U keycloak; do sleep 1; done'
270+
}
271+
272+
setup_keycloak() {
273+
# Patch realm: replace Drone Docker hostname with localhost IP
274+
sed 's|https://ocis-server:9200|https://127.0.0.1:9200|g' \
275+
$GITHUB_WORKSPACE/tests/drone/ocis_keycloak/ocis-ci-realm.dist.json > /tmp/ocis-realm.json
276+
docker run -d --name keycloak --network host \
277+
-e OCIS_DOMAIN=https://127.0.0.1:9200 \
278+
-e KC_HOSTNAME=localhost \
279+
-e KC_PORT=8443 \
280+
-e KC_DB=postgres \
281+
-e "KC_DB_URL=jdbc:postgresql://localhost:5432/keycloak" \
282+
-e KC_DB_USERNAME=keycloak \
283+
-e KC_DB_PASSWORD=keycloak \
284+
-e KC_FEATURES=impersonation \
285+
-e KC_BOOTSTRAP_ADMIN_USERNAME=admin \
286+
-e KC_BOOTSTRAP_ADMIN_PASSWORD=admin \
287+
-e KC_HTTPS_CERTIFICATE_FILE=$GITHUB_WORKSPACE/keycloak-certs/keycloakcrt.pem \
288+
-e KC_HTTPS_CERTIFICATE_KEY_FILE=$GITHUB_WORKSPACE/keycloak-certs/keycloakkey.pem \
289+
-v "$GITHUB_WORKSPACE/keycloak-certs:/keycloak-certs:ro" \
290+
-v "/tmp/ocis-realm.json:/opt/keycloak/data/import/oCIS-realm.json:ro" \
291+
$KEYCLOAK_IMAGE \
292+
start-dev --proxy-headers xforwarded \
293+
--spi-connections-http-client-default-disable-trust-manager=true \
294+
--import-realm --health-enabled=true
295+
timeout 300 bash -c 'until curl -skf https://localhost:9000/health/ready; do sleep 3; done' \
296+
|| (echo "=== keycloak logs ===" && docker logs keycloak --tail 80 && exit 1)
297+
echo "keycloak ready."
298+
}
299+
240300
if $TIKA_ENABLED; then
241301
setup_tika
242302
fi
243303

304+
if $KEYCLOAK_ENABLED; then
305+
generate_keycloak_certs
306+
setup_postgres
307+
setup_keycloak
308+
fi
309+
244310
clone_ocis
245311
setup_ocis "ocis" 9200
246312

0 commit comments

Comments
 (0)