forked from p15670423/monkey
agent: Rename get_all_files_in_directory()
Rename get_all_files_in_directory() -> get_all_regular_files_in_directory(), as this name is more explicit about exactly which files will be included in the function's output.
This commit is contained in:
parent
db8dfd9f17
commit
f33772060f
|
@ -5,7 +5,7 @@ from infection_monkey.ransomware.valid_file_extensions import VALID_FILE_EXTENSI
|
||||||
from infection_monkey.utils.dir_utils import (
|
from infection_monkey.utils.dir_utils import (
|
||||||
file_extension_filter,
|
file_extension_filter,
|
||||||
filter_files,
|
filter_files,
|
||||||
get_all_files_in_directory,
|
get_all_regular_files_in_directory,
|
||||||
)
|
)
|
||||||
from infection_monkey.utils.environment import is_windows_os
|
from infection_monkey.utils.environment import is_windows_os
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class RansomewarePayload:
|
||||||
def _find_files(self):
|
def _find_files(self):
|
||||||
file_filters = [file_extension_filter(VALID_FILE_EXTENSIONS_FOR_ENCRYPTION)]
|
file_filters = [file_extension_filter(VALID_FILE_EXTENSIONS_FOR_ENCRYPTION)]
|
||||||
|
|
||||||
all_files = get_all_files_in_directory(self.target_dir)
|
all_files = get_all_regular_files_in_directory(self.target_dir)
|
||||||
return filter_files(all_files, file_filters)
|
return filter_files(all_files, file_filters)
|
||||||
|
|
||||||
def _encrypt_files(self, file_list):
|
def _encrypt_files(self, file_list):
|
||||||
|
|
|
@ -2,7 +2,7 @@ from pathlib import Path
|
||||||
from typing import Callable, List, Set
|
from typing import Callable, List, Set
|
||||||
|
|
||||||
|
|
||||||
def get_all_files_in_directory(dir_path: Path) -> List[Path]:
|
def get_all_regular_files_in_directory(dir_path: Path) -> List[Path]:
|
||||||
return [f for f in dir_path.iterdir() if f.is_file()]
|
return [f for f in dir_path.iterdir() if f.is_file()]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from infection_monkey.utils.dir_utils import (
|
from infection_monkey.utils.dir_utils import (
|
||||||
file_extension_filter,
|
file_extension_filter,
|
||||||
filter_files,
|
filter_files,
|
||||||
get_all_files_in_directory,
|
get_all_regular_files_in_directory,
|
||||||
)
|
)
|
||||||
|
|
||||||
FILES = ["file.jpg.zip", "file.xyz", "1.tar", "2.tgz"]
|
FILES = ["file.jpg.zip", "file.xyz", "1.tar", "2.tgz"]
|
||||||
|
@ -29,35 +29,35 @@ def add_files_to_dir(parent_dir):
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_files_in_directory__no_files(tmp_path, monkeypatch):
|
def test_get_all_regular_files_in_directory__no_files(tmp_path, monkeypatch):
|
||||||
add_subdirs_to_dir(tmp_path)
|
add_subdirs_to_dir(tmp_path)
|
||||||
|
|
||||||
expected_return_value = []
|
expected_return_value = []
|
||||||
assert get_all_files_in_directory(tmp_path) == expected_return_value
|
assert get_all_regular_files_in_directory(tmp_path) == expected_return_value
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_files_in_directory__has_files(tmp_path, monkeypatch):
|
def test_get_all_regular_files_in_directory__has_files(tmp_path, monkeypatch):
|
||||||
add_subdirs_to_dir(tmp_path)
|
add_subdirs_to_dir(tmp_path)
|
||||||
files = add_files_to_dir(tmp_path)
|
files = add_files_to_dir(tmp_path)
|
||||||
|
|
||||||
expected_return_value = sorted(files)
|
expected_return_value = sorted(files)
|
||||||
assert sorted(get_all_files_in_directory(tmp_path)) == expected_return_value
|
assert sorted(get_all_regular_files_in_directory(tmp_path)) == expected_return_value
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_files_in_directory__subdir_has_files(tmp_path, monkeypatch):
|
def test_get_all_regular_files_in_directory__subdir_has_files(tmp_path, monkeypatch):
|
||||||
subdirs = add_subdirs_to_dir(tmp_path)
|
subdirs = add_subdirs_to_dir(tmp_path)
|
||||||
add_files_to_dir(subdirs[0])
|
add_files_to_dir(subdirs[0])
|
||||||
|
|
||||||
files = add_files_to_dir(tmp_path)
|
files = add_files_to_dir(tmp_path)
|
||||||
|
|
||||||
expected_return_value = sorted(files)
|
expected_return_value = sorted(files)
|
||||||
assert sorted(get_all_files_in_directory(tmp_path)) == expected_return_value
|
assert sorted(get_all_regular_files_in_directory(tmp_path)) == expected_return_value
|
||||||
|
|
||||||
|
|
||||||
def test_filter_files__no_results(tmp_path):
|
def test_filter_files__no_results(tmp_path):
|
||||||
add_files_to_dir(tmp_path)
|
add_files_to_dir(tmp_path)
|
||||||
|
|
||||||
files_in_dir = get_all_files_in_directory(tmp_path)
|
files_in_dir = get_all_regular_files_in_directory(tmp_path)
|
||||||
filtered_files = filter_files(files_in_dir, [lambda _: False])
|
filtered_files = filter_files(files_in_dir, [lambda _: False])
|
||||||
|
|
||||||
assert len(filtered_files) == 0
|
assert len(filtered_files) == 0
|
||||||
|
@ -67,7 +67,7 @@ def test_filter_files__all_true(tmp_path):
|
||||||
files = add_files_to_dir(tmp_path)
|
files = add_files_to_dir(tmp_path)
|
||||||
expected_return_value = sorted(files)
|
expected_return_value = sorted(files)
|
||||||
|
|
||||||
files_in_dir = get_all_files_in_directory(tmp_path)
|
files_in_dir = get_all_regular_files_in_directory(tmp_path)
|
||||||
filtered_files = filter_files(files_in_dir, [lambda _: True])
|
filtered_files = filter_files(files_in_dir, [lambda _: True])
|
||||||
|
|
||||||
assert sorted(filtered_files) == expected_return_value
|
assert sorted(filtered_files) == expected_return_value
|
||||||
|
@ -78,7 +78,7 @@ def test_file_extension_filter(tmp_path):
|
||||||
|
|
||||||
files = add_files_to_dir(tmp_path)
|
files = add_files_to_dir(tmp_path)
|
||||||
|
|
||||||
files_in_dir = get_all_files_in_directory(tmp_path)
|
files_in_dir = get_all_regular_files_in_directory(tmp_path)
|
||||||
filtered_files = filter_files(files_in_dir, [file_extension_filter(valid_extensions)])
|
filtered_files = filter_files(files_in_dir, [file_extension_filter(valid_extensions)])
|
||||||
|
|
||||||
assert sorted(files[0:2]) == sorted(filtered_files)
|
assert sorted(files[0:2]) == sorted(filtered_files)
|
||||||
|
|
Loading…
Reference in New Issue