Fix jwt-token

This commit is contained in:
2025-09-07 11:15:59 +02:00
parent 991e601a35
commit 5f8938d5bb
4 changed files with 99 additions and 9 deletions

View File

@@ -27,9 +27,10 @@ warnings.filterwarnings('ignore', message='Unverified HTTPS request')
API_BASE_URL = os.getenv('API_BASE_URL', 'http://localhost:3002/api')
BASE_PATH = os.getenv('VITE_BASE_PATH', '').rstrip('/')
# Authentication configuration
# Authentication configuration - Optional for local testing
USERNAME = os.getenv('TEST_USERNAME', 'admin')
PASSWORD = os.getenv('TEST_PASSWORD', 'admin123')
SKIP_AUTH = os.getenv('SKIP_AUTH', 'false').lower() == 'true' # Set to 'true' to skip authentication
# If BASE_PATH is set, construct the full URL
if BASE_PATH and not API_BASE_URL.endswith('/api'):
@@ -74,6 +75,9 @@ def authenticate():
def get_auth_headers():
"""Get headers with authentication token"""
if SKIP_AUTH:
return {"Content-Type": "application/json"}
if AUTH_TOKEN:
return {
"Authorization": f"Bearer {AUTH_TOKEN}",
@@ -120,7 +124,12 @@ def is_detectable(distance_km):
def fetch_devices():
"""Fetch devices from API"""
try:
response = requests.get(f"{API_BASE_URL}/devices", headers=get_auth_headers(), verify=False)
if SKIP_AUTH:
# Try without authentication first for local testing
response = requests.get(f"{API_BASE_URL}/devices/map", verify=False)
else:
response = requests.get(f"{API_BASE_URL}/devices", headers=get_auth_headers(), verify=False)
if response.status_code == 200:
data = response.json()
return data.get('data', [])
@@ -181,16 +190,19 @@ def run_orlan_detection_test():
print("• End position: Directly overhead (0m)")
print("=" * 70)
print(f"🔗 API Endpoint: {API_BASE_URL}")
if SKIP_AUTH:
print("⚠️ AUTHENTICATION DISABLED - Running in local test mode")
print()
# Authenticate first
if not authenticate():
# Authenticate first (unless skipped)
if not SKIP_AUTH and not authenticate():
print("❌ Authentication failed. Cannot proceed with test.")
print("Please check:")
print("1. Is the server running?")
print("2. Are the credentials correct?")
print(f" Username: {USERNAME}")
print("3. Set TEST_USERNAME and TEST_PASSWORD environment variables if needed")
print("4. Or set SKIP_AUTH=true to skip authentication for local testing")
return
# Test API connectivity first