forked from p15670423/monkey
agent: Add is_not_shortcut_filter()
Adds a filter that can be used with filter_files() to return only files that are not Windows shortcuts.
This commit is contained in:
parent
4eaa568479
commit
41bf137ee4
|
@ -23,3 +23,7 @@ def file_extension_filter(file_extensions: Set):
|
||||||
|
|
||||||
def is_not_symlink_filter(f: Path):
|
def is_not_symlink_filter(f: Path):
|
||||||
return not f.is_symlink()
|
return not f.is_symlink()
|
||||||
|
|
||||||
|
|
||||||
|
def is_not_shortcut_filter(f: Path):
|
||||||
|
return f.suffix != ".lnk"
|
||||||
|
|
|
@ -7,10 +7,12 @@ from infection_monkey.utils.dir_utils import (
|
||||||
file_extension_filter,
|
file_extension_filter,
|
||||||
filter_files,
|
filter_files,
|
||||||
get_all_regular_files_in_directory,
|
get_all_regular_files_in_directory,
|
||||||
|
is_not_shortcut_filter,
|
||||||
is_not_symlink_filter,
|
is_not_symlink_filter,
|
||||||
)
|
)
|
||||||
|
|
||||||
FILES = ["file.jpg.zip", "file.xyz", "1.tar", "2.tgz", "2.png", "2.mpg"]
|
SHORTCUT = "shortcut.lnk"
|
||||||
|
FILES = ["file.jpg.zip", "file.xyz", "1.tar", "2.tgz", "2.png", "2.mpg", SHORTCUT]
|
||||||
SUBDIRS = ["subdir1", "subdir2"]
|
SUBDIRS = ["subdir1", "subdir2"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -113,3 +115,13 @@ def test_is_not_symlink_filter(tmp_path):
|
||||||
assert link_path in files_in_dir
|
assert link_path in files_in_dir
|
||||||
assert len(filtered_files) == len(FILES)
|
assert len(filtered_files) == len(FILES)
|
||||||
assert link_path not in filtered_files
|
assert link_path not in filtered_files
|
||||||
|
|
||||||
|
|
||||||
|
def test_is_not_shortcut_filter(tmp_path):
|
||||||
|
add_files_to_dir(tmp_path)
|
||||||
|
|
||||||
|
files_in_dir = get_all_regular_files_in_directory(tmp_path)
|
||||||
|
filtered_files = filter_files(files_in_dir, [is_not_shortcut_filter])
|
||||||
|
|
||||||
|
assert len(filtered_files) == len(FILES) - 1
|
||||||
|
assert SHORTCUT not in [f.name for f in filtered_files]
|
||||||
|
|
Loading…
Reference in New Issue