diff --git a/docs/INDEX.md b/docs/INDEX.md index bb352f40..6b2ea466 100644 --- a/docs/INDEX.md +++ b/docs/INDEX.md @@ -18,7 +18,7 @@ Guide complet pour utiliser l'infrastructure 4NK Node au quotidien. - **Démarrage quotidien des services** - **Opérations de surveillance et monitoring** - **Utilisation du réseau de relais** -- **Connexion aux services (Bitcoin Core, Blindbit, sdk_relay)** +- **Connexion aux services (Bitcoin Core, Blindbit, sdk_relay, sdk_storage)** - **Tests et validation** - **Configuration et maintenance** - **Gestion des nœuds externes** @@ -54,6 +54,7 @@ Documentation complète des APIs disponibles. - **API Blindbit HTTP** : API REST pour les paiements silencieux - **API SDK Relay WebSocket** : Interface temps réel pour les clients - **API SDK Relay HTTP** : API REST pour les opérations de gestion +- **API SDK Storage HTTP** : API REST de stockage clé/valeur TTL via `/storage/*` - **Format des messages et payloads** - **Gestion des erreurs** - **Exemples d'utilisation** diff --git a/docs/TESTING.md b/docs/TESTING.md index 2c2eb12d..ba4e1c21 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -105,6 +105,7 @@ Options disponibles : **Tests inclus :** - `test_connectivity.sh` : Test de connectivité des services - `test_websocket_messages.py` : Test des messages WebSocket +- `test_storage_proxy.sh` : Test de l’API sdk_storage via le reverse proxy (`/storage/*`) - Tests externes reverse proxy : ```bash curl -kI https:/// diff --git a/tests/connectivity/test_storage_proxy.sh b/tests/connectivity/test_storage_proxy.sh new file mode 100755 index 00000000..c23ff54d --- /dev/null +++ b/tests/connectivity/test_storage_proxy.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# Test de connectivité du reverse proxy vers sdk_storage (/storage) +# Sorties: +# - 0 si tests OK +# - 1 sinon + +set -euo pipefail + +HOST="${HOST:-localhost}" +BASE_URL="https://${HOST}/storage" +LOG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)/logs" +TS="$(date +%Y-%m-%d_%H-%M-%S)" +LOG_FILE="$LOG_DIR/storage_proxy_${TS}.log" +mkdir -p "$LOG_DIR" + +log() { + printf "%s %s\n" "[$(date +%H:%M:%S)]" "$*" | tee -a "$LOG_FILE" +} + +fail() { + log "ERREUR: $*" + exit 1 +} + +key_hex="$(head -c 32 /dev/urandom | od -An -tx1 | tr -d " \n")$(head -c 32 /dev/urandom | od -An -tx1 | tr -d " \n")" +key_hex="${key_hex:0:64}" +val_hex="68656c6c6f5f34726e6b" # "hello_4rnk" en hex + +log "HEAD ${BASE_URL}/" +code_head=$(curl -skI "${BASE_URL}/" | awk 'NR==1{print $2}' || true) +log "HTTP ${code_head:-inconnu}" + +log "POST ${BASE_URL}/store" +resp_post=$(curl -sk -H 'Content-Type: application/json' -X POST "${BASE_URL}/store" \ + -d "{\"key\":\"${key_hex}\",\"value\":\"${val_hex}\",\"ttl\":120}" || true) +printf "%s\n" "$resp_post" | tee -a "$LOG_FILE" + +echo "$resp_post" | grep -q 'Data stored successfully' || fail "stockage échoué" + +log "GET ${BASE_URL}/retrieve/${key_hex}" +resp_get=$(curl -sk "${BASE_URL}/retrieve/${key_hex}" || true) +printf "%s\n" "$resp_get" | tee -a "$LOG_FILE" + +echo "$resp_get" | grep -q "\"key\":\"${key_hex}\"" || fail "clé non retrouvée" +echo "$resp_get" | grep -q "\"value\":\"${val_hex}\"" || fail "valeur inattendue" + +log "Succès: /storage opérationnel via reverse proxy" +exit 0 + + diff --git a/tests/run_connectivity_tests.sh b/tests/run_connectivity_tests.sh index dc427f9b..42a569af 100755 --- a/tests/run_connectivity_tests.sh +++ b/tests/run_connectivity_tests.sh @@ -177,6 +177,35 @@ run_connectivity_tests() { log "WARNING" "Test test_websocket_messages.py non trouvé" fi + # Test storage via reverse proxy + if [ -f "test_storage_proxy.sh" ]; then + total_tests=$((total_tests + 1)) + log "INFO" "Exécution de test_storage_proxy.sh" + if [ "$VERBOSE" = true ]; then + if HOST=localhost ./test_storage_proxy.sh 2>&1 | tee -a "$LOG_FILE"; then + connectivity_results+=("test_storage_proxy.sh:SUCCESS") + successful_tests=$((successful_tests + 1)) + log "SUCCESS" "test_storage_proxy.sh terminé avec succès" + else + connectivity_results+=("test_storage_proxy.sh:FAILED") + failed_tests=$((failed_tests + 1)) + log "ERROR" "test_storage_proxy.sh a échoué" + fi + else + if HOST=localhost ./test_storage_proxy.sh >> "$LOG_FILE" 2>&1; then + connectivity_results+=("test_storage_proxy.sh:SUCCESS") + successful_tests=$((successful_tests + 1)) + log "SUCCESS" "test_storage_proxy.sh terminé avec succès" + else + connectivity_results+=("test_storage_proxy.sh:FAILED") + failed_tests=$((failed_tests + 1)) + log "ERROR" "test_storage_proxy.sh a échoué" + fi + fi + else + log "WARNING" "Test test_storage_proxy.sh non trouvé" + fi + # Afficher le résumé des tests de connectivité log "INFO" "=== Résumé des tests de connectivité ===" log "INFO" "Total: $total_tests, Succès: $successful_tests, Échecs: $failed_tests"