leeds_backend/test/hmac_curl.sh
2026-01-29 18:28:39 -03:00

30 lines
744 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# ========= CONFIG PADRÃO =========
URL="${URL:-http://127.0.0.1:8080/v1/request}"
API_KEY="${API_KEY:-test_api_key}"
API_SECRET="${API_SECRET:-test_api_secret}"
API_USER="${API_USER:-test_user}"
# ========= ARGUMENTOS =========
METHOD="${1:-POST}"
BODY=$2
# ========= HMAC =========
TIMESTAMP=$(date +%s)
PAYLOAD="${API_KEY}:${TIMESTAMP}:${API_USER}"
SIGNATURE=$(printf "%s" "$PAYLOAD" \
| openssl dgst -sha256 -hmac "$API_SECRET" \
| sed 's/^.* //')
# ========= CURL =========
curl -i -X "$METHOD" "$URL" \
-H "Content-Type: application/json" \
-H "X-API-KEY: $API_KEY" \
-H "X-API-USER: $API_USER" \
-H "X-API-TIMESTAMP: $TIMESTAMP" \
-H "X-API-SIGNATURE: $SIGNATURE" \
-d "$BODY"