mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-12-15 11:43:41 +00:00
* initial auth implementation * add create user parser * add tests * update dependencies list * add login annd logout to index also improve auth * realworld fixes * add method set_option to Configuration and also use it everywhere * split CreateUser handler to additional read method * check user duplicate on auth mapping read * generate salt by using passlib instead of random.choice * case-insensetive usernames * update dependencies * update configuration reference * improve tests * fix codefactor errors * hide fields if authorization is enabled, but no auth supplied * add settings object for auth provider * readme update
33 lines
916 B
Python
33 lines
916 B
Python
import pytest
|
|
|
|
from collections import namedtuple
|
|
|
|
from ahriman.core.auth.auth import Auth
|
|
from ahriman.core.configuration import Configuration
|
|
from ahriman.models.user import User
|
|
from ahriman.web.middlewares.auth_handler import AuthorizationPolicy
|
|
|
|
_request = namedtuple("_request", ["path", "method"])
|
|
|
|
|
|
@pytest.fixture
|
|
def aiohttp_request() -> _request:
|
|
"""
|
|
fixture for aiohttp like object
|
|
:return: aiohttp like request test instance
|
|
"""
|
|
return _request("path", "GET")
|
|
|
|
|
|
@pytest.fixture
|
|
def authorization_policy(configuration: Configuration, user: User) -> AuthorizationPolicy:
|
|
"""
|
|
fixture for authorization policy
|
|
:return: authorization policy fixture
|
|
"""
|
|
configuration.set_option("auth", "target", "configuration")
|
|
validator = Auth.load(configuration)
|
|
policy = AuthorizationPolicy(validator)
|
|
policy.validator._users = {user.username: user}
|
|
return policy
|