Skip to content

Commit 7b342b4

Browse files
oriolriusclaude
andcommitted
docs: improve E2E testing documentation
- Add architecture diagram for E2E Docker environment - Document OIDC_DISCOVERY_BASE_URL for Docker networking - Add E2E-specific troubleshooting section - Fix typo in "Image Pull Failures" heading - Add build steps before running E2E tests - Document Keycloak v26+ hostname configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 05759cd commit 7b342b4

File tree

2 files changed

+95
-6
lines changed

2 files changed

+95
-6
lines changed

DEPLOYMENT.md

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,10 @@ Add these to your `.env` file:
222222

223223
| Variable | Example | Description |
224224
|----------|---------|-------------|
225-
| `OIDC_ISSUER` | `https://keycloak.example.com/realms/pki` | OIDC provider base URL |
225+
| `OIDC_ISSUER` | `https://keycloak.example.com/realms/pki` | OIDC provider base URL (must match token `iss` claim) |
226226
| `OIDC_AUDIENCE` | `pki-web,pki-service` | Expected audience claim(s), comma-separated |
227227
| `OIDC_ROLES_CLAIM` | `realm_access.roles` | JWT path to roles (provider-specific) |
228+
| `OIDC_DISCOVERY_BASE_URL` | _(optional)_ | Override URL for fetching OIDC discovery (for Docker networking) |
228229

229230
**Provider-specific issuer URLs:**
230231
- **Keycloak**: `https://keycloak.example.com/realms/your-realm`
@@ -386,21 +387,54 @@ Available tags:
386387

387388
PKI Manager includes comprehensive E2E tests for Role-Based Access Control (RBAC). Tests can run against a local Docker environment or production.
388389

390+
### E2E Architecture
391+
392+
```
393+
┌─────────────────────────────────────────────────────────────────────┐
394+
│ Host Machine │
395+
│ ┌────────────────┐ │
396+
│ │ Playwright │ ──────────────────┐ │
397+
│ │ Test Runner │ │ │
398+
│ └────────────────┘ ▼ │
399+
│ │ localhost:8080 (Frontend) │
400+
│ │ localhost:3000 (Backend API) │
401+
│ │ localhost:8180 (Keycloak) │
402+
│ │ │ │
403+
│ ═══════╪═════════════════════════════╪═════════════════════════ │
404+
│ │ Docker Network │ │
405+
│ ▼ (pki-e2e-network) │
406+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
407+
│ │ Frontend │ │ Backend │ │ Keycloak │ │ KMS │ │
408+
│ │ (nginx) │ │ (Node.js) │ │ (OIDC) │ │ (Cosmian) │ │
409+
│ │ :8080 │──│ :3000 │──│ :8080 │ │ :9998 │ │
410+
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │
411+
│ │ │
412+
│ └──── OIDC_DISCOVERY_BASE_URL ────┘ │
413+
│ (keycloak:8080) │
414+
└─────────────────────────────────────────────────────────────────────┘
415+
```
416+
417+
The backend uses `OIDC_DISCOVERY_BASE_URL` to fetch OIDC configuration from the Docker network (`keycloak:8080`) while validating tokens against the issuer URL that browsers use (`localhost:8180`).
418+
389419
### Local E2E Testing (Recommended)
390420
391421
The `docker-compose.e2e.yml` provides a complete isolated environment for testing:
392422
393423
```bash
394-
# 1. Start the E2E environment (includes Keycloak with pre-configured test users)
424+
# 1. Build images with latest code (if you made changes)
425+
docker build --target backend -t ghcr.io/oriolrius/pki-manager-web/backend:latest -f docker/Dockerfile .
426+
docker build --target frontend -t ghcr.io/oriolrius/pki-manager-web/frontend:latest -f docker/Dockerfile .
427+
428+
# 2. Start the E2E environment (includes Keycloak with pre-configured test users)
395429
docker compose -f docker/docker-compose.e2e.yml up -d
396430
397-
# 2. Wait for all services to be healthy (~60-90 seconds for Keycloak)
431+
# 3. Wait for all services to be healthy (~60-90 seconds for Keycloak)
398432
docker compose -f docker/docker-compose.e2e.yml ps
399433
400-
# 3. Run the RBAC tests
434+
# 4. Run the RBAC tests
401435
pnpm playwright test tests/e2e-rbac.spec.ts --reporter=list
402436
403-
# 4. Cleanup when done
437+
# 5. Cleanup when done
404438
docker compose -f docker/docker-compose.e2e.yml down -v
405439
```
406440

@@ -461,7 +495,7 @@ pnpm playwright test tests/e2e-rbac.spec.ts
461495
cd backend && pnpm typecheck
462496
```
463497

464-
###Image Pull Failures
498+
### Image Pull Failures
465499

466500
**Problem**: Cannot pull from ghcr.io
467501

@@ -529,6 +563,40 @@ FRONTEND_EXTERNAL_PORT=8081
529563
KMS_EXTERNAL_PORT=9999
530564
```
531565

566+
### E2E Test Failures
567+
568+
**Problem**: "no such table: audit_log" error
569+
570+
**Solution**: Database migrations didn't run. The E2E docker-compose automatically runs migrations on startup. If using a custom setup:
571+
```bash
572+
docker exec pki-e2e-backend node /app/backend/dist/db/migrate.js
573+
```
574+
575+
**Problem**: OIDC token validation fails in Docker
576+
577+
**Solution**: Ensure `OIDC_DISCOVERY_BASE_URL` is set for Docker networking:
578+
```yaml
579+
# docker-compose.e2e.yml
580+
environment:
581+
- OIDC_ISSUER=http://localhost:8180/realms/pki-e2e
582+
- OIDC_DISCOVERY_BASE_URL=http://keycloak:8080/realms/pki-e2e
583+
```
584+
585+
**Problem**: Keycloak healthcheck fails (timeout)
586+
587+
**Solution**: Keycloak 26+ takes ~60-90 seconds to start. The healthcheck has a 90-second start period. Check logs:
588+
```bash
589+
docker logs pki-e2e-keycloak
590+
```
591+
592+
**Problem**: Tests fail with "Login button not found"
593+
594+
**Solution**: Wait for all services to be healthy before running tests:
595+
```bash
596+
docker compose -f docker/docker-compose.e2e.yml ps
597+
# All services should show "healthy" status
598+
```
599+
532600
### Production Configuration
533601

534602
**Security Checklist**:

KEYCLOAK.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,27 @@ The `pki-e2e` realm is automatically imported when starting the E2E Docker envir
348348
- **Direct Access Grants**: Enabled (for automated testing)
349349
- **Brute Force Protection**: Disabled (to prevent test lockouts)
350350

351+
### Docker OIDC Networking
352+
353+
The E2E environment handles OIDC token validation in Docker with special configuration:
354+
355+
```yaml
356+
# Keycloak (v26+) - use full URL for consistent issuer
357+
environment:
358+
- KC_HOSTNAME=http://localhost:8180
359+
360+
# Backend - separate discovery URL for Docker networking
361+
environment:
362+
- OIDC_ISSUER=http://localhost:8180/realms/pki-e2e
363+
- OIDC_DISCOVERY_BASE_URL=http://keycloak:8080/realms/pki-e2e
364+
```
365+
366+
**Why this is needed:**
367+
1. Browser accesses Keycloak at `localhost:8180` and tokens have `iss: http://localhost:8180/...`
368+
2. Backend container cannot reach `localhost:8180` (it refers to the container itself)
369+
3. `OIDC_DISCOVERY_BASE_URL` tells the backend to fetch OIDC config from Docker network (`keycloak:8080`)
370+
4. The backend validates tokens against `OIDC_ISSUER` (what's in tokens) while fetching from the discovery URL
371+
351372
### Running E2E Tests
352373

353374
```bash

0 commit comments

Comments
 (0)