36 lines
865 B
Python
36 lines
865 B
Python
import sys
|
|
import subprocess
|
|
from pathlib import Path
|
|
from uuid import UUID
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests"))
|
|
|
|
from client import Client
|
|
|
|
c = Client("https://localhost:8443", "secrets/ca.crt")
|
|
alice, bob, eve, chat = c.bootstrap()
|
|
|
|
c.call("GET", "/api/v1/users/me", 200, actor=alice)
|
|
print("Before expiry: 200 OK")
|
|
|
|
user_id = str(UUID(str(alice["id"])))
|
|
|
|
sql = (
|
|
"UPDATE sessions SET expires_at = now() - interval '1 second' "
|
|
f"WHERE user_id = '{user_id}';"
|
|
)
|
|
|
|
subprocess.run(
|
|
[
|
|
"docker", "compose", "exec", "-T", "postgres",
|
|
"sh", "-c",
|
|
'psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB"',
|
|
],
|
|
input=sql,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
|
|
c.call("GET", "/api/v1/users/me", 401, actor=alice)
|
|
print("After expiry: 401 Unauthorized")
|
|
print("PASS: expired session rejected") |