forked from p15670423/monkey
Merge pull request #2127 from guardicore/2004-exploitation-options-configuration-validation
ExploitationOptionsConfiguration docstring + validation
This commit is contained in:
commit
e7b806c288
|
@ -115,7 +115,7 @@ class NetworkScanConfigurationSchema(Schema):
|
|||
|
||||
|
||||
class ExploitationOptionsConfigurationSchema(Schema):
|
||||
http_ports = fields.List(fields.Int())
|
||||
http_ports = fields.List(fields.Int(validate=validate.Range(min=0, max=65535)))
|
||||
|
||||
@post_load
|
||||
@freeze_lists
|
||||
|
|
|
@ -106,6 +106,13 @@ class NetworkScanConfiguration:
|
|||
|
||||
@dataclass(frozen=True)
|
||||
class ExploitationOptionsConfiguration:
|
||||
"""
|
||||
A configuration for exploitation options
|
||||
|
||||
Attributes:
|
||||
:param http_ports: HTTP ports to exploit
|
||||
"""
|
||||
|
||||
http_ports: Tuple[int, ...]
|
||||
|
||||
|
||||
|
|
|
@ -48,6 +48,8 @@ from common.agent_configuration.agent_sub_configurations import (
|
|||
PropagationConfiguration,
|
||||
)
|
||||
|
||||
INVALID_PORTS = [[-1, 1, 2], [1, 2, 99999]]
|
||||
|
||||
|
||||
def test_build_plugin_configuration():
|
||||
schema = PluginConfigurationSchema()
|
||||
|
@ -145,7 +147,7 @@ def test_tcp_scan_configuration_schema():
|
|||
assert config.ports == tuple(PORTS)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("ports", [[-1, 1, 2], [1, 2, 99999]])
|
||||
@pytest.mark.parametrize("ports", INVALID_PORTS)
|
||||
def test_tcp_scan_configuration_schema__ports_out_of_range(ports):
|
||||
schema = TCPScanConfigurationSchema()
|
||||
|
||||
|
@ -191,6 +193,16 @@ def test_exploitation_options_configuration_schema():
|
|||
assert config.http_ports == tuple(ports)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("ports", INVALID_PORTS)
|
||||
def test_exploitation_options_configuration_schema__ports_out_of_range(ports):
|
||||
schema = ExploitationOptionsConfigurationSchema()
|
||||
|
||||
invalid_ports_configuration = {"http_ports": ports}
|
||||
|
||||
with pytest.raises(ValidationError):
|
||||
schema.load(invalid_ports_configuration)
|
||||
|
||||
|
||||
def test_exploiter_configuration_schema():
|
||||
name = "bond"
|
||||
options = {"gun": "Walther PPK", "car": "Aston Martin DB5"}
|
||||
|
|
Loading…
Reference in New Issue