mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-23 23:07:17 +00:00
better reload
This commit is contained in:
parent
ba483173af
commit
57f45fdc89
@ -152,7 +152,7 @@ class Setup(Handler):
|
||||
:param architecture: repository architecture
|
||||
"""
|
||||
command = Setup.build_command(prefix, architecture)
|
||||
Setup.SUDOERS_PATH.write_text(f"ahriman ALL=(ALL) NOPASSWD: {command} *\n")
|
||||
Setup.SUDOERS_PATH.write_text(f"ahriman ALL=(ALL) NOPASSWD: {command} *\n", encoding="utf8")
|
||||
Setup.SUDOERS_PATH.chmod(0o400) # security!
|
||||
|
||||
@staticmethod
|
||||
|
@ -52,7 +52,7 @@ class User(Handler):
|
||||
User.clear_user(auth_configuration, user)
|
||||
if not args.remove:
|
||||
User.create_configuration(auth_configuration, user, salt, args.as_service)
|
||||
User.write_configuration(configuration)
|
||||
User.write_configuration(auth_configuration)
|
||||
|
||||
if not args.no_reload:
|
||||
client = Application(architecture, configuration, no_report=False).repository.reporter
|
||||
|
@ -72,7 +72,7 @@ class WebClient(Client):
|
||||
"""
|
||||
:return: full url for web service to reload authentication module
|
||||
"""
|
||||
return f"{self.address}/status-api/v1/reload-auth"
|
||||
return f"{self.address}/service-api/v1/reload-auth"
|
||||
|
||||
@property
|
||||
def _status_url(self) -> str:
|
||||
|
@ -35,6 +35,14 @@ class ReloadAuthView(BaseView):
|
||||
:return: 204 on success
|
||||
"""
|
||||
self.configuration.reload()
|
||||
self.request.app["validator"] = Auth.load(self.configuration)
|
||||
|
||||
try:
|
||||
import aiohttp_security # type: ignore
|
||||
self.request.app[aiohttp_security.api.AUTZ_KEY].validator =\
|
||||
self.request.app["validator"] =\
|
||||
Auth.load(self.configuration)
|
||||
except (ImportError, KeyError):
|
||||
self.request.app.logger.warning("could not update authentication module validator", exc_info=True)
|
||||
raise
|
||||
|
||||
return HTTPNoContent()
|
||||
|
@ -2,14 +2,26 @@ from aiohttp.test_utils import TestClient
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
|
||||
async def test_post(client: TestClient, mocker: MockerFixture) -> None:
|
||||
async def test_post(client_with_auth: TestClient, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call post request correctly
|
||||
"""
|
||||
mocker.patch("aiohttp_security.check_permission", return_value=True)
|
||||
reload_mock = mocker.patch("ahriman.core.configuration.Configuration.reload")
|
||||
load_mock = mocker.patch("ahriman.core.auth.auth.Auth.load")
|
||||
response = await client.post("/service-api/v1/reload-auth")
|
||||
response = await client_with_auth.post("/service-api/v1/reload-auth")
|
||||
|
||||
assert response.ok
|
||||
reload_mock.assert_called_once()
|
||||
load_mock.assert_called_with(client.app["configuration"])
|
||||
load_mock.assert_called_with(client_with_auth.app["configuration"])
|
||||
|
||||
|
||||
async def test_post_no_auth(client: TestClient, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call return 500 if no authorization module loaded
|
||||
"""
|
||||
reload_mock = mocker.patch("ahriman.core.configuration.Configuration.reload")
|
||||
response = await client.post("/service-api/v1/reload-auth")
|
||||
|
||||
assert response.status == 500
|
||||
reload_mock.assert_called_once()
|
||||
|
Loading…
Reference in New Issue
Block a user