forked from p15670423/monkey
Island: Remove disused PostBreachFilesService
This commit is contained in:
parent
70b404b9f5
commit
fe9cc86d8b
|
@ -33,7 +33,6 @@ from monkey_island.cc.repository import (
|
|||
from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH
|
||||
from monkey_island.cc.server_utils.encryption import ILockableEncryptor, RepositoryEncryptor
|
||||
from monkey_island.cc.services import AWSService, IslandModeService, RepositoryService
|
||||
from monkey_island.cc.services.post_breach_files import PostBreachFilesService
|
||||
from monkey_island.cc.services.run_local_monkey import LocalMonkeyRunService
|
||||
from monkey_island.cc.services.telemetry.processing.credentials.credentials_parser import (
|
||||
CredentialsParser,
|
||||
|
@ -70,7 +69,6 @@ def initialize_services(data_dir: Path) -> DIContainer:
|
|||
_patch_credentials_parser(container)
|
||||
|
||||
# This is temporary until we get DI all worked out.
|
||||
PostBreachFilesService.initialize(container.resolve(IFileRepository))
|
||||
ReportService.initialize(container.resolve(AWSService))
|
||||
|
||||
return container
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
import logging
|
||||
|
||||
from monkey_island.cc.repository import IFileRepository
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# TODO: This service wraps an IFileStorageService for the sole purpose of making the
|
||||
# `remove_PBA_files()` method available to the ConfigService. This whole service can be
|
||||
# removed once ConfigService is refactored to be stateful (it already is but everything is
|
||||
# still statically/globally scoped) and use dependency injection.
|
||||
class PostBreachFilesService:
|
||||
_file_storage_service = None
|
||||
|
||||
# TODO: A number of these services should be instance objects instead of
|
||||
# static/singleton hybrids. At the moment, this requires invasive refactoring that's
|
||||
# not a priority.
|
||||
@classmethod
|
||||
def initialize(cls, file_storage_service: IFileRepository):
|
||||
cls._file_storage_service = file_storage_service
|
||||
|
||||
@classmethod
|
||||
def remove_PBA_files(cls):
|
||||
cls._file_storage_service.delete_all_files()
|
|
@ -1,43 +0,0 @@
|
|||
import io
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from tests.utils import raise_
|
||||
|
||||
from monkey_island.cc.repository import LocalStorageFileRepository
|
||||
from monkey_island.cc.services.post_breach_files import PostBreachFilesService
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def local_storage_file_repository(tmp_path):
|
||||
return LocalStorageFileRepository(tmp_path)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def post_breach_files_service(local_storage_file_repository):
|
||||
PostBreachFilesService.initialize(local_storage_file_repository)
|
||||
|
||||
|
||||
def test_remove_pba_files(local_storage_file_repository, tmp_path):
|
||||
local_storage_file_repository.save_file("linux_file", io.BytesIO(b""))
|
||||
local_storage_file_repository.save_file("windows_file", io.BytesIO(b""))
|
||||
assert not dir_is_empty(tmp_path)
|
||||
|
||||
PostBreachFilesService.remove_PBA_files()
|
||||
|
||||
assert dir_is_empty(tmp_path)
|
||||
|
||||
|
||||
def dir_is_empty(dir_path):
|
||||
dir_contents = os.listdir(dir_path)
|
||||
return len(dir_contents) == 0
|
||||
|
||||
|
||||
def test_remove_failure(local_storage_file_repository, monkeypatch):
|
||||
monkeypatch.setattr(os, "remove", lambda x: raise_(OSError("Permission denied")))
|
||||
|
||||
try:
|
||||
local_storage_file_repository.save_file("windows_file", io.BytesIO(b""))
|
||||
PostBreachFilesService.remove_PBA_files()
|
||||
except Exception as ex:
|
||||
pytest.fail(f"Unxepected exception: {ex}")
|
Loading…
Reference in New Issue