From 94a42a1469f660c587fd8d417f0ff60eb2e22594 Mon Sep 17 00:00:00 2001
From: Mike Salvatore <mike.s.salvatore@gmail.com>
Date: Wed, 15 Dec 2021 12:59:04 -0500
Subject: [PATCH] UT: Make monkey configs available to Island and Agent

---
 monkey/tests/unit_tests/conftest.py           | 19 +++++++++++++++--
 .../unit_tests/monkey_island/cc/conftest.py   | 21 ++-----------------
 .../test_password_based_encryption.py         |  3 ---
 3 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/monkey/tests/unit_tests/conftest.py b/monkey/tests/unit_tests/conftest.py
index 3099263b0..5b83a7e69 100644
--- a/monkey/tests/unit_tests/conftest.py
+++ b/monkey/tests/unit_tests/conftest.py
@@ -1,6 +1,7 @@
-import os
+import json
 import sys
 from pathlib import Path
+from typing import Callable, Dict
 
 import pytest
 from _pytest.monkeypatch import MonkeyPatch
@@ -11,7 +12,7 @@ sys.path.insert(0, MONKEY_BASE_PATH)
 
 @pytest.fixture(scope="session")
 def data_for_tests_dir(pytestconfig):
-    return Path(os.path.join(pytestconfig.rootdir, "monkey", "tests", "data_for_tests"))
+    return Path(pytestconfig.rootdir) / "monkey" / "tests" / "data_for_tests"
 
 
 @pytest.fixture(scope="session")
@@ -39,3 +40,17 @@ def monkeypatch_session():
     monkeypatch_ = MonkeyPatch()
     yield monkeypatch_
     monkeypatch_.undo()
+
+
+@pytest.fixture
+def monkey_configs_dir(data_for_tests_dir) -> Path:
+    return data_for_tests_dir / "monkey_configs"
+
+
+@pytest.fixture
+def load_monkey_config(data_for_tests_dir) -> Callable[[str], Dict]:
+    def inner(filename: str) -> Dict:
+        config_path = data_for_tests_dir / "monkey_configs" / filename
+        return json.loads(open(config_path, "r").read())
+
+    return inner
diff --git a/monkey/tests/unit_tests/monkey_island/cc/conftest.py b/monkey/tests/unit_tests/monkey_island/cc/conftest.py
index 5777b3492..ba5a2c66e 100644
--- a/monkey/tests/unit_tests/monkey_island/cc/conftest.py
+++ b/monkey/tests/unit_tests/monkey_island/cc/conftest.py
@@ -1,38 +1,21 @@
 # Without these imports pytests can't use fixtures,
 # because they are not found
 import json
-from typing import Dict
 
 import pytest
 from tests.unit_tests.monkey_island.cc.mongomock_fixtures import *  # noqa: F401,F403,E402
-from tests.unit_tests.monkey_island.cc.server_utils.encryption.test_password_based_encryption import (  # noqa: E501
-    FLAT_PLAINTEXT_MONKEY_CONFIG_FILENAME,
-    MONKEY_CONFIGS_DIR_PATH,
-    STANDARD_PLAINTEXT_MONKEY_CONFIG_FILENAME,
-)
 
 from monkey_island.cc.server_utils.encryption import unlock_datastore_encryptor
 
 
-@pytest.fixture
-def load_monkey_config(data_for_tests_dir) -> Dict:
-    def inner(filename: str) -> Dict:
-        config_path = (
-            data_for_tests_dir / MONKEY_CONFIGS_DIR_PATH / FLAT_PLAINTEXT_MONKEY_CONFIG_FILENAME
-        )
-        return json.loads(open(config_path, "r").read())
-
-    return inner
-
-
 @pytest.fixture
 def monkey_config(load_monkey_config):
-    return load_monkey_config(STANDARD_PLAINTEXT_MONKEY_CONFIG_FILENAME)
+    return load_monkey_config("monkey_config_standard.json")
 
 
 @pytest.fixture
 def flat_monkey_config(load_monkey_config):
-    return load_monkey_config(FLAT_PLAINTEXT_MONKEY_CONFIG_FILENAME)
+    return load_monkey_config("flat_config.json")
 
 
 @pytest.fixture
diff --git a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_password_based_encryption.py b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_password_based_encryption.py
index ce0b46705..038b17ec1 100644
--- a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_password_based_encryption.py
+++ b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_password_based_encryption.py
@@ -13,9 +13,6 @@ from monkey_island.cc.server_utils.encryption import (
 # Mark all tests in this module as slow
 pytestmark = pytest.mark.slow
 
-MONKEY_CONFIGS_DIR_PATH = "monkey_configs"
-STANDARD_PLAINTEXT_MONKEY_CONFIG_FILENAME = "monkey_config_standard.json"
-FLAT_PLAINTEXT_MONKEY_CONFIG_FILENAME = "flat_config.json"
 PASSWORD = "hello123"
 INCORRECT_PASSWORD = "goodbye321"