Agent: Add get_machine_id()

This commit is contained in:
Mike Salvatore 2022-08-22 14:07:09 -04:00
parent 160d2d11cf
commit 09739268fa
3 changed files with 23 additions and 11 deletions

View File

@ -1,4 +1,4 @@
from uuid import UUID, uuid4
from uuid import UUID, getnode, uuid4
def get_agent_id() -> UUID:
@ -15,3 +15,8 @@ def get_agent_id() -> UUID:
get_agent_id._id = None
def get_machine_id() -> int:
"""Get an integer that uniquely defines the machine the agent is running on"""
return getnode()

View File

@ -1,10 +0,0 @@
from uuid import UUID
from infection_monkey.utils.agent_id import get_agent_id
def test_get_agent_id():
agent_id = get_agent_id()
assert isinstance(agent_id, UUID)
assert agent_id == get_agent_id()

View File

@ -0,0 +1,17 @@
from uuid import UUID
from infection_monkey.utils.ids import get_agent_id, get_machine_id
def test_get_agent_id():
agent_id = get_agent_id()
assert isinstance(agent_id, UUID)
assert agent_id == get_agent_id()
def test_get_machine_id():
machine_id = get_machine_id()
assert isinstance(machine_id, int)
assert machine_id == get_machine_id()