Refactoring
This commit is contained in:
140
test_auth.py
Normal file
140
test_auth.py
Normal file
@@ -0,0 +1,140 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script de test d'authentification pour tous les comptes UnionFlow
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
class AuthTester:
|
||||
def __init__(self, base_url: str = "http://localhost:8180"):
|
||||
self.base_url = base_url
|
||||
self.session = requests.Session()
|
||||
|
||||
def test_account(self, username: str, password: str, realm: str = "unionflow",
|
||||
client_id: str = "unionflow-mobile") -> Tuple[bool, str]:
|
||||
"""Teste l'authentification d'un compte"""
|
||||
try:
|
||||
data = {
|
||||
"username": username,
|
||||
"password": password,
|
||||
"grant_type": "password",
|
||||
"client_id": client_id
|
||||
}
|
||||
|
||||
response = self.session.post(
|
||||
f"{self.base_url}/realms/{realm}/protocol/openid-connect/token",
|
||||
data=data,
|
||||
headers={"Content-Type": "application/x-www-form-urlencoded"},
|
||||
timeout=10
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
token_data = response.json()
|
||||
if "access_token" in token_data:
|
||||
return True, "Authentification réussie"
|
||||
else:
|
||||
return False, "Token manquant dans la réponse"
|
||||
else:
|
||||
error_data = response.json() if response.content else {}
|
||||
error_msg = error_data.get("error_description", f"HTTP {response.status_code}")
|
||||
return False, error_msg
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
return False, f"Erreur de connexion: {e}"
|
||||
except json.JSONDecodeError:
|
||||
return False, "Réponse JSON invalide"
|
||||
except Exception as e:
|
||||
return False, f"Erreur inattendue: {e}"
|
||||
|
||||
def test_all_accounts(self) -> None:
|
||||
"""Teste tous les comptes UnionFlow"""
|
||||
accounts = [
|
||||
("superadmin", "SuperAdmin123!", "SUPER_ADMINISTRATEUR"),
|
||||
("marie.active", "Marie123!", "MEMBRE_ACTIF"),
|
||||
("jean.simple", "Jean123!", "MEMBRE_SIMPLE"),
|
||||
("tech.lead", "TechLead123!", "RESPONSABLE_TECHNIQUE"),
|
||||
("rh.manager", "RhManager123!", "RESPONSABLE_MEMBRES")
|
||||
]
|
||||
|
||||
print("=" * 80)
|
||||
print("🔍 TEST D'AUTHENTIFICATION UNIONFLOW")
|
||||
print("=" * 80)
|
||||
print()
|
||||
|
||||
# Vérifier que Keycloak est accessible
|
||||
try:
|
||||
response = self.session.get(f"{self.base_url}", timeout=5)
|
||||
if response.status_code != 200:
|
||||
print("❌ Keycloak n'est pas accessible")
|
||||
return
|
||||
except:
|
||||
print("❌ Keycloak n'est pas accessible")
|
||||
return
|
||||
|
||||
print("✅ Keycloak accessible")
|
||||
print()
|
||||
|
||||
success_count = 0
|
||||
total_count = len(accounts)
|
||||
|
||||
for username, password, role in accounts:
|
||||
print(f"🧪 Test {username}...", end=" ")
|
||||
|
||||
success, message = self.test_account(username, password)
|
||||
|
||||
if success:
|
||||
print(f"✅ SUCCÈS")
|
||||
print(f" └─ Rôle: {role}")
|
||||
success_count += 1
|
||||
else:
|
||||
print(f"❌ ÉCHEC")
|
||||
print(f" └─ Erreur: {message}")
|
||||
print()
|
||||
|
||||
print("=" * 80)
|
||||
print("📊 RÉSULTAT FINAL")
|
||||
print("=" * 80)
|
||||
print()
|
||||
|
||||
if success_count == total_count:
|
||||
print("🎉 PARFAIT ! Tous les comptes fonctionnent !")
|
||||
print(f" ✅ {success_count}/{total_count} comptes opérationnels")
|
||||
print()
|
||||
print("🚀 PRÊT POUR L'APPLICATION MOBILE :")
|
||||
print()
|
||||
print(" 📱 TESTEZ MAINTENANT SUR VOTRE SAMSUNG :")
|
||||
print(" 1. Ouvrez l'app UnionFlow")
|
||||
print(" 2. Cliquez sur 'Se connecter avec Keycloak'")
|
||||
print(" 3. Utilisez: marie.active / Marie123!")
|
||||
print(" 4. Vérifiez que l'authentification fonctionne")
|
||||
print()
|
||||
print(" 🔐 AUTRES COMPTES DISPONIBLES :")
|
||||
for username, password, role in accounts:
|
||||
print(f" • {username} / {password} ({role})")
|
||||
print()
|
||||
print("✅ ARCHITECTURE RÔLES UNIONFLOW 100% OPÉRATIONNELLE !")
|
||||
|
||||
elif success_count > 0:
|
||||
print(f"⚠️ Configuration partielle ({success_count}/{total_count} comptes fonctionnent)")
|
||||
print(" Vous pouvez tester avec les comptes qui marchent")
|
||||
print(" Relancez: python setup_keycloak.py pour corriger")
|
||||
|
||||
else:
|
||||
print("❌ Aucun compte ne fonctionne")
|
||||
print(" Vérifiez que Keycloak est configuré correctement")
|
||||
print(" Relancez: python setup_keycloak.py")
|
||||
|
||||
print()
|
||||
print("=" * 80)
|
||||
|
||||
|
||||
def main():
|
||||
"""Fonction principale"""
|
||||
tester = AuthTester()
|
||||
tester.test_all_accounts()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user