diff --git a/monkey/tests/unit_tests/infection_monkey/ransomware/test_ransomware_payload.py b/monkey/tests/unit_tests/infection_monkey/ransomware/test_ransomware_payload.py index 263de0dd3..df62af6ac 100644 --- a/monkey/tests/unit_tests/infection_monkey/ransomware/test_ransomware_payload.py +++ b/monkey/tests/unit_tests/infection_monkey/ransomware/test_ransomware_payload.py @@ -1,10 +1,9 @@ -import hashlib import os import shutil from pathlib import Path import pytest -from tests.utils import is_user_admin +from tests.utils import hash_file, is_user_admin from infection_monkey.ransomware.ransomware_payload import EXTENSION, RansomewarePayload @@ -33,15 +32,6 @@ TEST_KEYBOARD_TXT_ENCRYPTED_SHA256 = ( ) -def hash_file(filepath: Path): - sha256 = hashlib.sha256() - with open(filepath, "rb") as f: - for block in iter(lambda: f.read(65536), b""): - sha256.update(block) - - return sha256.hexdigest() - - def with_extension(filename): return f"{filename}{EXTENSION}" diff --git a/monkey/tests/utils.py b/monkey/tests/utils.py index 1e55e9bc3..2be032aad 100644 --- a/monkey/tests/utils.py +++ b/monkey/tests/utils.py @@ -1,5 +1,7 @@ import ctypes +import hashlib import os +from pathlib import Path def is_user_admin(): @@ -7,3 +9,12 @@ def is_user_admin(): return os.getuid() == 0 return ctypes.windll.shell32.IsUserAnAdmin() + + +def hash_file(filepath: Path): + sha256 = hashlib.sha256() + with open(filepath, "rb") as f: + for block in iter(lambda: f.read(65536), b""): + sha256.update(block) + + return sha256.hexdigest()