"""Истечение сессии: API перезапускается с SESSION_TTL_SECONDS=2, затем возвращается обычный TTL.""" import time from common import * TTL = 2 def main(): compose("up", "-d", "api", env={"SESSION_TTL_SECONDS": str(TTL)}) wait_ready() try: alice = new_user("exp") session = login(alice) token = session["token"] check(call("GET", "/api/v1/users/me", headers=bearer(token))[0] == 200, "fresh token works (and is cached)") time.sleep(TTL + 1.5) st, _, h, _ = call("GET", "/api/v1/users/me", headers=bearer(token)) check(st == 401 and h.get("WWW-Authenticate", "").startswith("Bearer"), f"expired token must be 401, got {st}") print(f"ok: TTL={TTL}s, after {TTL + 1.5}s the same token -> 401 (cache does not extend the session)") finally: compose("up", "-d", "api") # обычный TTL из .env wait_ready() print("PASS: test_expiry") run(main)