feat: add live-test container for the directory adapter

A test stage in the Dockerfile and an opt-in compose profile run the live
directory checks against the test OU inside the image, reading the LDAP_*
values from .env.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N3t4WL7bd9bdHHNjEsxzqC
This commit is contained in:
2026-10-17 18:52:06 +02:00
co-authored by Claude Sonnet 5.5
parent 96d3e77161
commit 7458a2a815
3 changed files with 32 additions and 2 deletions
+6
View File
@@ -18,6 +18,12 @@ RUN SECRET_KEY=build-time-only-value-not-used-at-runtime-000000 \
LDAP_CA_FILE=/app/README.md LDAP_PUBLISHER_GROUP_DN=build LDAP_ADMIN_GROUP_DN=build \
/app/.venv/bin/python manage.py collectstatic --noinput
# Not part of the runtime image: `docker compose --profile test run --rm live-test`
FROM builder AS test
RUN uv sync --frozen --no-install-project
ENV PATH="/app/.venv/bin:$PATH"
CMD ["python", "-m", "pytest", "portal/tests/test_directory_live.py", "-v", "-p", "no:cacheprovider"]
FROM python:3.13-slim
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 PATH="/app/.venv/bin:$PATH"
RUN apt-get update \
+5 -2
View File
@@ -51,10 +51,13 @@ uv run ruff check .
### Directory adapter against the test OU
`uv sync` builds `python-ldap`, which needs the OpenLDAP and SASL development libraries (the Docker image installs them). The automated tests use an in-memory fake and a stand-in for the `ldap` module, so they run anywhere. To check the real adapter against the test OU, run this on a Linux host with the libraries installed (never against the production OU):
`uv sync` builds `python-ldap`, which needs the OpenLDAP and SASL development libraries (the Docker image installs them). The automated tests use an in-memory fake and a stand-in for the `ldap` module, so they run anywhere.
To check the real adapter against the test OU (never the production OU), run the opt-in test container on the Linux host. It reads the `LDAP_*` values and `CA_FILE_HOST` from `.env`; the test user's current password comes from your shell:
```sh
PORTAL_LIVE_LDAP=1 LIVE_LDAP_SERVER=... LIVE_LDAP_USER_OU_DN=... LIVE_LDAP_BIND_DN=... LIVE_LDAP_BIND_PASSWORD=... LIVE_LDAP_CA_FILE=... LIVE_LDAP_PUBLISHER_GROUP_DN=... LIVE_LDAP_ADMIN_GROUP_DN=... LIVE_LDAP_TEST_PASSWORD=<current password of ptest-user1> uv run pytest portal/tests/test_directory_live.py -v
LIVE_LDAP_TEST_PASSWORD=<current password of ptest-user1> \
docker compose --profile test run --rm live-test
```
It restores what it writes and does not change any password.
+21
View File
@@ -17,6 +17,27 @@ services:
- no-new-privileges:true
restart: unless-stopped
# Opt-in checks against the test OU. Reads the LDAP_* values from .env; the test user's
# current password comes from the shell:
# LIVE_LDAP_TEST_PASSWORD=... docker compose --profile test run --rm live-test
live-test:
profiles: ["test"]
build:
context: .
target: test
environment:
PORTAL_LIVE_LDAP: "1"
LIVE_LDAP_SERVER: ${LDAP_SERVER:-}
LIVE_LDAP_USER_OU_DN: ${LDAP_USER_OU_DN:-}
LIVE_LDAP_BIND_DN: ${LDAP_BIND_DN:-}
LIVE_LDAP_BIND_PASSWORD: ${LDAP_BIND_PASSWORD:-}
LIVE_LDAP_CA_FILE: /certs/ca.pem
LIVE_LDAP_PUBLISHER_GROUP_DN: ${LDAP_PUBLISHER_GROUP_DN:-}
LIVE_LDAP_ADMIN_GROUP_DN: ${LDAP_ADMIN_GROUP_DN:-}
LIVE_LDAP_TEST_PASSWORD:
volumes:
- ${CA_FILE_HOST:?set CA_FILE_HOST in .env}:/certs/ca.pem:ro
volumes:
data:
backups: