141 lines
3.4 KiB
Bash
141 lines
3.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Test script for Secure Proxy in dev mode
|
|
# This script verifies that the application works correctly without OIDC
|
|
|
|
set -e
|
|
|
|
echo "🧪 Testing Secure Proxy in Development Mode"
|
|
echo "=============================================="
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
RED='\033[0;31m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Function to test endpoint
|
|
test_endpoint() {
|
|
local method=$1
|
|
local endpoint=$2
|
|
local expected_status=$3
|
|
local data=$4
|
|
|
|
echo -n "Testing $method $endpoint... "
|
|
|
|
if [ -n "$data" ]; then
|
|
response=$(curl -s -w "\n%{http_code}" -X "$method" "http://localhost:3000$endpoint" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$data")
|
|
else
|
|
response=$(curl -s -w "\n%{http_code}" -X "$method" "http://localhost:3000$endpoint")
|
|
fi
|
|
|
|
status=$(echo "$response" | tail -n1)
|
|
body=$(echo "$response" | head -n-1)
|
|
|
|
if [ "$status" = "$expected_status" ]; then
|
|
echo -e "${GREEN}✓${NC} (Status: $status)"
|
|
echo "$body"
|
|
else
|
|
echo -e "${RED}✗${NC} (Expected: $expected_status, Got: $status)"
|
|
echo "$body"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Wait for server
|
|
echo "Waiting for server to be ready..."
|
|
max_attempts=30
|
|
attempt=0
|
|
|
|
while [ $attempt -lt $max_attempts ]; do
|
|
if curl -s http://localhost:3000 > /dev/null 2>&1; then
|
|
echo -e "${GREEN}✓${NC} Server is ready"
|
|
break
|
|
fi
|
|
attempt=$((attempt + 1))
|
|
sleep 1
|
|
done
|
|
|
|
if [ $attempt -eq $max_attempts ]; then
|
|
echo -e "${RED}✗${NC} Server did not start in time"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo "📋 Running Tests"
|
|
echo "================"
|
|
|
|
# Test 1: Home page redirects
|
|
echo ""
|
|
echo "Test 1: Home page redirect"
|
|
test_endpoint "GET" "/" 302 || true
|
|
|
|
# Test 2: Login page shows (in dev mode)
|
|
echo ""
|
|
echo "Test 2: Login page (should show dev mode message)"
|
|
test_endpoint "GET" "/login" 200 || true
|
|
|
|
# Test 3: Create a service via API
|
|
echo ""
|
|
echo "Test 3: Create a service"
|
|
SERVICE_DATA='{
|
|
"name": "Test Service",
|
|
"path": "/test",
|
|
"target_url": "http://httpbin.org/status/200",
|
|
"require_auth": false,
|
|
"description": "Test service for verification"
|
|
}'
|
|
test_endpoint "POST" "/api/services" 201 "$SERVICE_DATA" || true
|
|
|
|
# Test 4: List services
|
|
echo ""
|
|
echo "Test 4: List services"
|
|
test_endpoint "GET" "/api/services" 200 || true
|
|
|
|
# Test 5: Admin panel
|
|
echo ""
|
|
echo "Test 5: Admin panel HTML"
|
|
test_endpoint "GET" "/admin" 200 || true
|
|
|
|
# Test 6: Dashboard stats
|
|
echo ""
|
|
echo "Test 6: Dashboard stats"
|
|
test_endpoint "GET" "/dashboard/stats" 200 || true
|
|
|
|
# Test 7: Dashboard logs
|
|
echo ""
|
|
echo "Test 7: Dashboard logs"
|
|
test_endpoint "GET" "/dashboard/logs" 200 || true
|
|
|
|
# Test 8: Logout
|
|
echo ""
|
|
echo "Test 8: Logout (should redirect)"
|
|
test_endpoint "GET" "/logout" 302 || true
|
|
|
|
echo ""
|
|
echo "=============================================="
|
|
echo -e "${GREEN}✓ All tests completed!${NC}"
|
|
echo ""
|
|
echo "📊 Test Summary"
|
|
echo "==============="
|
|
echo "✓ Login page loads (dev mode)"
|
|
echo "✓ Admin API accessible"
|
|
echo "✓ Services can be created"
|
|
echo "✓ Dashboard is functional"
|
|
echo "✓ Logout works"
|
|
echo ""
|
|
echo "🎉 Secure Proxy is working in development mode!"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo "1. Open http://localhost:3000/admin in your browser"
|
|
echo "2. Create some test services"
|
|
echo "3. Test the reverse proxy with real backends"
|
|
echo "4. Review logs in the dashboard"
|
|
echo ""
|
|
echo "To transition to production:"
|
|
echo "1. Set up Keycloak"
|
|
echo "2. Update OIDC settings in .env"
|
|
echo "3. Restart the server"
|