diff --git a/monkey/common/agent_configuration/agent_sub_configuration_schemas.py b/monkey/common/agent_configuration/agent_sub_configuration_schemas.py index 3c46cd0fe..8ea68df40 100644 --- a/monkey/common/agent_configuration/agent_sub_configuration_schemas.py +++ b/monkey/common/agent_configuration/agent_sub_configuration_schemas.py @@ -85,7 +85,7 @@ class ScanTargetConfigurationSchema(Schema): class ICMPScanConfigurationSchema(Schema): - timeout = fields.Float() + timeout = fields.Float(validate=validate.Range(min=0)) @post_load def _make_icmp_scan_configuration(self, data, **kwargs): diff --git a/monkey/common/agent_configuration/agent_sub_configurations.py b/monkey/common/agent_configuration/agent_sub_configurations.py index 4afa7db23..d0e4272eb 100644 --- a/monkey/common/agent_configuration/agent_sub_configurations.py +++ b/monkey/common/agent_configuration/agent_sub_configurations.py @@ -41,6 +41,13 @@ class ScanTargetConfiguration: @dataclass(frozen=True) class ICMPScanConfiguration: + """ + A configuration for ICMP scanning + + Attributes: + :param timeout: Maximum time in seconds to wait for a response from the target + """ + timeout: float diff --git a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py index d7e4bebd4..f1dfa43a0 100644 --- a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py @@ -126,6 +126,16 @@ def test_icmp_scan_configuration_schema(): assert config.timeout == TIMEOUT +def test_icmp_scan_configuration_schema__negative_timeout(): + schema = ICMPScanConfigurationSchema() + + negative_timeout_configuration = ICMP_CONFIGURATION.copy() + negative_timeout_configuration["timeout"] = -1 + + with pytest.raises(ValidationError): + schema.load(negative_timeout_configuration) + + def test_tcp_scan_configuration_schema(): schema = TCPScanConfigurationSchema()