From 02dcee8bfceee04f3d37267c79909d4a9465b96c Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Sun, 19 Jun 2022 23:35:35 -0700 Subject: [PATCH] UT: Modify tests to pass with config flattening changes --- .../monkey_island/cc/services/test_config.py | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py b/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py index 108659ddf..b70a6bd3b 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py @@ -92,32 +92,14 @@ def test_format_config_for_agent__propagation(): flat_monkey_config = ConfigService.format_flat_config_for_agent() assert "propagation" in flat_monkey_config - assert "targets" in flat_monkey_config["propagation"] assert "network_scan" in flat_monkey_config["propagation"] - assert "exploiters" in flat_monkey_config["propagation"] - - -def test_format_config_for_agent__propagation_targets(): - expected_targets = { - "blocked_ips": ["192.168.1.1", "192.168.1.100"], - "inaccessible_subnets": ["10.0.0.0/24", "10.0.10.0/24"], - "local_network_scan": True, - "subnet_scan_list": ["192.168.1.50", "192.168.56.0/24", "10.0.33.0/30"], - } - - flat_monkey_config = ConfigService.format_flat_config_for_agent() - - assert flat_monkey_config["propagation"]["targets"] == expected_targets - assert "blocked_ips" not in flat_monkey_config - assert "inaccessible_subnets" not in flat_monkey_config - assert "local_network_scan" not in flat_monkey_config - assert "subnet_scan_list" not in flat_monkey_config + assert "exploitation" in flat_monkey_config["propagation"] def test_format_config_for_agent__network_scan(): expected_network_scan_config = { "tcp": { - "timeout_ms": 3000, + "timeout": 3000, "ports": [ 22, 80, @@ -135,7 +117,13 @@ def test_format_config_for_agent__network_scan(): ], }, "icmp": { - "timeout_ms": 1000, + "timeout": 1000, + }, + "targets": { + "blocked_ips": ["192.168.1.1", "192.168.1.100"], + "inaccessible_subnets": ["10.0.0.0/24", "10.0.10.0/24"], + "local_network_scan": True, + "subnets": ["192.168.1.50", "192.168.56.0/24", "10.0.33.0/30"], }, "fingerprinters": [ {"name": "elastic", "options": {}}, @@ -160,36 +148,53 @@ def test_format_config_for_agent__network_scan(): assert "finger_classes" not in flat_monkey_config +def test_format_config_for_agent__propagation_network_scan_targets(): + expected_targets = { + "blocked_ips": ["192.168.1.1", "192.168.1.100"], + "inaccessible_subnets": ["10.0.0.0/24", "10.0.10.0/24"], + "local_network_scan": True, + "subnets": ["192.168.1.50", "192.168.56.0/24", "10.0.33.0/30"], + } + + flat_monkey_config = ConfigService.format_flat_config_for_agent() + + assert flat_monkey_config["propagation"]["network_scan"]["targets"] == expected_targets + assert "blocked_ips" not in flat_monkey_config + assert "inaccessible_subnets" not in flat_monkey_config + assert "local_network_scan" not in flat_monkey_config + assert "subnet_scan_list" not in flat_monkey_config + + def test_format_config_for_agent__exploiters(): expected_exploiters_config = { "options": { "http_ports": [80, 443, 7001, 8008, 8080, 9200], }, "brute_force": [ - {"name": "MSSQLExploiter", "supported_os": ["windows"], "options": {}}, - {"name": "PowerShellExploiter", "supported_os": ["windows"], "options": {}}, - {"name": "SSHExploiter", "supported_os": ["linux"], "options": {}}, + {"name": "MSSQLExploiter", "supported_os": ["WINDOWS"], "options": {}}, + {"name": "PowerShellExploiter", "supported_os": ["WINDOWS"], "options": {}}, + {"name": "SSHExploiter", "supported_os": ["LINUX"], "options": {}}, { "name": "SmbExploiter", - "supported_os": ["windows"], + "supported_os": ["WINDOWS"], "options": {"smb_download_timeout": 30}, }, { "name": "WmiExploiter", - "supported_os": ["windows"], + "supported_os": ["WINDOWS"], "options": {"smb_download_timeout": 30}, }, ], "vulnerability": [ - {"name": "HadoopExploiter", "supported_os": ["linux", "windows"], "options": {}}, - {"name": "Log4ShellExploiter", "supported_os": ["linux", "windows"], "options": {}}, - {"name": "ZerologonExploiter", "supported_os": ["windows"], "options": {}}, + {"name": "HadoopExploiter", "supported_os": ["LINUX", "WINDOWS"], "options": {}}, + {"name": "Log4ShellExploiter", "supported_os": ["LINUX", "WINDOWS"], "options": {}}, + {"name": "ZerologonExploiter", "supported_os": ["WINDOWS"], "options": {}}, ], } flat_monkey_config = ConfigService.format_flat_config_for_agent() assert "propagation" in flat_monkey_config - assert "exploiters" in flat_monkey_config["propagation"] + assert "exploitation" in flat_monkey_config["propagation"] - assert flat_monkey_config["propagation"]["exploiters"] == expected_exploiters_config + assert flat_monkey_config["propagation"]["exploitation"] == expected_exploiters_config assert "exploiter_classes" not in flat_monkey_config