Files
2026-10-23 10:35:28 +08:00

52 lines
2.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 冒烟测试:验证 LibreDesk / tools 服务 / 工具鉴权与验证门控。
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
# shellcheck disable=SC1091
set -a; . ./.env; set +a
TOOLS_PORT="${TOOLS_PORT:-4010}"
tools_base="http://127.0.0.1:${TOOLS_PORT}"
say() { printf '\n== %s ==\n' "$1"; }
status() { curl -s -o /tmp/crm_libredesk_smoke.out -w '%{http_code}' "$@"; }
say "LibreDesk /health"
code=$(status "http://localhost:9000/health" || true)
echo "HTTP ${code} $(head -c 200 /tmp/crm_libredesk_smoke.out 2>/dev/null || true)"
say "tools /healthz"
code=$(status "${tools_base}/healthz" || true)
echo "HTTP ${code} $(head -c 300 /tmp/crm_libredesk_smoke.out 2>/dev/null || true)"
say "tools manifest(鉴权)"
code=$(status -H "X-Tools-Key: ${TOOLS_SHARED_KEY}" "${tools_base}/tools/manifest" || true)
echo "HTTP ${code}"
python3 -c "import json;d=json.load(open('/tmp/crm_libredesk_smoke.out'));print('tools:',[t['name'] for t in d['tools']]);print('base:',d['base_url'])" 2>/dev/null || true
say "search_products(未验证,应 200)"
code=$(status -X POST "${tools_base}/tools/search_products" \
-H "X-Tools-Key: ${TOOLS_SHARED_KEY}" -H 'Content-Type: application/json' \
-d '{"query":"gold hoop earrings"}' || true)
echo "HTTP ${code} $(head -c 400 /tmp/crm_libredesk_smoke.out 2>/dev/null || true)"
say "search_orders(未验证,应 403 verification_required)"
code=$(status -X POST "${tools_base}/tools/search_orders" \
-H "X-Tools-Key: ${TOOLS_SHARED_KEY}" -H 'Content-Type: application/json' \
-d '{"orderNumber":"SO-1"}' || true)
echo "HTTP ${code} $(head -c 300 /tmp/crm_libredesk_smoke.out 2>/dev/null || true)"
say "search_orders(伪造已验证头,仅探测鉴权链路;生产不应依赖客户端头)"
code=$(status -X POST "${tools_base}/tools/search_orders" \
-H "X-Tools-Key: ${TOOLS_SHARED_KEY}" -H 'Content-Type: application/json' \
-H 'X-Libredesk-Contact-Verified: true' -H "X-Libredesk-Contact-Email: ${SMOKE_TEST_EMAIL:-demo@example.com}" \
-d '{"orderNumber":"SO-1"}' || true)
echo "HTTP ${code} $(head -c 300 /tmp/crm_libredesk_smoke.out 2>/dev/null || true)"
rm -f /tmp/crm_libredesk_smoke.out
echo
echo "冒烟测试完成。"