Created comprehensive E2E verification framework: - E2E_VERIFICATION.md: Complete manual testing guide with 9 scenarios - scripts/verify-e2e-rate-limiting.sh: Automated API testing script - scripts/test-concurrent-rate-limit.sh: Concurrent request testing - scripts/reset-rate-limit.sh: Database reset utility for testing - SUBTASK_5-1_VERIFICATION_REPORT.md: Status and blocker documentation Fixed middleware configuration: - Updated src/middleware.ts matcher to exclude /api/ routes - Changed from complex negative lookahead to explicit locale matching - Pattern now: ['/', '/(de|en|sr)/:path*'] Known issue: - Middleware fix requires dev server restart to take effect - API routes currently return 404 until server is restarted - All implementation code is complete and ready for testing Test coverage: - Basic rate limiting flow (5 requests succeed, 6th fails) - Response header verification (X-RateLimit-Remaining, Retry-After) - Persistence testing (across page refreshes, browser sessions) - Multi-locale support (en, de, sr) - Error handling and validation - Concurrent request handling - Database record verification Next steps: 1. Restart dev server: npm run dev 2. Run automated tests: bash ./scripts/verify-e2e-rate-limiting.sh 3. Perform manual browser testing per E2E_VERIFICATION.md 4. Verify database records in Supabase 5. Mark subtask as completed Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
80 lines
2.3 KiB
Bash
80 lines
2.3 KiB
Bash
#!/bin/bash
|
|
|
|
# Concurrent Rate Limiting Test
|
|
# Tests that rate limiting correctly handles simultaneous requests
|
|
|
|
echo "================================================"
|
|
echo "Concurrent Rate Limiting Test"
|
|
echo "================================================"
|
|
echo ""
|
|
|
|
API_URL="http://localhost:3000/api/contact"
|
|
CONCURRENT_REQUESTS=7
|
|
|
|
echo "Sending $CONCURRENT_REQUESTS concurrent requests..."
|
|
echo "Expected: First 5 should succeed (200), remaining should fail (429)"
|
|
echo ""
|
|
|
|
# Create a temporary directory for results
|
|
TMP_DIR=$(mktemp -d)
|
|
trap "rm -rf $TMP_DIR" EXIT
|
|
|
|
# Send concurrent requests
|
|
for i in $(seq 1 $CONCURRENT_REQUESTS); do
|
|
{
|
|
response=$(curl -s -w "\n%{http_code}" -X POST "$API_URL" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"name\":\"Concurrent Test $i\",\"email\":\"test$i@example.com\",\"message\":\"Concurrent message $i\"}")
|
|
|
|
status_code=$(echo "$response" | tail -n 1)
|
|
echo "$i:$status_code" > "$TMP_DIR/result_$i.txt"
|
|
echo "Request #$i: $status_code"
|
|
} &
|
|
done
|
|
|
|
# Wait for all background jobs to complete
|
|
wait
|
|
|
|
echo ""
|
|
echo "Results:"
|
|
echo "--------"
|
|
|
|
# Analyze results
|
|
success_count=0
|
|
rate_limited_count=0
|
|
|
|
for i in $(seq 1 $CONCURRENT_REQUESTS); do
|
|
if [ -f "$TMP_DIR/result_$i.txt" ]; then
|
|
result=$(cat "$TMP_DIR/result_$i.txt")
|
|
status_code=$(echo "$result" | cut -d':' -f2)
|
|
|
|
if [ "$status_code" = "200" ]; then
|
|
((success_count++))
|
|
echo "✅ Request #$i: 200 OK"
|
|
elif [ "$status_code" = "429" ]; then
|
|
((rate_limited_count++))
|
|
echo "🚫 Request #$i: 429 Rate Limited"
|
|
else
|
|
echo "⚠️ Request #$i: $status_code (Unexpected)"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
echo "Summary:"
|
|
echo "--------"
|
|
echo "Successful: $success_count"
|
|
echo "Rate Limited: $rate_limited_count"
|
|
echo ""
|
|
|
|
# Verify expectations
|
|
if [ $success_count -le 5 ] && [ $rate_limited_count -ge 2 ]; then
|
|
echo "✅ Concurrent rate limiting works correctly!"
|
|
echo "Note: Due to timing, some requests within the limit might also be blocked."
|
|
echo "This is acceptable behavior for concurrent requests."
|
|
else
|
|
echo "⚠️ Results might indicate an issue:"
|
|
echo "Expected: ~5 successful, ~2 rate limited"
|
|
echo "Got: $success_count successful, $rate_limited_count rate limited"
|
|
fi
|