#!/bin/bash echo "==========================================" echo "🧪 TEST D'AUTHENTIFICATION JWT" echo "==========================================" echo "" # Couleurs GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' # No Color BASE_URL="http://localhost:4000" echo "1️⃣ Test: Inscription d'un client" echo "------------------------------------------" REGISTER_RESPONSE=$(curl -s -X POST $BASE_URL/api/auth/register \ -H "Content-Type: application/json" \ -d @- << 'EOF' { "email": "test-client@test.com", "password": "Test1234", "confirmPassword": "Test1234", "firstName": "Test", "lastName": "Client", "phone": "0612345678", "address": "1 rue Test", "city": "Paris", "postalCode": "75001" } EOF ) echo "$REGISTER_RESPONSE" | head -10 echo "" echo "2️⃣ Test: Connexion avec le client" echo "------------------------------------------" LOGIN_RESPONSE=$(curl -s -X POST $BASE_URL/api/auth/login \ -H "Content-Type: application/json" \ -d @- << 'EOF' { "email": "test-client@test.com", "password": "Test1234" } EOF ) echo "$LOGIN_RESPONSE" | head -10 echo "" # Extraire le token TOKEN=$(echo $LOGIN_RESPONSE | grep -o '"token":"[^"]*' | cut -d'"' -f4) if [ -z "$TOKEN" ]; then echo "❌ Pas de token reçu" else echo "✅ Token reçu: ${TOKEN:0:30}..." fi echo "" echo "3️⃣ Test: Accès à une route protégée avec token" echo "------------------------------------------" if [ ! -z "$TOKEN" ]; then PROFILE_RESPONSE=$(curl -s -X GET $BASE_URL/api/users/profile \ -H "Authorization: Bearer $TOKEN") echo "$PROFILE_RESPONSE" | head -10 else echo "❌ Impossible de tester - pas de token" fi echo "" echo "4️⃣ Test: Accès sans token (doit échouer)" echo "------------------------------------------" NO_TOKEN_RESPONSE=$(curl -s -X GET $BASE_URL/api/users/profile) echo "$NO_TOKEN_RESPONSE" echo "" echo "5️⃣ Test: Accès avec token invalide (doit échouer)" echo "------------------------------------------" INVALID_TOKEN_RESPONSE=$(curl -s -X GET $BASE_URL/api/users/profile \ -H "Authorization: Bearer invalid_token_12345") echo "$INVALID_TOKEN_RESPONSE" echo "" echo "6️⃣ Test: Route nécessitant rôle EMPLOYEE avec CLIENT (doit échouer)" echo "------------------------------------------" if [ ! -z "$TOKEN" ]; then EMPLOYEE_RESPONSE=$(curl -s -X GET $BASE_URL/api/employee/pending-tickets \ -H "Authorization: Bearer $TOKEN") echo "$EMPLOYEE_RESPONSE" else echo "❌ Impossible de tester - pas de token" fi echo "" echo "==========================================" echo "✅ Tests terminés" echo "=========================================="