auto-form / tests /test_auth_gate.py
Menixis's picture
Claude Fable 5
feat: ALLOWED_USERS allowlist authorization (require_authorized) after login β€” server-side enforcement; unset secret = allow all (no lockout); themed denial card + logout
5ec0721
Raw History Blame Contribute Delete
916 Bytes
# -*- coding: utf-8 -*-
"""auth_gate β€” allowlist parsing (the st.user paths need a live session)."""
import auth_gate
def test_allowed_users_parsing(monkeypatch):
monkeypatch.setenv("ALLOWED_USERS",
" Kansak.s@pttplc.com, other@pttplc.com ,, ")
assert auth_gate._allowed_users() == {"kansak.s@pttplc.com",
"other@pttplc.com"}
def test_allowed_users_empty(monkeypatch):
monkeypatch.delenv("ALLOWED_USERS", raising=False)
assert auth_gate._allowed_users() == set()
monkeypatch.setenv("ALLOWED_USERS", " ")
assert auth_gate._allowed_users() == set()
def test_require_authorized_noop_when_unset(monkeypatch):
"""Unset allowlist β†’ returns without touching st.user (never locks out)."""
monkeypatch.delenv("ALLOWED_USERS", raising=False)
auth_gate.require_authorized() # must not raise / st.stop