clean routes
This commit is contained in:
148
DOCKER_AUTH_FIXES_SUMMARY.md
Normal file
148
DOCKER_AUTH_FIXES_SUMMARY.md
Normal file
@@ -0,0 +1,148 @@
|
||||
# Docker Auth/Session Test Fixes Summary
|
||||
|
||||
## Problem
|
||||
The docker-compose.test.yml setup had 18 failing tests related to authentication session issues. The main problems were:
|
||||
|
||||
1. **Service dependency issues**: Website container started before deps container finished installing
|
||||
2. **Cookie domain problems**: Mock API cookies weren't working properly in Docker environment
|
||||
3. **Network connectivity**: Website couldn't reach API due to timing and configuration issues
|
||||
|
||||
## Root Causes
|
||||
|
||||
### 1. Missing Service Dependencies
|
||||
- Website container didn't wait for deps container to complete
|
||||
- API container didn't wait for deps container
|
||||
- This caused "next: not found" and module resolution errors
|
||||
|
||||
### 2. Cookie Domain Issues
|
||||
- Mock API set cookies without domain specification
|
||||
- In Docker, cookies need proper domain settings to work across containers
|
||||
- Browser at localhost:3100 couldn't access cookies from API at localhost:3101
|
||||
|
||||
### 3. Slow npm Install
|
||||
- deps container took too long to install packages
|
||||
- Website container would timeout waiting
|
||||
- No proper health checks or completion signals
|
||||
|
||||
## Fixes Applied
|
||||
|
||||
### 1. Updated `docker-compose.test.yml`
|
||||
|
||||
**Before:**
|
||||
```yaml
|
||||
website:
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_healthy
|
||||
```
|
||||
|
||||
**After:**
|
||||
```yaml
|
||||
deps:
|
||||
command: ["sh", "-lc", "echo '[deps] Ready' && sleep infinity"]
|
||||
# Simple command that completes immediately
|
||||
|
||||
api:
|
||||
depends_on:
|
||||
deps:
|
||||
condition: service_started
|
||||
# Added deps dependency
|
||||
|
||||
website:
|
||||
depends_on:
|
||||
deps:
|
||||
condition: service_started # Wait for deps
|
||||
api:
|
||||
condition: service_healthy # Wait for API
|
||||
command:
|
||||
- sh
|
||||
- -lc
|
||||
- |
|
||||
# Check if node_modules exist, install if needed
|
||||
if [ ! -d "node_modules" ] || [ ! -f "node_modules/.bin/next" ]; then
|
||||
echo "[website] Installing dependencies..."
|
||||
npm install --no-package-lock --include-workspace-root --no-audit --fund=false --prefer-offline
|
||||
else
|
||||
echo "[website] node_modules already present"
|
||||
fi
|
||||
echo "[website] Starting Next.js dev server..."
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### 2. Fixed `testing/mock-api-server.cjs`
|
||||
|
||||
**Before:**
|
||||
```javascript
|
||||
const cookies = [
|
||||
`gp_session=${encodeURIComponent(gpSessionValue)}; Path=/; HttpOnly`,
|
||||
`gridpilot_demo_mode=${encodeURIComponent(mode)}; Path=/`,
|
||||
];
|
||||
```
|
||||
|
||||
**After:**
|
||||
```javascript
|
||||
// Set cookies with proper domain for Docker environment
|
||||
const domain = 'localhost';
|
||||
const cookies = [
|
||||
`gp_session=${encodeURIComponent(gpSessionValue)}; Path=/; HttpOnly; Domain=${domain}`,
|
||||
`gridpilot_demo_mode=${encodeURIComponent(mode)}; Path=/; Domain=${domain}`,
|
||||
];
|
||||
```
|
||||
|
||||
### 3. Verified `playwright.website.config.ts`
|
||||
- Already correctly configured for Docker
|
||||
- Uses `http://localhost:3100` when `DOCKER_SMOKE=true`
|
||||
- Proper timeout and retry settings
|
||||
|
||||
## Key Configuration Changes
|
||||
|
||||
### Environment Variables
|
||||
- `API_BASE_URL=http://api:3000` (internal Docker network)
|
||||
- `NEXT_PUBLIC_API_BASE_URL=http://localhost:3101` (external for browser)
|
||||
- `DOCKER_SMOKE=true` (tells tests to use Docker ports)
|
||||
|
||||
### Cookie Settings
|
||||
- Added `Domain=localhost` to all Set-Cookie headers
|
||||
- Ensures cookies work across localhost:3100 and localhost:3101
|
||||
|
||||
### Service Dependencies
|
||||
- deps → api → website (proper startup order)
|
||||
- Health checks ensure services are ready before dependent services start
|
||||
|
||||
## Testing the Fixes
|
||||
|
||||
### Quick Test
|
||||
```bash
|
||||
# Start services
|
||||
docker-compose -f docker-compose.test.yml up -d
|
||||
|
||||
# Wait for startup
|
||||
sleep 30
|
||||
|
||||
# Run tests
|
||||
DOCKER_SMOKE=true npx playwright test --config=playwright.website.config.ts
|
||||
```
|
||||
|
||||
### Verification Steps
|
||||
1. Check deps container starts immediately
|
||||
2. API container waits for deps and becomes healthy
|
||||
3. Website container waits for both deps and API
|
||||
4. Cookies are set with proper domain
|
||||
5. Tests can access both website and API
|
||||
|
||||
## Expected Results
|
||||
- All 93 tests should pass
|
||||
- No "next: not found" errors
|
||||
- No connection refused errors
|
||||
- Auth sessions work properly in Docker
|
||||
- Cookie-based authentication flows correctly
|
||||
|
||||
## Files Modified
|
||||
1. `docker-compose.test.yml` - Service dependencies and startup logic
|
||||
2. `testing/mock-api-server.cjs` - Cookie domain settings
|
||||
3. `test-docker-fix.sh` - Verification script (new)
|
||||
|
||||
## Notes
|
||||
- The fixes address the core infrastructure issues that were causing auth/session failures
|
||||
- The mock API now properly simulates real authentication flows
|
||||
- Docker networking is properly configured for cross-container communication
|
||||
Reference in New Issue
Block a user