forked from p15670423/monkey
island: Add tests for PostBreachFilesService
This commit is contained in:
parent
4364a48561
commit
ea82e86df5
|
@ -0,0 +1,4 @@
|
|||
try:
|
||||
raise Exception("Ex")
|
||||
except Exception as ex:
|
||||
print(f"F: {ex}")
|
|
@ -5,6 +5,10 @@ import pytest
|
|||
from monkey_island.cc.services.post_breach_files import PostBreachFilesService
|
||||
|
||||
|
||||
def raise_(ex):
|
||||
raise ex
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def custom_pba_directory(tmpdir):
|
||||
PostBreachFilesService.initialize(tmpdir)
|
||||
|
@ -28,3 +32,29 @@ def test_remove_pba_files():
|
|||
|
||||
custom_pda_dir_contents = os.listdir(PostBreachFilesService.get_custom_pba_directory())
|
||||
assert len(custom_pda_dir_contents) == 0
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name != "posix", reason="Tests Posix (not Windows) permissions.")
|
||||
def test_custom_pba_dir_permissions():
|
||||
st = os.stat(PostBreachFilesService.get_custom_pba_directory())
|
||||
|
||||
assert st.st_mode == 0o40700
|
||||
|
||||
|
||||
def test_remove_failure(monkeypatch):
|
||||
monkeypatch.setattr(os, "remove", lambda x: raise_(OSError("Permission denied")))
|
||||
|
||||
try:
|
||||
create_custom_pba_file("windows_file")
|
||||
PostBreachFilesService.remove_PBA_files()
|
||||
except Exception as ex:
|
||||
pytest.fail(f"Unxepected exception: {ex}")
|
||||
|
||||
|
||||
def test_remove_nonexistant_file(monkeypatch):
|
||||
monkeypatch.setattr(os, "remove", lambda x: raise_(FileNotFoundError("FileNotFound")))
|
||||
|
||||
try:
|
||||
PostBreachFilesService.remove_file("/nonexistant/file")
|
||||
except Exception as ex:
|
||||
pytest.fail(f"Unxepected exception: {ex}")
|
||||
|
|
Loading…
Reference in New Issue