mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
rase 405 error in case if GET login method is used whereas no aioauth
library installed
This commit is contained in:
parent
c7de182f3d
commit
9cb39f6767
@ -20,6 +20,14 @@ ahriman.core.formatters.build\_printer module
|
||||
:no-undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
ahriman.core.formatters.configuration\_paths\_printer module
|
||||
------------------------------------------------------------
|
||||
|
||||
.. automodule:: ahriman.core.formatters.configuration_paths_printer
|
||||
:members:
|
||||
:no-undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
ahriman.core.formatters.configuration\_printer module
|
||||
-----------------------------------------------------
|
||||
|
||||
|
@ -64,7 +64,11 @@ class LoginView(BaseView):
|
||||
HTTPMethodNotAllowed: in case if method is used, but OAuth is disabled
|
||||
HTTPUnauthorized: if case of authorization error
|
||||
"""
|
||||
from ahriman.core.auth.oauth import OAuth
|
||||
try:
|
||||
from ahriman.core.auth.oauth import OAuth
|
||||
except ImportError:
|
||||
# no aioauth library found
|
||||
raise HTTPMethodNotAllowed(self.request.method, ["POST"])
|
||||
|
||||
oauth_provider = self.validator
|
||||
if not isinstance(oauth_provider, OAuth): # there is actually property, but mypy does not like it anyway
|
||||
|
@ -88,6 +88,30 @@ def get_package_status_extended(package: Package) -> dict[str, Any]:
|
||||
return {"status": BuildStatus().view(), "package": package.view()}
|
||||
|
||||
|
||||
@pytest.helpers.register
|
||||
def import_error(package: str, components: list[str], mocker: MockerFixture) -> MagicMock:
|
||||
"""
|
||||
mock import error
|
||||
|
||||
Args:
|
||||
package(str): package name to import
|
||||
components(list[str]): component to import if any (e.g. from ... import ...)
|
||||
mocker(MockerFixture): mocker object
|
||||
|
||||
Returns:
|
||||
MagicMock: mocked object
|
||||
"""
|
||||
import builtins
|
||||
_import = builtins.__import__
|
||||
|
||||
def test_import(name: str, globals: Any, locals: Any, from_list: list[str], level: Any):
|
||||
if name == package and (not components or any(component in from_list for component in components)):
|
||||
raise ImportError
|
||||
return _import(name, globals, locals, from_list, level)
|
||||
|
||||
return mocker.patch.object(builtins, "__import__", test_import)
|
||||
|
||||
|
||||
# generic fixtures
|
||||
@pytest.fixture
|
||||
def aur_package_ahriman() -> AURPackage:
|
||||
|
@ -25,6 +25,15 @@ async def test_get_default_validator(client_with_auth: TestClient) -> None:
|
||||
assert response.status == 405
|
||||
|
||||
|
||||
async def test_get_import_error(client_with_auth: TestClient, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must return 405 on import error
|
||||
"""
|
||||
pytest.helpers.import_error("ahriman.core.auth.oauth", ["OAuth"], mocker)
|
||||
response = await client_with_auth.get("/api/v1/login")
|
||||
assert response.status == 405
|
||||
|
||||
|
||||
async def test_get_redirect_to_oauth(client_with_oauth_auth: TestClient) -> None:
|
||||
"""
|
||||
must redirect to OAuth service provider in case if no code is supplied
|
||||
|
Loading…
Reference in New Issue
Block a user