Merge pull request #2129 from guardicore/2004-propagation-configuration-validation
PropagationConfiguration docstring + validation
This commit is contained in:
commit
40b29ba99a
|
@ -135,7 +135,7 @@ class ExploitationConfigurationSchema(Schema):
|
|||
|
||||
|
||||
class PropagationConfigurationSchema(Schema):
|
||||
maximum_depth = fields.Int()
|
||||
maximum_depth = fields.Int(validate=validate.Range(min=0))
|
||||
network_scan = fields.Nested(NetworkScanConfigurationSchema)
|
||||
exploitation = fields.Nested(ExploitationConfigurationSchema)
|
||||
|
||||
|
|
|
@ -134,6 +134,17 @@ class ExploitationConfiguration:
|
|||
|
||||
@dataclass(frozen=True)
|
||||
class PropagationConfiguration:
|
||||
"""
|
||||
A configuration for propagation
|
||||
|
||||
Attributes:
|
||||
:param maximum_depth: Maximum number of hops allowed to spread from the machine where
|
||||
the attack started i.e. how far to propagate in the network from the
|
||||
first machine
|
||||
:param network_scan: Configuration for network scanning
|
||||
:param exploitation: Configuration for exploitation
|
||||
"""
|
||||
|
||||
maximum_depth: int
|
||||
network_scan: NetworkScanConfiguration
|
||||
exploitation: ExploitationConfiguration
|
||||
|
|
|
@ -11,14 +11,15 @@ const PROPAGATION_CONFIGURATION_SCHEMA = {
|
|||
'maximum_depth': {
|
||||
'title': 'Maximum scan depth',
|
||||
'type': 'integer',
|
||||
'minimum': 1,
|
||||
'minimum': 0,
|
||||
'default': 2,
|
||||
'description': 'Amount of hops allowed for the monkey to spread from the ' +
|
||||
'Island server. \n' +
|
||||
' \u26A0' +
|
||||
' Note that setting this value too high may result in the ' +
|
||||
'Monkey propagating too far, '+
|
||||
'if the "Local network scan" is enabled'
|
||||
'if "Local network scan" is enabled.\n' +
|
||||
'Setting this to 0 will disable all scanning and exploitation.'
|
||||
},
|
||||
'network_scan': NETWORK_SCAN_CONFIGURATION_SCHEMA
|
||||
}
|
||||
|
|
|
@ -237,6 +237,16 @@ def test_propagation_configuration():
|
|||
assert config_dict == PROPAGATION_CONFIGURATION
|
||||
|
||||
|
||||
def test_propagation_configuration__invalid_maximum_depth():
|
||||
schema = PropagationConfigurationSchema()
|
||||
|
||||
negative_maximum_depth_configuration = PROPAGATION_CONFIGURATION.copy()
|
||||
negative_maximum_depth_configuration["maximum_depth"] = -1
|
||||
|
||||
with pytest.raises(ValidationError):
|
||||
schema.load(negative_maximum_depth_configuration)
|
||||
|
||||
|
||||
def test_agent_configuration():
|
||||
config = AgentConfiguration.from_mapping(AGENT_CONFIGURATION)
|
||||
config_json = AgentConfiguration.to_json(config)
|
||||
|
|
Loading…
Reference in New Issue