Skip to content

Commit b3a9507

Browse files
cakekoamssalvatore
authored andcommitted
Common: Add validation to AgentRegistrationData.sha256 field
1 parent fd03a5f commit b3a9507

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

monkey/common/agent_registration_data.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Optional, Sequence
44
from uuid import UUID
55

6-
from pydantic import validator
6+
from pydantic import Field, validator
77

88
from .base_models import InfectionMonkeyBaseModel
99
from .transforms import make_immutable_sequence
@@ -17,7 +17,7 @@ class AgentRegistrationData(InfectionMonkeyBaseModel):
1717
parent_id: Optional[UUID]
1818
cc_server: SocketAddress
1919
network_interfaces: Sequence[IPv4Interface]
20-
sha256: str
20+
sha256: str = Field(regex=r"^[0-9a-fA-F]{64}$")
2121

2222
_make_immutable_sequence = validator("network_interfaces", pre=True, allow_reuse=True)(
2323
make_immutable_sequence

monkey/tests/unit_tests/monkey_island/cc/models/test_agent_registration_message.py

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ def test_construct_invalid_field__type_error(key, value):
7575
("start_time", "not-a-date-time"),
7676
("network_interfaces", [1, "stuff", 3]),
7777
("cc_server", []),
78+
("sha256", "not-a-hex-string-although-it-is-of-the-correct-length-for-sha256"),
79+
("sha256", "12345678123456781234567812345678123456781234567812345678123456780"),
80+
("sha256", "12345678"),
7881
],
7982
)
8083
def test_construct_invalid_field__value_error(key, value):

0 commit comments

Comments
 (0)