"""Session expiry (short TTL) — run against stack with SESSION_TTL_SECONDS=2.""" from __future__ import annotations import base64 import os import time from helpers import call, register def test_session_expiry_if_short_ttl(): ttl = int(os.environ.get("SESSION_TTL_SECONDS", "3600")) if ttl > 5: print("SKIP expiry: SESSION_TTL_SECONDS=%s (need <=5 for this test)" % ttl) return a = register("expire") time.sleep(ttl + 1.5) call("GET", "/api/v1/users/me", 401, token=a["token"]) def test_login_after_register(): a = register("relogin") cred = base64.b64encode( (a["registration"]["username"] + ":" + a["registration"]["password"]).encode() ).decode() session = call( "POST", "/api/v1/auth/sessions", 201, headers={"Authorization": "Basic " + cred}, )["json"] assert session["token_type"] == "Bearer" assert session["user"]["id"] == a["id"]