"""Lab3 revocation: logout takes effect immediately on every replica. Session validity is decided only by PostgreSQL, so a revoked token must be rejected regardless of which replica answers and regardless of the cache state. The heavier Valkey-outage reproduction lives in scripts/check-revocation.py. """ from __future__ import annotations import os def _actor(client, label="revoke"): suffix = os.urandom(4).hex() username = f"s_{label}_{suffix}" password = "T3st-" + os.urandom(8).hex() assert client.register(username, password).status == 201 token = client.login(username, password).json["token"] return {"id": client.me(token).json["id"], "token": token} def test_logout_invalidates_across_replicas(client): actor = _actor(client) seen = set() for _ in range(20): response = client.me(actor["token"]) assert response.status == 200, response.body seen.add(response.instance_id) assert len(seen) >= 2, f"expected the LB to spread requests, saw {sorted(seen)}" logout = client.logout(actor["token"]) assert logout.status == 204, logout.body for _ in range(20): assert client.me(actor["token"]).status == 401