forked from p34709852/monkey
UT: Make monkey configs available to Island and Agent
This commit is contained in:
parent
baeee8b90a
commit
94a42a1469
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue