test(services): test that we indeed return correct folders and owned folders from real services

This commit is contained in:
Houkime 2023-04-19 11:34:14 +00:00
parent 043675ce14
commit ba72fadb8d
3 changed files with 44 additions and 2 deletions

View file

@ -37,6 +37,10 @@ class Bitwarden(Service):
"""Read SVG icon from file and return it as base64 encoded string.""" """Read SVG icon from file and return it as base64 encoded string."""
return base64.b64encode(BITWARDEN_ICON.encode("utf-8")).decode("utf-8") return base64.b64encode(BITWARDEN_ICON.encode("utf-8")).decode("utf-8")
@staticmethod
def get_user() -> str:
return "vaultwarden"
@staticmethod @staticmethod
def get_url() -> typing.Optional[str]: def get_url() -> typing.Optional[str]:
"""Return service url.""" """Return service url."""

View file

@ -6,6 +6,7 @@ from selfprivacy_api.jobs import Job, Jobs
from selfprivacy_api.services.generic_service_mover import FolderMoveNames, move_service from selfprivacy_api.services.generic_service_mover import FolderMoveNames, move_service
from selfprivacy_api.services.generic_status_getter import get_service_status from selfprivacy_api.services.generic_status_getter import get_service_status
from selfprivacy_api.services.service import Service, ServiceDnsRecord, ServiceStatus from selfprivacy_api.services.service import Service, ServiceDnsRecord, ServiceStatus
from selfprivacy_api.services.owned_path import OwnedPath
from selfprivacy_api.utils import ReadUserData, WriteUserData, get_domain from selfprivacy_api.utils import ReadUserData, WriteUserData, get_domain
from selfprivacy_api.utils.block_devices import BlockDevice from selfprivacy_api.utils.block_devices import BlockDevice
import selfprivacy_api.utils.network as network_utils import selfprivacy_api.utils.network as network_utils
@ -96,8 +97,23 @@ class Pleroma(Service):
return "" return ""
@staticmethod @staticmethod
def get_folders() -> typing.List[str]: def get_owned_folders() -> typing.List[OwnedPath]:
return ["/var/lib/pleroma", "/var/lib/postgresql"] """
Get a list of occupied directories with ownership info
pleroma has folders that are owned by different users
"""
return [
OwnedPath(
path="/var/lib/pleroma",
owner="pleroma",
group="pleroma",
),
OwnedPath(
path="/var/lib/postgresql",
owner="postgres",
group="postgres",
),
]
@staticmethod @staticmethod
def get_drive() -> str: def get_drive() -> str:

View file

@ -3,6 +3,10 @@
""" """
from pytest import raises from pytest import raises
from selfprivacy_api.services.bitwarden import Bitwarden
from selfprivacy_api.services.pleroma import Pleroma
from selfprivacy_api.services.owned_path import OwnedPath
from selfprivacy_api.services.test_service import DummyService from selfprivacy_api.services.test_service import DummyService
from selfprivacy_api.services.service import Service from selfprivacy_api.services.service import Service
@ -18,3 +22,21 @@ def test_unimplemented_folders_raises():
owned_folders = OurDummy.get_owned_folders() owned_folders = OurDummy.get_owned_folders()
assert owned_folders is not None assert owned_folders is not None
def test_owned_folders_from_not_owned():
assert Bitwarden.get_owned_folders() == [
OwnedPath(
path=folder,
group="vaultwarden",
owner="vaultwarden",
)
for folder in Bitwarden.get_folders()
]
def test_paths_from_owned_paths():
assert len(Pleroma.get_folders()) == 2
assert Pleroma.get_folders() == [
ownedpath.path for ownedpath in Pleroma.get_owned_folders()
]