# Multi-Service Site QA Patterns ## Architecture Recognition When a site has multiple subdomains or services, first map the architecture: | Indicator | What it means | |-----------|--------------| | Multiple `main.py` files in subdirectories | Separate service entry points | | `shared/` directory with auth/cookie modules | Shared authentication across services | | Different port numbers in config | Local dev runs separate processes | | Subdomain routing (auth.ephron.ren, blog.ephron.ren) | Production reverse proxy setup | ## Common Multi-Service Patterns (FastAPI) ``` project/ ├── auth/src/main.py # Auth service (login, register, RBAC) ├── blog/src/main.py # Blog service (posts, comments, likes) ├── canvas/src/main.py # Canvas service (AI-generated pages) ├── prompt/src/main.py # Prompt service (prompt CRUD) ├── home/src/main.py # Homepage service ├── shared/ # Shared modules (auth, CSRF, audit, templating) │ ├── auth_users.py │ ├── cookie_utils.py │ ├── csrf.py │ ├── templating.py │ └── ports.py # Service URL configuration └── main.py # Unified launcher (starts all services) ``` ## Cross-Service Cookie Auth Testing 1. Login on auth service → get `ephron_auth` cookie 2. Verify cookie domain is `.example.com` (not service-specific) 3. Test cookie propagation: visit each service, check logged-in state 4. Test logout: logout on one service, verify all services see logged-out state ## Route File Reading Strategy For each service, read these files in order: 1. `src/routes/pages.py` — public page routes 2. `src/routes/admin.py` — admin/management routes 3. `src/routes/api.py` — API endpoints 4. `src/routes/service_api.py` — inter-service APIs 5. `src/services/auth.py` — auth helpers (what permissions are checked) Extract from each route: - `@router.get("/path")` or `@router.post("/path")` → HTTP method + path - `_require_auth(ephron_auth, request, permission="X.Y.Z")` → required permission - `@limiter.limit("N/minute")` → rate limit - `Form(...)` parameters → required form fields - `Cookie(default=None)` → cookie dependencies ## Test Matrix Generation For each discovered route, create test cases: - **Happy path**: valid inputs, correct auth → expected success - **Auth failure**: no cookie / wrong role → expected redirect or 403 - **Validation failure**: missing fields, invalid data → expected error - **Rate limit**: exceed the limit → expected 429 - **CSRF**: missing/invalid CSRF token → expected rejection ## Consistency Checks Across Services Build a comparison table: | Feature | Service A | Service B | Service C | |---------|-----------|-----------|-----------| | mobile.css loaded? | ✅ | ❌ | ❌ | | loader.js loaded? | ❌ | ✅ | ✅ | | Site navigation? | ✅ | ✅ | ❌ | | user-scalable? | yes | no | no | Inconsistencies are bugs — all services sharing a design system should be consistent. ## Curl-Based QA Techniques (Session-Proven) When browser automation is unavailable, these curl patterns reliably test multi-service sites: ### Cookie Management ```bash # Each curl -c (save) / -b (read) needs a SEPARATE cookie file per request chain curl -s -c /tmp/c1.txt https://auth.example.com/login > /tmp/login.html curl -s -b /tmp/c1.txt -c /tmp/c2.txt -X POST https://auth.example.com/api/login \ -d "username=user&password=pass&csrf_token=$CSRF" > /dev/null # Verify: grep ephron /tmp/c2.txt ``` ### CSRF Token Extraction (FastAPI/Tortoise patterns) ```bash # Most reliable — matches name= then grabs value: grep -oP 'name="csrf_token"[^>]*value="\K[^"]+' /tmp/page.html | head -1 # Fallback variants: grep -oP 'csrf_token.*?value="\K[^"]+' /tmp/page.html | head -1 grep -i 'csrf' /tmp/page.html | grep -oP 'value="\K[^"]+' | head -1 ``` ### API Login: JSON vs Form-Encoded ```bash # Modern FastAPI services use /api/login with JSON: curl -s -b /tmp/c.txt -c /tmp/c.txt -X POST https://auth.example.com/api/login \ -H "Content-Type: application/json" \ -d '{"username":"user","password":"pass","csrf_token":"TOKEN"}' # Legacy form-encoded (action="/login"): curl -s -b /tmp/c.txt -c /tmp/c.txt -X POST https://auth.example.com/login \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "username=user&password=pass&csrf_token=$CSRF" ``` ### Post-Login Redirect Chain ```bash # Follow 303 redirect chain automatically: curl -sL -b /tmp/c.txt -c /tmp/c.txt -X POST https://auth.example.com/api/login \ -d "username=u&password=p&csrf_token=$CSRF" -w "\nHTTP:%{http_code}" # Get final status: curl -sL ... -o /dev/null -w "%{http_code}" ``` ### Health Checks (All Services at Once) ```bash for svc in www auth blog canvas prompt; do result=$(curl -s "https://$svc.example.com/health") echo "$svc: $result" done ``` ### Security Headers (All Services) ```bash for svc in www auth blog canvas prompt; do echo "=== $svc ===" curl -sI "https://$svc.example.com/" | grep -iE \ 'x-content-type|x-frame|referrer-policy|content-security|set-cookie' done ``` ### CSP Deep Analysis — script-src-elem Override Trap ```bash # Extract full CSP header curl -sI https://www.example.com/admin | grep -i content-security-policy # Look for script-src-elem which OVERRIDES script-src for