#!/usr/bin/env python3 """ Simple test script to verify agent upload authentication. """ import os import requests import tempfile import zipfile # Get the production token ADMIN_TOKEN = "73cf0db73f9a5064e79afebba96c85338be65cc2060b9c1d42c3ea5dd7d4e490" API_URL = "http://localhost:8000/api/traces/upload" def test_upload(): """Test uploading a dummy session file.""" # Create a dummy ZIP file with tempfile.NamedTemporaryFile(suffix='.zip', delete=False) as tmp_file: with zipfile.ZipFile(tmp_file.name, 'w') as zf: zf.writestr('test_session.json', '{"test": "data"}') zip_path = tmp_file.name try: # Test upload with authentication with open(zip_path, 'rb') as f: files = { 'file': ('test_session.zip', f, 'application/zip') } data = { 'session_id': 'test_session_123' } headers = { 'Authorization': f'Bearer {ADMIN_TOKEN}' } print(f"Testing upload to {API_URL}") print(f"Using token: {ADMIN_TOKEN[:8]}...") response = requests.post(API_URL, files=files, data=data, headers=headers) print(f"Response status: {response.status_code}") print(f"Response body: {response.text}") if response.status_code == 200: print("✅ Upload successful!") return True elif response.status_code == 400: print("⚠️ Upload processed but failed validation (expected for dummy data)") return True else: print("❌ Upload failed!") return False finally: # Clean up os.unlink(zip_path) if __name__ == "__main__": test_upload()