Files
mtusi2026lab2/scripts/check_expiry.py
T
User name 376f1a9a10
application / application (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
ЛР 2 — БПИ-2304 — Саламатин — на 4
2026-10-31 02:44:10 +03:00

36 lines
1.2 KiB
Python

"""Run against a separate API configured with SESSION_TTL_SECONDS=2."""
from pathlib import Path
import json
import os
import sys
import time
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "tests"))
from client import Client, check
def main():
c = Client(os.environ["EXPIRY_BASE_URL"])
deadline = time.monotonic() + 30
while True:
try:
c.call("GET", "/health/ready", schema="Health")
break
except AssertionError:
check(time.monotonic() < deadline, "TTL API did not become ready")
time.sleep(0.25)
actor = c.user("expiry")
c.call("GET", "/api/v1/users/me", actor=actor, schema="User")
time.sleep(2.3)
response = c.call("GET", "/api/v1/users/me", 401, actor=actor)
report = {"session_ttl_seconds": 2, "wait_seconds": 2.3,
"before_expiry_status": 200, "after_expiry_status": response["status"],
"result": "PASS"}
(ROOT / "evidence" / "expiry.json").write_text(json.dumps(report, indent=2) + "\n")
print("PASS: TTL=2s, initial 200, after 2.3s -> 401; normal API TTL unchanged")
if __name__ == "__main__":
main()