2026-08-16 22:04:11 +03:00

15 lines
526 B
Python

import pytest
from lawsynth_server.auth import TokenAuthenticator, require_scope
from lawsynth_server.errors import AuthenticationError, AuthorizationError
def test_bearer_auth_and_scope():
auth = TokenAuthenticator({"secret": ("org", frozenset({"read"}))})
principal = auth.authenticate("Bearer secret")
require_scope(principal, "read")
with pytest.raises(AuthorizationError):
require_scope(principal, "write")
with pytest.raises(AuthenticationError):
auth.authenticate("Basic secret")