From f9ea196b98cc3bb534adca842cc1d01162d56d1d Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 25 Feb 2021 22:14:36 +0530 Subject: [PATCH] Add unit tests for `set_server_ips_in_config()` in monkey_island/cc/services/config.py --- .../cc/services/tests/test_config.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 monkey/monkey_island/cc/services/tests/test_config.py diff --git a/monkey/monkey_island/cc/services/tests/test_config.py b/monkey/monkey_island/cc/services/tests/test_config.py new file mode 100644 index 000000000..fac88f805 --- /dev/null +++ b/monkey/monkey_island/cc/services/tests/test_config.py @@ -0,0 +1,31 @@ +import pytest + +import monkey_island.cc.services.config +from monkey_island.cc.environment import Environment +from monkey_island.cc.services.config import ConfigService + +IPS = ["0.0.0.0", "9.9.9.9"] +PORT = 9999 + + +@pytest.fixture +def config(monkeypatch): + monkeypatch.setattr("monkey_island.cc.services.config.local_ip_addresses", + lambda: IPS) + monkeypatch.setattr(Environment, "_ISLAND_PORT", PORT) + config = ConfigService.get_default_config(True) + return config + + +def test_set_server_ips_in_config_command_servers(config): + ConfigService.set_server_ips_in_config(config) + expected_config_command_servers = [f"{ip}:{PORT}" for ip in IPS] + assert config["internal"]["island_server"]["command_servers"] ==\ + expected_config_command_servers + + +def test_set_server_ips_in_config_current_server(config): + ConfigService.set_server_ips_in_config(config) + expected_config_current_server = f"{IPS[0]}:{PORT}" + assert config["internal"]["island_server"]["current_server"] ==\ + expected_config_current_server