Island: Rename Machine.node_id -> hardware_id

"hardware_id" more accurately explains the data we want to store. It
also avoids any confusion resulting from overloading the term "node".
This commit is contained in:
Mike Salvatore 2022-08-18 12:21:54 -04:00
parent 59fd83f0a0
commit a625cc4583
2 changed files with 10 additions and 10 deletions

View File

@ -13,7 +13,7 @@ MachineID = PositiveInt
class Machine(MutableBaseModel):
id: MachineID = Field(..., allow_mutation=False)
node_id: Optional[PositiveInt]
hardware_id: Optional[PositiveInt]
network_interfaces: Sequence[IPv4Interface]
operating_system: OperatingSystems
operating_system_version: str

View File

@ -11,7 +11,7 @@ from monkey_island.cc.models import Machine
MACHINE_OBJECT_DICT = MappingProxyType(
{
"id": 1,
"node_id": uuid.getnode(),
"hardware_id": uuid.getnode(),
"network_interfaces": [IPv4Interface("10.0.0.1/24"), IPv4Interface("192.168.5.32/16")],
"operating_system": OperatingSystems.WINDOWS,
"operating_system_version": "eXtra Problems",
@ -22,7 +22,7 @@ MACHINE_OBJECT_DICT = MappingProxyType(
MACHINE_SIMPLE_DICT = MappingProxyType(
{
"id": 1,
"node_id": uuid.getnode(),
"hardware_id": uuid.getnode(),
"network_interfaces": ["10.0.0.1/24", "192.168.5.32/16"],
"operating_system": "windows",
"operating_system_version": "eXtra Problems",
@ -51,7 +51,7 @@ def test_to_dict():
"key, value",
[
("id", "not-an-int"),
("node_id", "not-an-int"),
("hardware_id", "not-an-int"),
("network_interfaces", "not-a-list"),
("operating_system", 2.1),
("operating_system", "bsd"),
@ -71,7 +71,7 @@ def test_construct_invalid_field__type_error(key, value):
"key, value",
[
("id", -1),
("node_id", 0),
("hardware_id", 0),
("network_interfaces", [1, "stuff", 3]),
("network_interfaces", ["10.0.0.1/16", 2, []]),
],
@ -98,18 +98,18 @@ def test_id_immutable():
m.id = 2
@pytest.mark.parametrize("node_id", [None, 1, 100])
def test_node_id_set_valid_value(node_id):
@pytest.mark.parametrize("hardware_id", [None, 1, 100])
def test_hardware_id_set_valid_value(hardware_id):
m = Machine(**MACHINE_OBJECT_DICT)
# Raises exception_on_failure
m.node_id = node_id
m.hardware_id = hardware_id
def test_node_id_validate_on_set():
def test_hardware_id_validate_on_set():
m = Machine(**MACHINE_OBJECT_DICT)
with pytest.raises(ValueError):
m.node_id = -50
m.hardware_id = -50
def test_network_interfaces_set_valid_value():