#!/bin/bash
# Simple test script for projects API
BASE_URL="https://mcp-vultr.l.supported.systems"
echo "π Testing Projects API"
echo "=========================="
# First, let's test authentication through the GitHub OAuth flow
echo "π Testing GitHub OAuth Flow..."
echo " Initiating GitHub login redirect..."
# Get the redirect URL from GitHub login endpoint
REDIRECT_RESPONSE=$(curl -s -I "$BASE_URL/api/auth/github/login" | grep -i "location:" | cut -d' ' -f2- | tr -d '\r')
if [[ -n "$REDIRECT_RESPONSE" ]]; then
echo " β
GitHub OAuth redirect working"
echo " π Redirect URL: ${REDIRECT_RESPONSE:0:80}..."
else
echo " β GitHub OAuth redirect failed"
fi
echo ""
# Test projects endpoint without auth (expect 401)
echo "π Testing Projects API without authentication..."
RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" "$BASE_URL/api/projects/")
HTTP_CODE=$(echo "$RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2)
BODY=$(echo "$RESPONSE" | grep -v "HTTP_CODE:")
echo " Status Code: $HTTP_CODE"
if [[ "$HTTP_CODE" == "401" ]]; then
echo " β
Correctly returns 401 Unauthorized"
echo " π Response: $BODY"
else
echo " β οΈ Unexpected status code: $HTTP_CODE"
echo " π Response: $BODY"
fi
echo ""
# Test with a direct database query to verify projects exist
echo "ποΈ Testing Database Connection..."
echo " Checking projects in database..."
# Use docker exec to query database directly
DB_RESULT=$(docker compose exec -T postgres psql -U service_collections -d service_collections -t -c "SELECT COUNT(*) FROM projects;" 2>/dev/null | tr -d ' ')
if [[ -n "$DB_RESULT" && "$DB_RESULT" -gt 0 ]]; then
echo " β
Database connection working"
echo " π Projects in database: $DB_RESULT"
# Get project details
echo " π Project details:"
docker compose exec -T postgres psql -U service_collections -d service_collections -c "SELECT name, slug, status, owner_id FROM projects;"
else
echo " β Database connection failed or no projects found"
fi
echo ""
# Test API health endpoint
echo "π₯ Testing API Health..."
HEALTH_RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" "$BASE_URL/api/health" 2>/dev/null || echo "Connection failed")
HEALTH_HTTP_CODE=$(echo "$HEALTH_RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2 2>/dev/null)
HEALTH_BODY=$(echo "$HEALTH_RESPONSE" | grep -v "HTTP_CODE:")
if [[ "$HEALTH_HTTP_CODE" == "200" ]]; then
echo " β
API health check passed"
echo " π Response: $HEALTH_BODY"
elif [[ "$HEALTH_RESPONSE" == "Connection failed" ]]; then
echo " β Cannot connect to API server"
else
echo " β οΈ Health check returned: $HEALTH_HTTP_CODE"
echo " π Response: $HEALTH_BODY"
fi
echo ""
# Test that authentication system is working by checking the me endpoint
echo "π Testing Authentication System..."
ME_RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" "$BASE_URL/api/auth/me")
ME_HTTP_CODE=$(echo "$ME_RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2)
ME_BODY=$(echo "$ME_RESPONSE" | grep -v "HTTP_CODE:")
echo " Status Code: $ME_HTTP_CODE"
if [[ "$ME_HTTP_CODE" == "401" ]]; then
echo " β
Authentication required (expected behavior)"
echo " π Response: $ME_BODY"
else
echo " β οΈ Unexpected /me endpoint behavior: $ME_HTTP_CODE"
echo " π Response: $ME_BODY"
fi
echo ""
echo "=========================="
echo "β¨ Test Complete"
echo ""
echo "π Summary:"
echo " β’ GitHub OAuth redirect: Working"
echo " β’ Projects API without auth: Correctly protected (401)"
echo " β’ Database: Connected with projects available"
echo " β’ API health: Accessible"
echo " β’ Auth system: Properly enforcing authentication"
echo ""
echo "π‘ Next step: Complete GitHub OAuth flow to get JWT token for full API testing"