From 45ba743418740fc177c434569125876ab863ff5f Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 23 Jun 2021 09:01:42 -0400 Subject: [PATCH] tests: Move hash_file() into tests/utils.py --- .../ransomware/test_ransomware_payload.py | 12 +----------- monkey/tests/utils.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 11 deletions(-) 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()