#!/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