2021-11-29 19:16:08 +00:00
|
|
|
import pytest
|
|
|
|
|
2023-11-24 14:16:42 +00:00
|
|
|
from selfprivacy_api.services.service import ServiceStatus
|
|
|
|
from selfprivacy_api.services.bitwarden import Bitwarden
|
|
|
|
from selfprivacy_api.services.gitea import Gitea
|
|
|
|
from selfprivacy_api.services.mailserver import MailServer
|
|
|
|
from selfprivacy_api.services.nextcloud import Nextcloud
|
|
|
|
from selfprivacy_api.services.ocserv import Ocserv
|
|
|
|
from selfprivacy_api.services.pleroma import Pleroma
|
2021-11-29 19:16:08 +00:00
|
|
|
|
2021-11-30 21:53:39 +00:00
|
|
|
|
2021-11-29 19:16:08 +00:00
|
|
|
def call_args_asserts(mocked_object):
|
2022-08-25 17:03:56 +00:00
|
|
|
assert mocked_object.call_count == 7
|
2021-11-29 19:16:08 +00:00
|
|
|
assert mocked_object.call_args_list[0][0][0] == [
|
|
|
|
"systemctl",
|
2022-08-25 17:03:56 +00:00
|
|
|
"show",
|
2021-11-29 19:16:08 +00:00
|
|
|
"dovecot2.service",
|
|
|
|
]
|
|
|
|
assert mocked_object.call_args_list[1][0][0] == [
|
|
|
|
"systemctl",
|
2022-08-25 17:03:56 +00:00
|
|
|
"show",
|
2021-11-29 19:16:08 +00:00
|
|
|
"postfix.service",
|
|
|
|
]
|
|
|
|
assert mocked_object.call_args_list[2][0][0] == [
|
|
|
|
"systemctl",
|
2022-08-25 17:03:56 +00:00
|
|
|
"show",
|
2022-05-26 15:40:07 +00:00
|
|
|
"vaultwarden.service",
|
2021-11-29 19:16:08 +00:00
|
|
|
]
|
2022-08-25 17:03:56 +00:00
|
|
|
assert mocked_object.call_args_list[3][0][0] == [
|
2021-11-29 19:16:08 +00:00
|
|
|
"systemctl",
|
2022-08-25 17:03:56 +00:00
|
|
|
"show",
|
2021-11-29 19:16:08 +00:00
|
|
|
"gitea.service",
|
|
|
|
]
|
2022-08-25 17:03:56 +00:00
|
|
|
assert mocked_object.call_args_list[4][0][0] == [
|
2021-11-29 19:16:08 +00:00
|
|
|
"systemctl",
|
2022-08-25 17:03:56 +00:00
|
|
|
"show",
|
2021-11-29 19:16:08 +00:00
|
|
|
"phpfpm-nextcloud.service",
|
|
|
|
]
|
2022-08-25 17:03:56 +00:00
|
|
|
assert mocked_object.call_args_list[5][0][0] == [
|
2021-11-29 19:16:08 +00:00
|
|
|
"systemctl",
|
2022-08-25 17:03:56 +00:00
|
|
|
"show",
|
2021-11-29 19:16:08 +00:00
|
|
|
"ocserv.service",
|
|
|
|
]
|
2022-08-25 17:03:56 +00:00
|
|
|
assert mocked_object.call_args_list[6][0][0] == [
|
2021-11-29 19:16:08 +00:00
|
|
|
"systemctl",
|
2022-08-25 17:03:56 +00:00
|
|
|
"show",
|
2021-11-29 19:16:08 +00:00
|
|
|
"pleroma.service",
|
|
|
|
]
|
|
|
|
|
2021-11-30 21:53:39 +00:00
|
|
|
|
2022-08-25 17:03:56 +00:00
|
|
|
SUCCESSFUL_STATUS = b"""
|
|
|
|
Type=oneshot
|
|
|
|
ExitType=main
|
|
|
|
Restart=no
|
|
|
|
NotifyAccess=none
|
|
|
|
RestartUSec=100ms
|
|
|
|
LoadState=loaded
|
|
|
|
ActiveState=active
|
|
|
|
FreezerState=running
|
|
|
|
SubState=exited
|
|
|
|
"""
|
|
|
|
|
|
|
|
FAILED_STATUS = b"""
|
|
|
|
Type=oneshot
|
|
|
|
ExitType=main
|
|
|
|
Restart=no
|
|
|
|
NotifyAccess=none
|
|
|
|
RestartUSec=100ms
|
|
|
|
LoadState=loaded
|
|
|
|
ActiveState=failed
|
|
|
|
FreezerState=running
|
|
|
|
SubState=exited
|
|
|
|
"""
|
2021-11-29 19:16:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def mock_subproccess_popen(mocker):
|
2022-08-25 17:03:56 +00:00
|
|
|
mock = mocker.patch(
|
|
|
|
"subprocess.check_output", autospec=True, return_value=SUCCESSFUL_STATUS
|
|
|
|
)
|
2021-11-29 19:16:08 +00:00
|
|
|
return mock
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def mock_broken_service(mocker):
|
|
|
|
mock = mocker.patch(
|
2022-08-25 17:03:56 +00:00
|
|
|
"subprocess.check_output", autospec=True, return_value=FAILED_STATUS
|
2021-11-29 19:16:08 +00:00
|
|
|
)
|
|
|
|
return mock
|
|
|
|
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
def test_dkim_key(authorized_client, mock_subproccess_popen):
|
2023-11-24 14:16:42 +00:00
|
|
|
assert MailServer.get_status() == ServiceStatus.ACTIVE
|
|
|
|
assert Bitwarden.get_status() == ServiceStatus.ACTIVE
|
|
|
|
assert Gitea.get_status() == ServiceStatus.ACTIVE
|
|
|
|
assert Nextcloud.get_status() == ServiceStatus.ACTIVE
|
|
|
|
assert Ocserv.get_status() == ServiceStatus.ACTIVE
|
|
|
|
assert Pleroma.get_status() == ServiceStatus.ACTIVE
|
2021-11-29 19:16:08 +00:00
|
|
|
call_args_asserts(mock_subproccess_popen)
|
|
|
|
|
|
|
|
|
|
|
|
def test_no_dkim_key(authorized_client, mock_broken_service):
|
2023-11-24 14:16:42 +00:00
|
|
|
assert MailServer.get_status() == ServiceStatus.FAILED
|
|
|
|
assert Bitwarden.get_status() == ServiceStatus.FAILED
|
|
|
|
assert Gitea.get_status() == ServiceStatus.FAILED
|
|
|
|
assert Nextcloud.get_status() == ServiceStatus.FAILED
|
|
|
|
assert Ocserv.get_status() == ServiceStatus.FAILED
|
|
|
|
assert Pleroma.get_status() == ServiceStatus.FAILED
|
2021-11-29 19:16:08 +00:00
|
|
|
call_args_asserts(mock_broken_service)
|