diff --git a/monkey/common/configuration/__init__.py b/monkey/common/configuration/__init__.py index c36144499..393bba020 100644 --- a/monkey/common/configuration/__init__.py +++ b/monkey/common/configuration/__init__.py @@ -13,4 +13,6 @@ from .agent_configuration import ( ICMPScanConfigurationSchema, TCPScanConfiguration, TCPScanConfigurationSchema, + ScanTargetConfiguration, + ScanTargetConfigurationSchema, ) diff --git a/monkey/common/configuration/agent_configuration.py b/monkey/common/configuration/agent_configuration.py index aa716a7a6..a34b93d94 100644 --- a/monkey/common/configuration/agent_configuration.py +++ b/monkey/common/configuration/agent_configuration.py @@ -96,6 +96,17 @@ class ScanTargetConfiguration: subnets: List[str] +class ScanTargetConfigurationSchema(Schema): + blocked_ips = fields.List(fields.Str()) + inaccessible_subnets = fields.List(fields.Str()) + local_network_scan = fields.Bool() + subnets = fields.List(fields.Str()) + + @post_load + def _make_scan_target_configuration(self, data, **kwargs): + return ScanTargetConfiguration(**data) + + @dataclass(frozen=True) class ICMPScanConfiguration: timeout_ms: int diff --git a/monkey/tests/unit_tests/common/test_agent_configuration.py b/monkey/tests/unit_tests/common/test_agent_configuration.py index d6c1a3a18..12697021d 100644 --- a/monkey/tests/unit_tests/common/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/test_agent_configuration.py @@ -7,6 +7,7 @@ from common.configuration import ( ExploiterConfigurationSchema, ICMPScanConfigurationSchema, PluginConfigurationSchema, + ScanTargetConfigurationSchema, TCPScanConfigurationSchema, ) @@ -99,6 +100,27 @@ def test_exploitation_configuration(): assert config_dict == exploitation_config +def test_scan_target_configuration(): + blocked_ips = ["10.0.0.1", "192.168.1.1"] + inaccessible_subnets = ["172.0.0.0/24", "172.2.2.0/24", "192.168.56.0/24"] + local_network_scan = True + subnets = ["10.0.0.2", "10.0.0.2/16"] + scan_target_config = { + "blocked_ips": blocked_ips, + "inaccessible_subnets": inaccessible_subnets, + "local_network_scan": local_network_scan, + "subnets": subnets, + } + schema = ScanTargetConfigurationSchema() + + config = schema.load(scan_target_config) + + assert config.blocked_ips == blocked_ips + assert config.inaccessible_subnets == inaccessible_subnets + assert config.local_network_scan == local_network_scan + assert config.subnets == subnets + + def test_icmp_scan_configuration_schema(): timeout_ms = 2525 schema = ICMPScanConfigurationSchema() diff --git a/vulture_allowlist.py b/vulture_allowlist.py index fcdefe8a0..0082925c6 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -190,6 +190,7 @@ _make_plugin_configuration # unused method (monkey/common/configuration/agent_c _make_custom_pba_configuration # unused method (monkey/common/configuration/agent_configuration.py:24) _make_exploiter_configuration # unused method (monkey/common/configuration/agent_configuration.py:69) _make_exploitation_options_configuration # unused method (monkey/common/configuration/agent_configuration.py:86) +_make_scan_target_configuration # unused method (monkey/common/configuration/agent_configuration.py:105) _make_icmp_scan_configuration # unused method (monkey/common/configuration/agent_configuration.py:107) _make_tcp_scan_configuration # unused method (monkey/common/configuration/agent_configuration.py:122) LINUX # unused variable (monkey/common/operating_systems.py:5)