Fix jwt-token

This commit is contained in:
2025-09-07 09:07:40 +02:00
parent af072b74fd
commit 3d4ea88269
6 changed files with 178 additions and 11 deletions

20
.env.test.example Normal file
View File

@@ -0,0 +1,20 @@
# Environment configuration for test scripts
# Copy this to .env in the project root or set these as environment variables
# API Base URL - Update this to your deployment
API_BASE_URL=http://localhost:3002/api
# For production deployment, use your domain:
# API_BASE_URL=https://your-domain.com/uggla/api
# Base path (should match VITE_BASE_PATH)
VITE_BASE_PATH=/uggla
# Alternative configurations:
# For local development:
# API_BASE_URL=http://localhost:3002/api
# VITE_BASE_PATH=
# For production with different base path:
# API_BASE_URL=https://your-domain.com
# VITE_BASE_PATH=/your-custom-path

103
run-tests.sh Normal file
View File

@@ -0,0 +1,103 @@
#!/bin/bash
# Test runner script for Uggla Drone Detection System
# Automatically sets up environment and runs test scripts
set -e
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}======================================${NC}"
echo -e "${BLUE} Uggla Test Runner${NC}"
echo -e "${BLUE}======================================${NC}"
echo
# Check if .env exists, if not suggest creating it
if [ ! -f ".env" ]; then
echo -e "${YELLOW}Warning: .env file not found.${NC}"
echo "You can:"
echo "1. Copy .env.test.example to .env and customize it"
echo "2. Set environment variables manually"
echo "3. Use default localhost settings"
echo
read -p "Continue with default localhost settings? (y/N): " CONTINUE
if [[ ! $CONTINUE =~ ^[Yy]$ ]]; then
echo "Please create .env file and try again."
exit 1
fi
# Set default environment variables
export API_BASE_URL="http://localhost:3002/api"
export VITE_BASE_PATH=""
echo -e "${GREEN}Using default localhost configuration${NC}"
else
echo -e "${GREEN}Loading environment from .env file${NC}"
# Load environment variables from .env file
export $(grep -v '^#' .env | xargs)
fi
echo -e "${BLUE}Current configuration:${NC}"
echo "API_BASE_URL: ${API_BASE_URL:-http://localhost:3002/api}"
echo "VITE_BASE_PATH: ${VITE_BASE_PATH:-<empty>}"
echo
# Check which test to run
if [ $# -eq 0 ]; then
echo "Available tests:"
echo "1. test_drone_data.py - Comprehensive drone simulation"
echo "2. test_orlan_scenario.py - Military drone approach scenario"
echo "3. test_orlan_detection.py - Long-range Orlan detection test"
echo "4. test_drone_curl.sh - Simple curl-based API test"
echo
read -p "Select test (1-4): " TEST_CHOICE
case $TEST_CHOICE in
1) TEST_SCRIPT="test_drone_data.py" ;;
2) TEST_SCRIPT="test_orlan_scenario.py" ;;
3) TEST_SCRIPT="test_orlan_detection.py" ;;
4) TEST_SCRIPT="test_drone_curl.sh" ;;
*) echo "Invalid choice"; exit 1 ;;
esac
else
TEST_SCRIPT=$1
fi
echo -e "${YELLOW}Running test: $TEST_SCRIPT${NC}"
echo
# Check if script exists
if [ ! -f "$TEST_SCRIPT" ]; then
echo "Error: Test script $TEST_SCRIPT not found"
exit 1
fi
# Run the test script
if [[ $TEST_SCRIPT == *.py ]]; then
# Check if Python and required packages are available
if ! command -v python3 &> /dev/null; then
echo "Error: Python 3 is required to run Python test scripts"
exit 1
fi
# Check if requests module is available
python3 -c "import requests" 2>/dev/null || {
echo "Error: 'requests' module is required. Install with: pip install requests"
exit 1
}
python3 "$TEST_SCRIPT"
elif [[ $TEST_SCRIPT == *.sh ]]; then
# Make sure the script is executable
chmod +x "$TEST_SCRIPT"
./"$TEST_SCRIPT"
else
echo "Error: Unknown script type for $TEST_SCRIPT"
exit 1
fi
echo
echo -e "${GREEN}Test completed!${NC}"

View File

@@ -1,15 +1,30 @@
#!/bin/bash
# Simple bash script to test drone detection API with curl
API_BASE="http://selfservice.cqers.com/drones/api"
# Alternative for local testing: "http://localhost:3002/api"
# Load environment variables from .env file if it exists
if [ -f ".env" ]; then
export $(grep -v '^#' .env | xargs)
fi
# Configuration from environment variables
API_BASE_URL=${API_BASE_URL:-"http://localhost:3002/api"}
BASE_PATH=${VITE_BASE_PATH:-""}
# If BASE_PATH is set, construct the full URL
if [ ! -z "$BASE_PATH" ] && [[ ! "$API_BASE_URL" == *"/api" ]]; then
# Remove any existing path suffixes and add base path
DOMAIN=$(echo "$API_BASE_URL" | sed 's|/api$||' | sed 's|/drones/api$||' | sed 's|/uggla/api$||')
API_BASE_URL="${DOMAIN}${BASE_PATH}/api"
fi
echo "🚁 Drone Detection API Test Script"
echo "=================================="
echo "🔗 Using API Base URL: $API_BASE_URL"
echo ""
# Test API health
echo "🔍 Testing API health..."
curl -s "$API_BASE/health" | jq '.' || echo "Health check failed"
curl -s "$API_BASE_URL/health" | jq '.' || echo "Health check failed"
echo ""
# Send test detection data
@@ -39,7 +54,7 @@ echo ""
# Send the detection
echo "Sending detection..."
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
-X POST "$API_BASE/detections" \
-X POST "$API_BASE_URL/detectors" \
-H "Content-Type: application/json" \
-d "$DETECTION_DATA")

View File

@@ -11,11 +11,20 @@ import time
import random
import math
import argparse
import os
from datetime import datetime, timedelta
# Configuration
API_BASE_URL = "https://selfservice.cqers.com/drones/api"
# Alternative for local testing: "http://localhost:3002/api"
# Configuration from environment variables
API_BASE_URL = os.getenv('API_BASE_URL', 'http://localhost:3002/api')
BASE_PATH = os.getenv('VITE_BASE_PATH', '').rstrip('/')
# If BASE_PATH is set, construct the full URL
if BASE_PATH and not API_BASE_URL.endswith('/api'):
# Extract domain from API_BASE_URL and add base path
domain = API_BASE_URL.replace('/api', '').replace('/drones/api', '').replace('/uggla/api', '')
API_BASE_URL = f"{domain}{BASE_PATH}/api"
print(f"🔗 Using API Base URL: {API_BASE_URL}")
# Debug configuration
DEBUG_MODE = False # Set to True to enable payload debugging

View File

@@ -15,10 +15,20 @@ import requests
import json
import time
import math
import os
from datetime import datetime
# Configuration
API_BASE_URL = "http://selfservice.cqers.com/drones/api"
# Configuration from environment variables
API_BASE_URL = os.getenv('API_BASE_URL', 'http://localhost:3002/api')
BASE_PATH = os.getenv('VITE_BASE_PATH', '').rstrip('/')
# If BASE_PATH is set, construct the full URL
if BASE_PATH and not API_BASE_URL.endswith('/api'):
# Extract domain from API_BASE_URL and add base path
domain = API_BASE_URL.replace('/api', '').replace('/drones/api', '').replace('/uggla/api', '')
API_BASE_URL = f"{domain}{BASE_PATH}/api"
print(f"🔗 Using API Base URL: {API_BASE_URL}")
# Detection range parameters (approximate)
MAX_DETECTION_RANGE_KM = 25.0 # Maximum range for drone detection

View File

@@ -9,10 +9,20 @@ import requests
import json
import time
import math
import os
from datetime import datetime
# Configuration
API_BASE_URL = "http://selfservice.cqers.com/drones/api"
# Configuration from environment variables
API_BASE_URL = os.getenv('API_BASE_URL', 'http://localhost:3002/api')
BASE_PATH = os.getenv('VITE_BASE_PATH', '').rstrip('/')
# If BASE_PATH is set, construct the full URL
if BASE_PATH and not API_BASE_URL.endswith('/api'):
# Extract domain from API_BASE_URL and add base path
domain = API_BASE_URL.replace('/api', '').replace('/drones/api', '').replace('/uggla/api', '')
API_BASE_URL = f"{domain}{BASE_PATH}/api"
print(f"🔗 Using API Base URL: {API_BASE_URL}")
def haversine_distance(lat1, lon1, lat2, lon2):
"""Calculate distance between two points in kilometers"""