forked from mtusi2026/mtusi2026lab3
Исправить обход отзыва сессии при сбое Valkey
resolve() больше не доверяет кэшу: валидность сессии всегда проверяется в PostgreSQL, поэтому неудавшаяся инвалидация при недоступном Valkey не воскрешает отозванный токен. Valkey остаётся read-through кэшем неизменяемого профиля. Добавлены scripts/check-revocation.py и student-tests/test_session_revocation.py.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""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
|
||||
Reference in New Issue
Block a user