espace-paie-odentas/test-signature-flow.sh
odentas b790faf12c feat: Implémentation complète du système Odentas Sign
- Remplacement de DocuSeal par solution souveraine Odentas Sign
- Système d'authentification OTP pour signataires (bcryptjs + JWT)
- 8 routes API: send-otp, verify-otp, sign, pdf-url, positions, status, webhook, signers
- Interface moderne avec canvas de signature et animations (framer-motion, confetti)
- Système de templates pour auto-détection des positions de signature (CDDU, RG, avenants)
- PDF viewer avec @react-pdf-viewer (compatible Next.js)
- Stockage S3: source/, signatures/, evidence/, signed/, certs/
- Tables Supabase: sign_requests, signers, sign_positions, sign_events, sign_assets
- Evidence bundle automatique (JSON metadata + timestamps)
- Templates emails: OTP et completion
- Scripts Lambda prêts: pades-sign (KMS seal) et tsaStamp (RFC3161)
- Mode test détecté automatiquement (emails whitelist)
- Tests complets avec PDF CDDU réel (2 signataires)
2025-10-27 19:03:07 +01:00

164 lines
6.6 KiB
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Script pour tester rapidement les étapes de signature
# Usage: ./test-signature-flow.sh
# Charger les infos de la dernière demande créée
INFO_FILE="test-odentas-sign-info.json"
if [ ! -f "$INFO_FILE" ]; then
echo "❌ Fichier $INFO_FILE introuvable"
echo " Lancez d'abord: node test-odentas-sign.js"
exit 1
fi
# Extraire les IDs des signataires
EMPLOYEUR_ID=$(cat "$INFO_FILE" | grep -A 4 '"role": "Employeur"' | grep '"signerId"' | cut -d'"' -f4)
SALARIE_ID=$(cat "$INFO_FILE" | grep -A 4 '"role": "Salarié"' | grep '"signerId"' | cut -d'"' -f4)
REQUEST_ID=$(cat "$INFO_FILE" | grep '"id"' | head -1 | cut -d'"' -f4)
API_URL="${NEXT_PUBLIC_APP_URL:-http://localhost:3000}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🧪 Test du workflow de signature Odentas Sign"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "Request ID: $REQUEST_ID"
echo "Employeur ID: $EMPLOYEUR_ID"
echo "Salarié ID: $SALARIE_ID"
echo ""
# Menu
echo "Que voulez-vous tester ?"
echo "1) Envoyer OTP Employeur"
echo "2) Envoyer OTP Salarié"
echo "3) Vérifier OTP Employeur"
echo "4) Vérifier OTP Salarié"
echo "5) Signer (Employeur)"
echo "6) Signer (Salarié)"
echo "7) Voir statut de la demande"
echo "8) Tout tester automatiquement"
echo ""
read -p "Choix (1-8): " CHOICE
case $CHOICE in
1)
echo ""
echo "📤 Envoi OTP Employeur..."
curl -X POST "$API_URL/api/odentas-sign/signers/$EMPLOYEUR_ID/send-otp" | jq
echo ""
echo "📧 Vérifiez votre email paie@odentas.fr"
echo "⚠️ Le code OTP est aussi affiché dans les logs du serveur Next.js"
;;
2)
echo ""
echo "📤 Envoi OTP Salarié..."
curl -X POST "$API_URL/api/odentas-sign/signers/$SALARIE_ID/send-otp" | jq
echo ""
echo "📧 Vérifiez votre email renaud.breviere@gmail.com"
echo "⚠️ Le code OTP est aussi affiché dans les logs du serveur Next.js"
;;
3)
echo ""
read -p "Entrez le code OTP reçu: " OTP_CODE
echo ""
echo "🔐 Vérification OTP Employeur..."
RESPONSE=$(curl -s -X POST "$API_URL/api/odentas-sign/signers/$EMPLOYEUR_ID/verify-otp" \
-H "Content-Type: application/json" \
-d "{\"otp\": \"$OTP_CODE\"}")
echo "$RESPONSE" | jq
TOKEN=$(echo "$RESPONSE" | jq -r '.sessionToken // empty')
if [ -n "$TOKEN" ]; then
echo ""
echo "✅ Session token obtenu !"
echo "💾 Token sauvegardé dans .test-employeur-token"
echo "$TOKEN" > .test-employeur-token
fi
;;
4)
echo ""
read -p "Entrez le code OTP reçu: " OTP_CODE
echo ""
echo "🔐 Vérification OTP Salarié..."
RESPONSE=$(curl -s -X POST "$API_URL/api/odentas-sign/signers/$SALARIE_ID/verify-otp" \
-H "Content-Type: application/json" \
-d "{\"otp\": \"$OTP_CODE\"}")
echo "$RESPONSE" | jq
TOKEN=$(echo "$RESPONSE" | jq -r '.sessionToken // empty')
if [ -n "$TOKEN" ]; then
echo ""
echo "✅ Session token obtenu !"
echo "💾 Token sauvegardé dans .test-salarie-token"
echo "$TOKEN" > .test-salarie-token
fi
;;
5)
if [ ! -f ".test-employeur-token" ]; then
echo "❌ Token employeur introuvable. Vérifiez d'abord l'OTP (option 3)"
exit 1
fi
TOKEN=$(cat .test-employeur-token)
# Image de signature de test (carré rouge 100x50)
SIG_B64="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAyCAYAAACqNX6+AAAABmJLR0QA/wD/AP+gvaeTAAAAeklEQVR4nO3QMQEAAAjAMMC/52ECvlRA00ASAgECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQcNkFzQABOWLnlYwAAAAASUVORK5CYII="
echo ""
echo "✍️ Enregistrement signature Employeur..."
curl -X POST "$API_URL/api/odentas-sign/signers/$EMPLOYEUR_ID/sign" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "{\"signatureImageBase64\": \"$SIG_B64\", \"consentText\": \"Je consens à signer électroniquement ce document.\"}" | jq
;;
6)
if [ ! -f ".test-salarie-token" ]; then
echo "❌ Token salarié introuvable. Vérifiez d'abord l'OTP (option 4)"
exit 1
fi
TOKEN=$(cat .test-salarie-token)
# Image de signature de test (carré rouge 100x50)
SIG_B64="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAyCAYAAACqNX6+AAAABmJLR0QA/wD/AP+gvaeTAAAAeklEQVR4nO3QMQEAAAjAMMC/52ECvlRA00ASAgECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQcNkFzQABOWLnlYwAAAAASUVORK5CYII="
echo ""
echo "✍️ Enregistrement signature Salarié..."
curl -X POST "$API_URL/api/odentas-sign/signers/$SALARIE_ID/sign" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "{\"signatureImageBase64\": \"$SIG_B64\", \"consentText\": \"Je consens à signer électroniquement ce document.\"}" | jq
;;
7)
echo ""
echo "📊 Statut de la demande..."
curl "$API_URL/api/odentas-sign/requests/$REQUEST_ID" | jq
;;
8)
echo ""
echo "🤖 Test automatique complet..."
echo ""
# 1. OTP Employeur
echo "1⃣ Envoi OTP Employeur..."
curl -s -X POST "$API_URL/api/odentas-sign/signers/$EMPLOYEUR_ID/send-otp" > /dev/null
echo " Consultez les logs serveur pour le code OTP"
echo ""
# 2. OTP Salarié
echo "2⃣ Envoi OTP Salarié..."
curl -s -X POST "$API_URL/api/odentas-sign/signers/$SALARIE_ID/send-otp" > /dev/null
echo " Consultez les logs serveur pour le code OTP"
echo ""
echo "⚠️ Pour continuer le test automatique, vous devez :"
echo " 1. Relever les codes OTP dans les logs serveur"
echo " 2. Exécuter les options 3-6 manuellement"
;;
*)
echo "❌ Choix invalide"
exit 1
;;
esac
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"