lab7
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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")
|
||||
Reference in New Issue
Block a user