Files
ahriman/tests/ahriman/core/auth/test_auth.py
Evgenii Alekseev a05eab9042 feat: brand-new interface (#158)
This was initally generated by ai, but later has been heavily edited.
The reason why it has been implemented is that there are plans to
implement more features to ui, but it becomes hard to add new features
to plain js, so I decided to rewrite it in typescript.

Yet because it is still ai slop, it is still possible to enable old
interface via configuration, even though new interface is turned on by
default to get feedback
2026-03-06 00:59:10 +02:00

93 lines
2.8 KiB
Python

from ahriman.core.auth import Auth
from ahriman.core.auth.mapping import Mapping
from ahriman.core.auth.oauth import OAuth
from ahriman.core.auth.pam import PAM
from ahriman.core.configuration import Configuration
from ahriman.core.database import SQLite
from ahriman.models.user import User
from ahriman.models.user_access import UserAccess
def test_auth_control(auth: Auth) -> None:
"""
must return a control for authorization
"""
assert auth.auth_control
assert "button" in auth.auth_control # I think it should be a button
def test_is_external(auth: Auth) -> None:
"""
must not be external provider
"""
assert not auth.is_external
def test_load_dummy(configuration: Configuration, database: SQLite) -> None:
"""
must load dummy validator if authorization is not enabled
"""
configuration.set_option("auth", "target", "disabled")
auth = Auth.load(configuration, database)
assert isinstance(auth, Auth)
def test_load_dummy_empty(configuration: Configuration, database: SQLite) -> None:
"""
must load dummy validator if no option set
"""
auth = Auth.load(configuration, database)
assert isinstance(auth, Auth)
def test_load_mapping(configuration: Configuration, database: SQLite) -> None:
"""
must load mapping validator if option set
"""
configuration.set_option("auth", "target", "configuration")
auth = Auth.load(configuration, database)
assert isinstance(auth, Mapping)
def test_load_oauth(configuration: Configuration, database: SQLite) -> None:
"""
must load OAuth2 validator if option set
"""
configuration.set_option("auth", "target", "oauth")
configuration.set_option("web", "address", "https://example.com")
auth = Auth.load(configuration, database)
assert isinstance(auth, OAuth)
def test_load_pam(configuration: Configuration, database: SQLite) -> None:
"""
must load pam validator if option set
"""
configuration.set_option("auth", "target", "pam")
configuration.set_option("auth", "full_access_group", "wheel")
auth = Auth.load(configuration, database)
assert isinstance(auth, PAM)
async def test_check_credentials(auth: Auth, user: User) -> None:
"""
must pass any credentials
"""
assert await auth.check_credentials(user.username, user.password)
assert await auth.check_credentials("", None)
async def test_known_username(auth: Auth, user: User) -> None:
"""
must allow any username
"""
assert await auth.known_username(user.username)
async def test_verify_access(auth: Auth, user: User) -> None:
"""
must allow any access
"""
assert await auth.verify_access(user.username, user.access, None)
assert await auth.verify_access(user.username, UserAccess.Full, None)