forked from p15670423/monkey
Common: Add validation to AgentConfiguration construction
This commit is contained in:
parent
ea02bec0b4
commit
fc9d854c72
|
@ -26,6 +26,11 @@ class AgentConfiguration:
|
|||
payloads: List[PluginConfiguration]
|
||||
propagation: PropagationConfiguration
|
||||
|
||||
def __post_init__(self):
|
||||
# This will raise an exception if the object is invalid. Calling this in __post__init()
|
||||
# makes it impossible to construct an invalid object
|
||||
AgentConfigurationSchema().dump(self)
|
||||
|
||||
@staticmethod
|
||||
def from_dict(dict_: dict):
|
||||
config_dict = AgentConfigurationSchema().load(dict_)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
|
||||
import pytest
|
||||
from tests.common.example_agent_configuration import (
|
||||
AGENT_CONFIGURATION,
|
||||
BLOCKED_IPS,
|
||||
|
@ -169,6 +170,14 @@ def test_agent_configuration():
|
|||
assert json.loads(config_json) == AGENT_CONFIGURATION
|
||||
|
||||
|
||||
def test_incorrect_type():
|
||||
valid_config = AgentConfiguration.from_dict(AGENT_CONFIGURATION)
|
||||
with pytest.raises(Exception):
|
||||
valid_config_dict = valid_config.__dict__
|
||||
valid_config_dict["keep_tunnel_open_time"] = "not_a_float"
|
||||
AgentConfiguration(**valid_config_dict)
|
||||
|
||||
|
||||
def test_default_agent_configuration():
|
||||
config = AgentConfiguration.from_json(DEFAULT_AGENT_CONFIGURATION_JSON)
|
||||
|
||||
|
|
Loading…
Reference in New Issue