#!/bin/sh set -eu cd "$(dirname "$0")/.." docker compose exec -T api sh -eu <<'CHECK' addr=https://openbao:8200/v1 req() { curl -sS --max-time 10 --cacert /tls/ca.crt --cert /tls/client.crt --key /tls/client.key "$@" } login() { req -f --data '{"name":"api"}' "$addr/auth/cert/login"; } header() { printf 'X-Vault-Token: %s\n' "$token"; } check_read() { status=$(header | req -H @- -o /dev/null -w '%{http_code}' "$addr/lab7/data/api") if [ "$status" != "$1" ]; then echo "Ожидался HTTP $1 при чтении KV, получен $status" >&2 exit 1 fi } auth=$(login) token=$(printf %s "$auth" | jq -er '.auth.client_token | strings | select(length > 0)') ttl=$(printf %s "$auth" | jq -er '.auth.lease_duration | numbers | select(. > 0 and . <= 120 and . == floor)') check_read 200 echo "Токен действует. Ожидаем истечения TTL ($ttl с)." sleep "$((ttl + 2))" check_read 403 token=$(login | jq -er '.auth.client_token | strings | select(length > 0)') check_read 200 header | req -f -H @- -X POST "$addr/auth/token/revoke-self" >/dev/null echo 'PASS: прежний токен истёк, повторный вход по сертификату разрешил чтение KV.' CHECK