mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-23 10:49:55 +00:00
add settings object for auth provider
This commit is contained in:
@ -10,5 +10,4 @@ def mapping_auth(configuration: Configuration) -> MappingAuth:
|
||||
auth provider fixture
|
||||
:return: auth service instance
|
||||
"""
|
||||
configuration.set_option("auth", "enabled", "yes")
|
||||
return MappingAuth(configuration)
|
||||
|
@ -9,7 +9,7 @@ def test_load_dummy(configuration: Configuration) -> None:
|
||||
"""
|
||||
must load dummy validator if authorization is not enabled
|
||||
"""
|
||||
configuration.set_option("auth", "enabled", "no")
|
||||
configuration.set_option("auth", "target", "disabled")
|
||||
auth = Auth.load(configuration)
|
||||
assert isinstance(auth, Auth)
|
||||
|
||||
@ -26,7 +26,7 @@ def test_load_mapping(configuration: Configuration) -> None:
|
||||
"""
|
||||
must load mapping validator if option set
|
||||
"""
|
||||
configuration.set_option("auth", "enabled", "yes")
|
||||
configuration.set_option("auth", "target", "configuration")
|
||||
auth = Auth.load(configuration)
|
||||
assert isinstance(auth, MappingAuth)
|
||||
|
||||
|
36
tests/ahriman/models/test_auth_settings.py
Normal file
36
tests/ahriman/models/test_auth_settings.py
Normal file
@ -0,0 +1,36 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.exceptions import InvalidOption
|
||||
from ahriman.models.auth_settings import AuthSettings
|
||||
|
||||
|
||||
def test_from_option_invalid() -> None:
|
||||
"""
|
||||
must raise exception on invalid option
|
||||
"""
|
||||
with pytest.raises(InvalidOption, match=".* `invalid`$"):
|
||||
AuthSettings.from_option("invalid")
|
||||
|
||||
|
||||
def test_from_option_valid() -> None:
|
||||
"""
|
||||
must return value from valid options
|
||||
"""
|
||||
assert AuthSettings.from_option("disabled") == AuthSettings.Disabled
|
||||
assert AuthSettings.from_option("DISABLED") == AuthSettings.Disabled
|
||||
assert AuthSettings.from_option("no") == AuthSettings.Disabled
|
||||
assert AuthSettings.from_option("NO") == AuthSettings.Disabled
|
||||
|
||||
assert AuthSettings.from_option("configuration") == AuthSettings.Configuration
|
||||
assert AuthSettings.from_option("ConFigUration") == AuthSettings.Configuration
|
||||
assert AuthSettings.from_option("mapping") == AuthSettings.Configuration
|
||||
assert AuthSettings.from_option("MAPPing") == AuthSettings.Configuration
|
||||
|
||||
|
||||
def test_is_enabled() -> None:
|
||||
"""
|
||||
must mark as disabled authorization for disabled and enabled otherwise
|
||||
"""
|
||||
assert not AuthSettings.Disabled.is_enabled
|
||||
for option in filter(lambda o: o != AuthSettings.Disabled, AuthSettings):
|
||||
assert option.is_enabled
|
@ -32,7 +32,7 @@ def application_with_auth(configuration: Configuration, user: User, mocker: Mock
|
||||
:param mocker: mocker object
|
||||
:return: application test instance
|
||||
"""
|
||||
configuration.set_option("auth", "enabled", "yes")
|
||||
configuration.set_option("auth", "target", "configuration")
|
||||
mocker.patch.object(ahriman.core.auth.helpers, "_has_aiohttp_security", True)
|
||||
mocker.patch("pathlib.Path.mkdir")
|
||||
application = setup_service("x86_64", configuration)
|
||||
|
@ -25,7 +25,7 @@ def authorization_policy(configuration: Configuration, user: User) -> Authorizat
|
||||
fixture for authorization policy
|
||||
:return: authorization policy fixture
|
||||
"""
|
||||
configuration.set_option("auth", "enabled", "yes")
|
||||
configuration.set_option("auth", "target", "configuration")
|
||||
validator = Auth.load(configuration)
|
||||
policy = AuthorizationPolicy(validator)
|
||||
policy.validator._users = {user.username: user}
|
||||
|
Reference in New Issue
Block a user