forked from mtusi2026/mtusi2026lab2
Исправить logout при сбое записи в кэш сессий
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
import hashlib
|
||||
import time
|
||||
|
||||
from stack import BASE_URL, Client, Failure, check, compose, main_wrapper, ok, valkey
|
||||
@@ -48,6 +49,29 @@ def main():
|
||||
finally:
|
||||
compose("start", "valkey")
|
||||
|
||||
paused = c.user("pause")
|
||||
key = "session:" + hashlib.sha256(paused["token"].encode("ascii")).hexdigest()
|
||||
deadline = time.monotonic() + 15
|
||||
while not valkey("GET", key).startswith("{"):
|
||||
check(time.monotonic() < deadline, "live session must be cached before the failure")
|
||||
c.call("GET", "/api/v1/users/me", actor=paused, schema="User")
|
||||
time.sleep(0.5)
|
||||
try:
|
||||
compose("pause", "valkey")
|
||||
status = c.call("DELETE", "/api/v1/auth/sessions/current", [204, 503], actor=paused)["status"]
|
||||
finally:
|
||||
compose("unpause", "valkey")
|
||||
check(status == 503, "logout must not report success while the cache still holds the live session (got %d)" % status)
|
||||
time.sleep(6)
|
||||
c.call("GET", "/api/v1/users/me", 401, actor=paused)
|
||||
deadline = time.monotonic() + 10
|
||||
while valkey("GET", key) != "revoked":
|
||||
check(time.monotonic() < deadline, "tombstone must be written once Valkey is back")
|
||||
time.sleep(0.5)
|
||||
c.call("GET", "/api/v1/users/me", 401, actor=paused)
|
||||
c.call("DELETE", "/api/v1/auth/sessions/current", 401, actor=paused)
|
||||
ok("tombstone write failed during logout -> 503, cached session never accepted again, tombstone repaired")
|
||||
|
||||
fresh = c.user("dbdown")
|
||||
try:
|
||||
compose("stop", "postgres")
|
||||
|
||||
Reference in New Issue
Block a user