proxy-oidcv2/test.sh
2025-12-03 21:38:43 +01:00

186 lines
4.2 KiB
Bash

#!/bin/bash
# Complete test suite for Secure Proxy
echo "🧪 Running Secure Proxy Test Suite..."
echo ""
TEST_PASSED=0
TEST_FAILED=0
# Color codes
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Helper functions
pass() {
echo -e "${GREEN}${NC} $1"
TEST_PASSED=$((TEST_PASSED+1))
}
fail() {
echo -e "${RED}${NC} $1"
TEST_FAILED=$((TEST_FAILED+1))
}
warn() {
echo -e "${YELLOW}${NC} $1"
}
# Test 1: Node.js version
echo "Test 1: Environment"
if command -v node &> /dev/null; then
NODE_VERSION=$(node --version)
pass "Node.js installed: $NODE_VERSION"
else
fail "Node.js not installed"
fi
# Test 2: npm version
if command -v npm &> /dev/null; then
NPM_VERSION=$(npm --version)
pass "npm installed: $NPM_VERSION"
else
fail "npm not installed"
fi
echo ""
echo "Test 2: Project Structure"
# Test 3: Key directories
for dir in "src" "public" "scripts" "db" "sessions"; do
if [ -d "$dir" ]; then
pass "Directory exists: $dir"
else
fail "Directory missing: $dir"
fi
done
echo ""
echo "Test 3: Configuration Files"
# Test 4: Configuration files
if [ -f ".env" ]; then
pass "Configuration file exists: .env"
else
warn "No .env file (can use .env.example)"
fi
if [ -f "package.json" ]; then
pass "Package file exists: package.json"
else
fail "Missing: package.json"
fi
echo ""
echo "Test 4: Source Files"
# Test 5: Key source files
for file in \
"src/server.js" \
"src/config.js" \
"src/db.js" \
"src/middleware/oidcMiddleware.js" \
"src/middleware/security.js" \
"src/middleware/proxyMiddleware.js" \
"public/admin.html"; do
if [ -f "$file" ]; then
pass "File exists: $file"
else
fail "File missing: $file"
fi
done
echo ""
echo "Test 5: Dependencies"
# Test 6: node_modules
if [ -d "node_modules" ]; then
MODULES=$(find node_modules -maxdepth 1 -type d | wc -l)
pass "Dependencies installed: $MODULES packages"
else
warn "Dependencies not installed (run 'npm install')"
fi
echo ""
echo "Test 6: Database"
# Test 7: Database
if [ -f "db/services.db" ]; then
if command -v sqlite3 &> /dev/null; then
TABLES=$(sqlite3 db/services.db "SELECT count(*) FROM sqlite_master WHERE type='table';" 2>/dev/null)
if [ "$TABLES" -gt 0 ]; then
pass "Database initialized with $TABLES tables"
else
fail "Database exists but no tables"
fi
else
warn "sqlite3 not installed (can't verify database)"
fi
else
warn "Database not initialized yet (run 'npm run init-db')"
fi
echo ""
echo "Test 7: Scripts"
# Test 8: NPM scripts
for script in "start" "dev" "init-db" "seed-db"; do
if grep -q "\"$script\"" package.json; then
pass "NPM script available: $script"
else
fail "Missing NPM script: $script"
fi
done
echo ""
echo "Test 8: Documentation"
# Test 9: Documentation files
for doc in \
"00-START-HERE.md" \
"README.md" \
"QUICKSTART.md" \
"INSTALLATION.md" \
"ARCHITECTURE.md"; do
if [ -f "$doc" ]; then
pass "Documentation: $doc"
else
fail "Missing documentation: $doc"
fi
done
echo ""
echo "════════════════════════════════════════════════════════"
echo "Test Results:"
echo -e " ${GREEN}Passed: $TEST_PASSED${NC}"
if [ $TEST_FAILED -gt 0 ]; then
echo -e " ${RED}Failed: $TEST_FAILED${NC}"
else
echo -e " ${RED}Failed: 0${NC}"
fi
echo "════════════════════════════════════════════════════════"
if [ $TEST_FAILED -eq 0 ]; then
echo ""
echo "✅ All tests passed!"
echo ""
echo "Next steps:"
echo " 1. Start the server:"
echo " npm run dev"
echo ""
echo " 2. Open browser:"
echo " http://localhost:3000"
exit 0
else
echo ""
echo "⚠️ Some tests failed. Please address the issues above."
echo ""
echo "Common fixes:"
echo " - npm install # Install dependencies"
echo " - npm run init-db # Initialize database"
exit 1
fi