forked from p15670423/monkey
Merge pull request #2125 from guardicore/2004-tcp-scan-configuration-validation
TCPScanConfiguration docstring + validation
This commit is contained in:
commit
643896bb5b
|
@ -93,8 +93,8 @@ class ICMPScanConfigurationSchema(Schema):
|
|||
|
||||
|
||||
class TCPScanConfigurationSchema(Schema):
|
||||
timeout = fields.Float()
|
||||
ports = fields.List(fields.Int())
|
||||
timeout = fields.Float(validate=validate.Range(min=0))
|
||||
ports = fields.List(fields.Int(validate=validate.Range(min=0, max=65535)))
|
||||
|
||||
@post_load
|
||||
@freeze_lists
|
||||
|
|
|
@ -74,6 +74,14 @@ class ICMPScanConfiguration:
|
|||
|
||||
@dataclass(frozen=True)
|
||||
class TCPScanConfiguration:
|
||||
"""
|
||||
A configuration for TCP scanning
|
||||
|
||||
Attributes:
|
||||
:param timeout: Maximum time in seconds to wait for a response from the target
|
||||
:param ports: Ports to scan
|
||||
"""
|
||||
|
||||
timeout: float
|
||||
ports: Tuple[int, ...]
|
||||
|
||||
|
|
|
@ -145,6 +145,27 @@ def test_tcp_scan_configuration_schema():
|
|||
assert config.ports == tuple(PORTS)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("ports", [[-1, 1, 2], [1, 2, 99999]])
|
||||
def test_tcp_scan_configuration_schema__ports_out_of_range(ports):
|
||||
schema = TCPScanConfigurationSchema()
|
||||
|
||||
invalid_ports_configuration = TCP_SCAN_CONFIGURATION.copy()
|
||||
invalid_ports_configuration["ports"] = ports
|
||||
|
||||
with pytest.raises(ValidationError):
|
||||
schema.load(invalid_ports_configuration)
|
||||
|
||||
|
||||
def test_tcp_scan_configuration_schema__negative_timeout():
|
||||
schema = TCPScanConfigurationSchema()
|
||||
|
||||
negative_timeout_configuration = TCP_SCAN_CONFIGURATION.copy()
|
||||
negative_timeout_configuration["timeout"] = -1
|
||||
|
||||
with pytest.raises(ValidationError):
|
||||
schema.load(negative_timeout_configuration)
|
||||
|
||||
|
||||
def test_network_scan_configuration():
|
||||
schema = NetworkScanConfigurationSchema()
|
||||
|
||||
|
|
Loading…
Reference in New Issue