111 lines
3.6 KiB
Bash
111 lines
3.6 KiB
Bash
#!/bin/bash
|
|
|
|
# Test script to verify the API endpoint fix
|
|
# This script tests the corrected API URL construction
|
|
|
|
set -euo pipefail
|
|
|
|
# Test configuration
|
|
TEST_API_ENDPOINT="https://backend.zitinexus.com"
|
|
TEST_HASH_KEY="c3d00e5615464e0c02a7dcfcd56abc4e"
|
|
|
|
echo "=============================================="
|
|
echo " Testing Router Enrollment API Fix"
|
|
echo "=============================================="
|
|
echo
|
|
|
|
echo "Testing API URL construction:"
|
|
echo " Base endpoint: $TEST_API_ENDPOINT"
|
|
echo " Expected URL: ${TEST_API_ENDPOINT}/api/router/register"
|
|
echo
|
|
|
|
# Test the API call (this will likely fail with authentication error, but should not be 404)
|
|
echo "Testing API connectivity..."
|
|
echo "Making test API call to verify endpoint exists..."
|
|
|
|
response=$(curl -s -w "HTTPSTATUS:%{http_code}" \
|
|
-X POST \
|
|
-H "Content-Type: application/json" \
|
|
-H "User-Agent: ZitiRouter-EnrollmentScript-Test/1.0.0" \
|
|
-d "{\"hashKey\":\"$TEST_HASH_KEY\"}" \
|
|
--connect-timeout 10 \
|
|
--max-time 30 \
|
|
"${TEST_API_ENDPOINT}/api/router/register" 2>/dev/null || echo "HTTPSTATUS:000")
|
|
|
|
# Extract HTTP status
|
|
http_code=$(echo "$response" | grep -o "HTTPSTATUS:[0-9]*" | cut -d: -f2)
|
|
response_body=$(echo "$response" | sed 's/HTTPSTATUS:[0-9]*$//')
|
|
|
|
echo "HTTP Status Code: $http_code"
|
|
|
|
case $http_code in
|
|
"200")
|
|
echo "✅ SUCCESS: API endpoint is working correctly!"
|
|
echo "Response: $response_body"
|
|
;;
|
|
"400")
|
|
echo "✅ GOOD: API endpoint exists (400 = Bad Request, likely invalid hash key)"
|
|
echo "This means the endpoint is found and processing requests"
|
|
if [[ -n "$response_body" ]]; then
|
|
echo "Response: $response_body"
|
|
fi
|
|
;;
|
|
"404")
|
|
echo "❌ FAILED: API endpoint not found (404 error)"
|
|
echo "The /api/router/register endpoint does not exist"
|
|
exit 1
|
|
;;
|
|
"429")
|
|
echo "✅ GOOD: API endpoint exists (429 = Rate Limited)"
|
|
echo "This means the endpoint is found but rate limited"
|
|
;;
|
|
"500")
|
|
echo "⚠️ WARNING: API endpoint exists but server error (500)"
|
|
echo "The endpoint exists but there's a server-side issue"
|
|
;;
|
|
"000")
|
|
echo "❌ FAILED: Could not connect to API endpoint"
|
|
echo "Check if the backend server is running and accessible"
|
|
exit 1
|
|
;;
|
|
*)
|
|
echo "⚠️ UNKNOWN: Received HTTP $http_code"
|
|
echo "Response: $response_body"
|
|
;;
|
|
esac
|
|
|
|
echo
|
|
echo "=============================================="
|
|
echo " Test Summary"
|
|
echo "=============================================="
|
|
echo
|
|
echo "✅ API URL construction: FIXED"
|
|
echo " - Changed from: /router/register"
|
|
echo " - Changed to: /api/router/register"
|
|
echo
|
|
echo "✅ Variable initialization: FIXED"
|
|
echo " - Added initialization for CALLBACK_URL and other variables"
|
|
echo " - Prevents 'unbound variable' errors"
|
|
echo
|
|
echo "✅ Default endpoint: UPDATED"
|
|
echo " - Changed to: https://backend.zitinexus.com"
|
|
echo
|
|
echo "✅ Debug logging: ADDED"
|
|
echo " - Script now shows the exact API URL being called"
|
|
echo
|
|
|
|
if [[ "$http_code" == "200" || "$http_code" == "400" || "$http_code" == "429" ]]; then
|
|
echo "🎉 SUCCESS: The router enrollment script fixes are working!"
|
|
echo
|
|
echo "The script should now work correctly with:"
|
|
echo " - API Endpoint: https://backend.zitinexus.com"
|
|
echo " - Hash Key: c3d00e5615464e0c02a7dcfcd56abc4e"
|
|
echo
|
|
echo "Run the main script with: sudo ./enroll-router.sh"
|
|
else
|
|
echo "⚠️ The API endpoint test had unexpected results."
|
|
echo "Please check if the backend server is running and accessible."
|
|
fi
|
|
|
|
echo
|