32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
import sqlite3
|
|
|
|
from src.session_store import SessionStore
|
|
|
|
|
|
def test_revocation_is_durable_and_scoped_to_one_session(tmp_path):
|
|
now = [1_000.0]
|
|
database = tmp_path / "sessions.sqlite3"
|
|
first = SessionStore(database, clock=lambda: now[0])
|
|
first.activate("first-session-secret", 2_000)
|
|
first.activate("second-session-secret", 2_000)
|
|
|
|
reconstructed = SessionStore(database, clock=lambda: now[0])
|
|
reconstructed.revoke("first-session-secret")
|
|
|
|
assert reconstructed.is_active("first-session-secret", 2_000) is False
|
|
assert reconstructed.is_active("second-session-secret", 2_000) is True
|
|
assert b"first-session-secret" not in database.read_bytes()
|
|
assert b"second-session-secret" not in database.read_bytes()
|
|
|
|
|
|
def test_expired_sessions_are_rejected_and_pruned(tmp_path):
|
|
now = [1_000.0]
|
|
store = SessionStore(tmp_path / "sessions.sqlite3", clock=lambda: now[0])
|
|
store.activate("expiring-session", 1_001)
|
|
|
|
now[0] = 1_001.0
|
|
|
|
assert store.is_active("expiring-session", 1_001) is False
|
|
with sqlite3.connect(store.path) as connection:
|
|
assert connection.execute("SELECT COUNT(*) FROM active_sessions").fetchone() == (0,)
|