#!/bin/bash # # LogWhispererAI - Workflow Test Script # Verifica che il workflow n8n risponda correttamente # set -euo pipefail N8N_URL="${N8N_URL:-http://192.168.254.12:5678}" WEBHOOK_PATH="/webhook/logwhisperer/ingest" CLIENT_SECRET="${CLIENT_SECRET:-test-secret-32-chars-long-minimum}" # Colori per output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color log_info() { echo -e "${GREEN}[INFO]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } log_warn() { echo -e "${YELLOW}[WARN]${NC} $1" } # Funzione per generare HMAC generate_hmac() { local payload="$1" local timestamp="$2" local secret="$3" printf '%s:%s' "$timestamp" "$payload" | \ openssl dgst -sha256 -hmac "$secret" | \ sed 's/^.* //' } # Test 1: HMAC Valido test_valid_hmac() { log_info "Test 1: Invio log con HMAC valido..." local timestamp timestamp=$(date +%s) local payload payload=$(cat < /dev/null; then log_error "curl non trovato. Installare curl." exit 1 fi if ! command -v openssl &> /dev/null; then log_error "openssl non trovato. Installare openssl." exit 1 fi local failed=0 # Esegui test test_valid_hmac || failed=$((failed + 1)) echo "" test_invalid_hmac || failed=$((failed + 1)) echo "" test_invalid_data || failed=$((failed + 1)) echo "" test_medium_severity || failed=$((failed + 1)) echo "" # Report finale echo "==========================================" if [[ $failed -eq 0 ]]; then log_info "Tutti i test PASSATI! ✓" exit 0 else log_error "$failed test FALLITI! ✗" exit 1 fi } main "$@"