82 lines
3.7 KiB
Bash
Executable File
82 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
LOCAL_BASE="${LANDWELLE_LOCAL_API_BASE:-http://127.0.0.1:2200}"
|
|
PUBLIC_BASE="${LANDWELLE_PUBLIC_API_BASE:-https://api.landwelle.de}"
|
|
MUTATING="${LANDWELLE_VERIFY_MUTATING:-0}"
|
|
TMP_DIR="$(mktemp -d)"
|
|
trap 'rm -rf "$TMP_DIR"' EXIT
|
|
|
|
json_status() {
|
|
local method="$1" url="$2" body="${3:-}" headers="$TMP_DIR/h" output="$TMP_DIR/b" status
|
|
if [[ -n "$body" ]]; then
|
|
status="$(curl -sS --connect-timeout 5 --max-time 30 -X "$method" -H 'Content-Type: application/json' -D "$headers" -o "$output" -w '%{http_code}' --data "$body" "$url" || true)"
|
|
else
|
|
status="$(curl -sS --connect-timeout 5 --max-time 30 -X "$method" -D "$headers" -o "$output" -w '%{http_code}' "$url" || true)"
|
|
fi
|
|
printf '%s' "$status"
|
|
}
|
|
|
|
assert_json_status() {
|
|
local label="$1" expected="$2" method="$3" url="$4" body="${5:-}" status
|
|
status="$(json_status "$method" "$url" "$body")"
|
|
printf '%-34s HTTP %s\n' "$label" "$status"
|
|
if [[ "$status" != "$expected" ]]; then
|
|
echo " FEHLER: erwartet HTTP $expected"
|
|
cat "$TMP_DIR/b" 2>/dev/null || true
|
|
echo
|
|
return 1
|
|
fi
|
|
if ! grep -qi 'content-type:.*application/json' "$TMP_DIR/h"; then
|
|
echo " FEHLER: Antwort ist nicht application/json"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
assert_json_status "lokal /v1/wishes GET" 405 GET "$LOCAL_BASE/v1/wishes"
|
|
assert_json_status "öffentlich /v1/wishes GET" 405 GET "$PUBLIC_BASE/v1/wishes"
|
|
|
|
if [[ "$MUTATING" != "1" ]]; then
|
|
cat <<'MSG'
|
|
|
|
Nur nicht-mutierende Routentests wurden ausgeführt.
|
|
Für die im Auftrag verlangten POST-Tests einmal bewusst ausführen:
|
|
LANDWELLE_VERIFY_MUTATING=1 ./scripts/verify-app-api-production.sh
|
|
Dabei werden zwei Test-Musikwünsche angelegt und anschließend eine temporäre App-Installation registriert und wieder gelöscht.
|
|
MSG
|
|
exit 0
|
|
fi
|
|
|
|
wish='{"name":"App Test","place":"Visselhövede","artist":"Testinterpret","song":"Testtitel","message":"API-Verifikation aus dem Landwelle-Portal","publish_consent":true}'
|
|
assert_json_status "lokaler Wunschbox-POST" 201 POST "$LOCAL_BASE/v1/wishes" "$wish"
|
|
assert_json_status "öffentlicher Wunschbox-POST" 201 POST "$PUBLIC_BASE/v1/wishes" "$wish"
|
|
|
|
installation='{"platform":"android","device_class":"unknown","distribution_channel":"development","app_version":"1.3.2","app_build":"8","os_version":"Android Test","locale":"de-DE","timezone":"Europe/Berlin"}'
|
|
status="$(json_status POST "$PUBLIC_BASE/v1/installations" "$installation")"
|
|
printf '%-34s HTTP %s\n' "Installation registrieren" "$status"
|
|
[[ "$status" == "201" ]] || { cat "$TMP_DIR/b"; exit 1; }
|
|
python3 - "$TMP_DIR/b" "$TMP_DIR/installation.env" <<'PY'
|
|
import json,sys
|
|
p=json.load(open(sys.argv[1]))['data']
|
|
with open(sys.argv[2],'w') as f:
|
|
f.write('INSTALLATION_ID='+p['installation_id']+'\n')
|
|
f.write('INSTALLATION_TOKEN='+p['installation_token']+'\n')
|
|
PY
|
|
# shellcheck disable=SC1090
|
|
source "$TMP_DIR/installation.env"
|
|
AUTH="Authorization: Installation $INSTALLATION_TOKEN"
|
|
|
|
status="$(curl -sS --connect-timeout 5 --max-time 30 -H "$AUTH" -D "$TMP_DIR/h" -o "$TMP_DIR/b" -w '%{http_code}' "$PUBLIC_BASE/v1/installations/$INSTALLATION_ID/topics" || true)"
|
|
printf '%-34s HTTP %s\n' "Push-Themen laden" "$status"
|
|
[[ "$status" == "200" ]] || { cat "$TMP_DIR/b"; exit 1; }
|
|
for topic in breaking-news niedersachsen program; do
|
|
grep -q "\"slug\":\"$topic\"" "$TMP_DIR/b" || { echo "Thema $topic fehlt"; exit 1; }
|
|
done
|
|
|
|
status="$(curl -sS --connect-timeout 5 --max-time 30 -X DELETE -H "$AUTH" -o /dev/null -w '%{http_code}' "$PUBLIC_BASE/v1/installations/$INSTALLATION_ID" || true)"
|
|
printf '%-34s HTTP %s\n' "Testinstallation löschen" "$status"
|
|
[[ "$status" == "204" ]] || exit 1
|
|
|
|
echo
|
|
echo "Landwelle Wunschbox-/Installations-API ist lokal und öffentlich erreichbar."
|