лабораторная работа 7

This commit is contained in:
2026-11-18 01:02:09 +03:00
parent 20afc2c790
commit b035b50dbd
298 changed files with 28830 additions and 109 deletions
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
"""Минимальное воспроизведение замечания ревью №1 (отзыв токена при разрыве с Redis).
Прогрев кэша -> разрыв сети API<->Redis без рестарта Redis -> logout ->
восстановление связи -> 8 с опроса старого токена (дольше circuit breaker).
Ожидается только 401. По умолчанию — команды docker compose-стенда:
python student-tests/revocation_partition.py --base-url https://localhost:8443
"""
import tlsenv # noqa: F401 lab7: HTTPS с проверкой CA стенда
import argparse, shlex, subprocess, sys, time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import common
from common import actor, request
p = argparse.ArgumentParser()
p.add_argument("--base-url", default="https://localhost:8443")
p.add_argument("--partition", default="docker network disconnect messenger-lab3_backend messenger-lab3-redis-1")
p.add_argument("--heal", default="docker network connect --alias redis messenger-lab3_backend messenger-lab3-redis-1")
args = p.parse_args()
common.BASE_URL = args.base_url.rstrip("/")
ROOT = Path(__file__).resolve().parents[1]
def run(cmd):
subprocess.run(shlex.split(cmd), cwd=ROOT, check=True)
a = actor("repro"); t = a["_token"]
for _ in range(2): request("GET","/api/v1/users/me",token=t)
run(args.partition)
try:
print("logout during partition:", request("DELETE","/api/v1/auth/sessions/current",token=t).status)
finally:
run(args.heal)
seen=set(); end=time.monotonic()+8
while time.monotonic()<end:
seen.add(request("GET","/api/v1/users/me",token=t).status); time.sleep(0.25)
print("revoked token statuses over 8 s after heal:", sorted(seen))
ok = seen == {401}
print("PASS" if ok else "FAIL", ": revoked token never accepted after partition heals")
sys.exit(0 if ok else 1)