Merge pull request #2129 from guardicore/2004-propagation-configuration-validation

PropagationConfiguration docstring + validation
This commit is contained in:
Mike Salvatore 2022-07-27 09:42:15 -04:00 committed by GitHub
commit 40b29ba99a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 3 deletions

View File

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

View File

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

View File

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

View File

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