forked from p15670423/monkey
Island: Rename add_tcp_connections to upsert_tcp_connections
This commit is contained in:
parent
3bc2e4876f
commit
0d246a0479
|
@ -104,7 +104,7 @@ class ScanEventHandler:
|
|||
tcp_connections.add(socket_address)
|
||||
|
||||
if tcp_connections:
|
||||
self._node_repository.add_tcp_connections(
|
||||
self._node_repository.upsert_tcp_connections(
|
||||
src_node.machine_id, {target_machine.id: tcp_connections}
|
||||
)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class INodeRepository(ABC):
|
|||
"""
|
||||
|
||||
@abstractmethod
|
||||
def add_tcp_connections(self, machine_id: MachineID, tcp_connections: TCPConnections):
|
||||
def upsert_tcp_connections(self, machine_id: MachineID, tcp_connections: TCPConnections):
|
||||
"""
|
||||
Add TCP connections to Node
|
||||
:param machine_id: Machine ID of the Node that made the connections
|
||||
|
|
|
@ -48,7 +48,7 @@ class MongoNodeRepository(INodeRepository):
|
|||
|
||||
return new_node
|
||||
|
||||
def add_tcp_connections(self, machine_id: MachineID, tcp_connections: TCPConnections):
|
||||
def upsert_tcp_connections(self, machine_id: MachineID, tcp_connections: TCPConnections):
|
||||
node = self._get_node_by_id(machine_id)
|
||||
|
||||
if node is None:
|
||||
|
|
|
@ -234,7 +234,7 @@ def test_handle_tcp_scan_event__no_open_ports(
|
|||
scan_event_handler._update_nodes = MagicMock()
|
||||
scan_event_handler.handle_tcp_scan_event(event)
|
||||
|
||||
assert not node_repository.add_tcp_connections.called
|
||||
assert not node_repository.upsert_tcp_connections.called
|
||||
|
||||
|
||||
def test_handle_tcp_scan_event__ports_found(
|
||||
|
@ -244,7 +244,7 @@ def test_handle_tcp_scan_event__ports_found(
|
|||
scan_event_handler._update_nodes = MagicMock()
|
||||
scan_event_handler.handle_tcp_scan_event(event)
|
||||
|
||||
call_args = node_repository.add_tcp_connections.call_args[0]
|
||||
call_args = node_repository.upsert_tcp_connections.call_args[0]
|
||||
assert call_args[0] == MACHINE_ID
|
||||
assert TARGET_MACHINE_ID in call_args[1]
|
||||
open_socket_addresses = call_args[1][TARGET_MACHINE_ID]
|
||||
|
|
|
@ -211,7 +211,7 @@ def test_reset__removal_error(error_raising_node_repository):
|
|||
|
||||
|
||||
def test_upsert_tcp_connections__empty_connections(node_repository):
|
||||
node_repository.add_tcp_connections(1, TCP_CONNECTION_PORT_22)
|
||||
node_repository.upsert_tcp_connections(1, TCP_CONNECTION_PORT_22)
|
||||
nodes = node_repository.get_nodes()
|
||||
for node in nodes:
|
||||
if node.machine_id == 1:
|
||||
|
@ -219,7 +219,7 @@ def test_upsert_tcp_connections__empty_connections(node_repository):
|
|||
|
||||
|
||||
def test_upsert_tcp_connections__upsert_new_port(node_repository):
|
||||
node_repository.add_tcp_connections(2, TCP_CONNECTION_PORT_80)
|
||||
node_repository.upsert_tcp_connections(2, TCP_CONNECTION_PORT_80)
|
||||
nodes = node_repository.get_nodes()
|
||||
modified_node = [node for node in nodes if node.machine_id == 2][0]
|
||||
assert set(modified_node.tcp_connections) == set(ALL_TCP_CONNECTIONS)
|
||||
|
@ -227,7 +227,7 @@ def test_upsert_tcp_connections__upsert_new_port(node_repository):
|
|||
|
||||
|
||||
def test_upsert_tcp_connections__port_already_present(node_repository):
|
||||
node_repository.add_tcp_connections(4, TCP_CONNECTION_PORT_80)
|
||||
node_repository.upsert_tcp_connections(4, TCP_CONNECTION_PORT_80)
|
||||
nodes = node_repository.get_nodes()
|
||||
modified_node = [node for node in nodes if node.machine_id == 4][0]
|
||||
assert set(modified_node.tcp_connections) == set(ALL_TCP_CONNECTIONS)
|
||||
|
@ -235,7 +235,7 @@ def test_upsert_tcp_connections__port_already_present(node_repository):
|
|||
|
||||
|
||||
def test_upsert_tcp_connections__node_missing(node_repository):
|
||||
node_repository.add_tcp_connections(999, TCP_CONNECTION_PORT_80)
|
||||
node_repository.upsert_tcp_connections(999, TCP_CONNECTION_PORT_80)
|
||||
nodes = node_repository.get_nodes()
|
||||
modified_node = [node for node in nodes if node.machine_id == 999][0]
|
||||
assert set(modified_node.tcp_connections) == set(TCP_CONNECTION_PORT_80)
|
||||
|
|
Loading…
Reference in New Issue