test(smoke): probe a protected endpoint for the api-key check

llama.cpp exempts /health and /v1/models from --api-key; only
/v1/chat/completions is protected. The smoke test probed /v1/models and thus
saw 200 without a key. Probe /v1/chat/completions instead (no key -> 401,
key -> 200). Verified live end-to-end: 9 PASS, 0 FAIL.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-07-06 17:25:41 +02:00
commit aa1a9fc232

View file

@ -71,12 +71,17 @@ echo "== --check Exit-Code (läuft -> 0) =="
rc=0; "$CLI" --check "${base[@]}" >/dev/null 2>&1 || rc=$?
[ "$rc" -eq 0 ] && ok "--check == 0" || bad "--check == $rc (erwartet 0)"
# Probe a PROTECTED endpoint: llama.cpp exempts /health and /v1/models from the
# API key, but /v1/chat/completions requires it.
chat_probe='{"messages":[{"role":"user","content":"hi"}],"max_tokens":1}'
echo "== API-Key erzwungen: ohne Key -> 401 =="
code=$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PORT/v1/models")
code=$(curl -s -o /dev/null -w '%{http_code}' -X POST "http://127.0.0.1:$PORT/v1/chat/completions" \
-H 'Content-Type: application/json' -d "$chat_probe")
[ "$code" = "401" ] && ok "unauth -> 401" || bad "unauth -> $code (erwartet 401)"
echo "== API-Key: mit Key -> 200 =="
code=$(curl -s -o /dev/null -w '%{http_code}' -H "Authorization: Bearer $API_KEY" "http://127.0.0.1:$PORT/v1/models")
code=$(curl -s -o /dev/null -w '%{http_code}' -X POST "http://127.0.0.1:$PORT/v1/chat/completions" \
-H 'Content-Type: application/json' -H "Authorization: Bearer $API_KEY" -d "$chat_probe")
[ "$code" = "200" ] && ok "auth -> 200" || bad "auth -> $code (erwartet 200)"
echo "== chat (Tool sendet Bearer-Key) =="