Merge pull request #2125 from guardicore/2004-tcp-scan-configuration-validation

TCPScanConfiguration docstring + validation
This commit is contained in:
Shreya Malviya 2022-07-27 17:24:07 +05:30 committed by GitHub
commit 643896bb5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 2 deletions

View File

@ -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

View File

@ -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, ...]

View File

@ -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()