#!/usr/bin/env python3 """ Script de test pour l'API Vault Teste les endpoints et le chiffrement quantique résistant """ import requests import ssl import json from pathlib import Path # Configuration API_BASE_URL = "https://vault.4nkweb.com:6666" VERIFY_SSL = False # Désactivé pour les certificats auto-signés def test_health_endpoint(): """Test du endpoint de santé""" print("🔍 Test du endpoint /health...") try: response = requests.get(f"{API_BASE_URL}/health", verify=VERIFY_SSL) if response.status_code == 200: data = response.json() print(f"✅ Santé: {data['status']}") print(f"🔐 Chiffrement: {data['encryption']}") print(f"🔧 Algorithme: {data['algorithm']}") return True else: print(f"❌ Erreur santé: {response.status_code}") return False except Exception as e: print(f"❌ Erreur connexion santé: {e}") return False def test_info_endpoint(): """Test du endpoint d'information""" print("\n🔍 Test du endpoint /info...") try: response = requests.get(f"{API_BASE_URL}/info", verify=VERIFY_SSL) if response.status_code == 200: data = response.json() print(f"✅ API: {data['name']} v{data['version']}") print(f"🌐 Domaine: {data['domain']}") print(f"🔌 Port: {data['port']}") print(f"📡 Protocole: {data['protocol']}") print("📋 Endpoints:") for endpoint, description in data['endpoints'].items(): print(f" {endpoint}: {description}") return True else: print(f"❌ Erreur info: {response.status_code}") return False except Exception as e: print(f"❌ Erreur connexion info: {e}") return False def test_file_endpoint(): """Test du endpoint de fichier""" print("\n🔍 Test du endpoint de fichier...") # Test avec un fichier existant test_files = [ "dev/bitcoin/bitcoin.conf", "dev/tor/torrc", "dev/sdk_relay/sdk_relay.conf" ] for file_path in test_files: print(f"\n📁 Test du fichier: {file_path}") try: response = requests.get(f"{API_BASE_URL}/{file_path}", verify=VERIFY_SSL) if response.status_code == 200: print(f"✅ Fichier servi avec succès") print(f"📦 Taille: {len(response.content)} bytes") print(f"🔐 Type chiffrement: {response.headers.get('X-Encryption-Type', 'N/A')}") print(f"🔧 Algorithme: {response.headers.get('X-Algorithm', 'N/A')}") # Affichage d'un échantillon du contenu chiffré (base64) sample = response.content[:100] print(f"📄 Échantillon chiffré: {sample.decode('utf-8', errors='ignore')}...") elif response.status_code == 404: print(f"⚠️ Fichier non trouvé: {file_path}") else: print(f"❌ Erreur fichier: {response.status_code}") if response.headers.get('content-type') == 'application/json': error_data = response.json() print(f" Détail: {error_data.get('error', 'N/A')}") except Exception as e: print(f"❌ Erreur connexion fichier: {e}") def test_variable_processing(): """Test du traitement des variables d'environnement""" print("\n🔍 Test du traitement des variables...") # Création d'un fichier de test avec des variables test_content = """ # Test de variables composites API_URL=${ROOT_URL}${URL_ROUTE_LECOFFRE_FRONT} BITCOIN_RPC=${BITCOIN_RPC_URL} DOMAIN=${DOMAIN} HOST=${HOST} COMPOSITE=${ROOT_DIR_LOGS}/bitcoin """ test_file_path = Path("/home/debian/4NK_vault/storage/dev/test_variables.conf") try: # Création du fichier de test with open(test_file_path, 'w') as f: f.write(test_content) print(f"📝 Fichier de test créé: {test_file_path}") # Test de l'API response = requests.get(f"{API_BASE_URL}/dev/test_variables.conf", verify=VERIFY_SSL) if response.status_code == 200: print("✅ Variables traitées avec succès") print(f"📦 Contenu chiffré reçu: {len(response.content)} bytes") else: print(f"❌ Erreur traitement variables: {response.status_code}") # Nettoyage test_file_path.unlink() print("🧹 Fichier de test supprimé") except Exception as e: print(f"❌ Erreur test variables: {e}") if test_file_path.exists(): test_file_path.unlink() def main(): """Fonction principale de test""" print("🚀 Test de l'API Vault 4NK") print("=" * 50) # Désactivation des avertissements SSL pour les certificats auto-signés import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # Tests health_ok = test_health_endpoint() info_ok = test_info_endpoint() test_file_endpoint() test_variable_processing() print("\n" + "=" * 50) print("📊 Résumé des tests:") print(f" Santé: {'✅' if health_ok else '❌'}") print(f" Info: {'✅' if info_ok else '❌'}") print(" Fichiers: Voir détails ci-dessus") print(" Variables: Voir détails ci-dessus") if health_ok and info_ok: print("\n🎉 L'API fonctionne correctement!") else: print("\n⚠️ L'API a des problèmes") if __name__ == "__main__": main()