forked from p15670423/monkey
Island: Rename Filesystem to FileSystem
This commit is contained in:
parent
faf2259c59
commit
6c1fa80f42
|
@ -1,2 +1,2 @@
|
|||
from .file_storage.filesystem_storage import FilesystemStorage
|
||||
from .file_storage.file_system_storage import FileSystemStorage
|
||||
from .file_storage.i_file_repository import IFileRepository, FileRetrievalError
|
||||
|
|
|
@ -11,7 +11,7 @@ from .i_file_repository import FileRetrievalError, IFileRepository
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FilesystemStorage(IFileRepository):
|
||||
class FileSystemStorage(IFileRepository):
|
||||
"""
|
||||
A implementation of IFileStorageService that reads and writes files from/to the local
|
||||
filesystem.
|
|
@ -2,7 +2,7 @@ from pathlib import Path
|
|||
|
||||
from common import DIContainer
|
||||
from common.aws import AWSInstance
|
||||
from monkey_island.cc.repository import FilesystemStorage, IFileRepository
|
||||
from monkey_island.cc.repository import FileSystemStorage, IFileRepository
|
||||
from monkey_island.cc.services import AWSService
|
||||
from monkey_island.cc.services.post_breach_files import PostBreachFilesService
|
||||
from monkey_island.cc.services.run_local_monkey import LocalMonkeyRunService
|
||||
|
@ -15,7 +15,7 @@ def initialize_services(data_dir: Path) -> DIContainer:
|
|||
container = DIContainer()
|
||||
container.register_instance(AWSInstance, AWSInstance())
|
||||
|
||||
container.register_instance(IFileRepository, FilesystemStorage(data_dir / "custom_pbas"))
|
||||
container.register_instance(IFileRepository, FileSystemStorage(data_dir / "custom_pbas"))
|
||||
container.register_instance(AWSService, container.resolve(AWSService))
|
||||
|
||||
# This is temporary until we get DI all worked out.
|
||||
|
|
|
@ -4,7 +4,7 @@ from pathlib import Path
|
|||
import pytest
|
||||
from tests.monkey_island.utils import assert_linux_permissions, assert_windows_permissions
|
||||
|
||||
from monkey_island.cc.repository import FileRetrievalError, FilesystemStorage
|
||||
from monkey_island.cc.repository import FileRetrievalError, FileSystemStorage
|
||||
from monkey_island.cc.server_utils.file_utils import is_windows_os
|
||||
|
||||
|
||||
|
@ -13,13 +13,13 @@ def test_error_if_storage_directory_is_file(tmp_path):
|
|||
new_file.write_text("HelloWorld!")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
FilesystemStorage(new_file)
|
||||
FileSystemStorage(new_file)
|
||||
|
||||
|
||||
def test_directory_created(tmp_path):
|
||||
new_dir = tmp_path / "new_dir"
|
||||
|
||||
FilesystemStorage(new_dir)
|
||||
FileSystemStorage(new_dir)
|
||||
|
||||
assert new_dir.exists() and new_dir.is_dir()
|
||||
|
||||
|
@ -28,7 +28,7 @@ def test_directory_created(tmp_path):
|
|||
def test_directory_permissions__linux(tmp_path):
|
||||
new_dir = tmp_path / "new_dir"
|
||||
|
||||
FilesystemStorage(new_dir)
|
||||
FileSystemStorage(new_dir)
|
||||
|
||||
assert_linux_permissions(new_dir)
|
||||
|
||||
|
@ -37,7 +37,7 @@ def test_directory_permissions__linux(tmp_path):
|
|||
def test_directory_permissions__windows(tmp_path):
|
||||
new_dir = tmp_path / "new_dir"
|
||||
|
||||
FilesystemStorage(new_dir)
|
||||
FileSystemStorage(new_dir)
|
||||
|
||||
assert_windows_permissions(new_dir)
|
||||
|
||||
|
@ -47,7 +47,7 @@ def save_file(tmp_path, file_path_prefix=""):
|
|||
file_contents = "Hello World!"
|
||||
expected_file_path = tmp_path / file_name
|
||||
|
||||
fss = FilesystemStorage(tmp_path)
|
||||
fss = FileSystemStorage(tmp_path)
|
||||
fss.save_file(Path(file_path_prefix) / file_name, io.BytesIO(file_contents.encode()))
|
||||
|
||||
assert expected_file_path.is_file()
|
||||
|
@ -60,7 +60,7 @@ def delete_file(tmp_path, file_path_prefix=""):
|
|||
file.touch()
|
||||
assert file.is_file()
|
||||
|
||||
fss = FilesystemStorage(tmp_path)
|
||||
fss = FileSystemStorage(tmp_path)
|
||||
fss.delete_file(Path(file_path_prefix) / file_name)
|
||||
|
||||
assert not file.exists()
|
||||
|
@ -72,7 +72,7 @@ def open_file(tmp_path, file_path_prefix=""):
|
|||
expected_file_path = tmp_path / file_name
|
||||
expected_file_path.write_text(expected_file_contents)
|
||||
|
||||
fss = FilesystemStorage(tmp_path)
|
||||
fss = FileSystemStorage(tmp_path)
|
||||
with fss.open_file(Path(file_path_prefix) / file_name) as f:
|
||||
actual_file_contents = f.read()
|
||||
|
||||
|
@ -101,7 +101,7 @@ def test_remove_all_files(tmp_path):
|
|||
for filename in ["1.txt", "2.txt", "3.txt"]:
|
||||
(tmp_path / filename).touch()
|
||||
|
||||
fss = FilesystemStorage(tmp_path)
|
||||
fss = FileSystemStorage(tmp_path)
|
||||
fss.delete_all_files()
|
||||
|
||||
for file in tmp_path.iterdir():
|
||||
|
@ -114,7 +114,7 @@ def test_remove_all_files__skip_directories(tmp_path):
|
|||
for filename in ["1.txt", "2.txt", "3.txt"]:
|
||||
(tmp_path / filename).touch()
|
||||
|
||||
fss = FilesystemStorage(tmp_path)
|
||||
fss = FileSystemStorage(tmp_path)
|
||||
fss.delete_all_files()
|
||||
|
||||
for file in tmp_path.iterdir():
|
||||
|
@ -122,14 +122,14 @@ def test_remove_all_files__skip_directories(tmp_path):
|
|||
|
||||
|
||||
def test_remove_nonexistant_file(tmp_path):
|
||||
fss = FilesystemStorage(tmp_path)
|
||||
fss = FileSystemStorage(tmp_path)
|
||||
|
||||
# This test will fail if this call raises an exception.
|
||||
fss.delete_file("nonexistant_file.txt")
|
||||
|
||||
|
||||
def test_open_nonexistant_file(tmp_path):
|
||||
fss = FilesystemStorage(tmp_path)
|
||||
fss = FileSystemStorage(tmp_path)
|
||||
|
||||
with pytest.raises(FileRetrievalError):
|
||||
fss.open_file("nonexistant_file.txt")
|
||||
|
|
|
@ -4,13 +4,13 @@ import os
|
|||
import pytest
|
||||
from tests.utils import raise_
|
||||
|
||||
from monkey_island.cc.repository import FilesystemStorage
|
||||
from monkey_island.cc.repository import FileSystemStorage
|
||||
from monkey_island.cc.services.post_breach_files import PostBreachFilesService
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def file_storage_service(tmp_path):
|
||||
return FilesystemStorage(tmp_path)
|
||||
return FileSystemStorage(tmp_path)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
|
Loading…
Reference in New Issue