#2706 - Additional assert on new test and a guard clause on LocalTerminalConnection.execute() to check that the Terminal service is running before sending a command

This commit is contained in:
Charlie Crane
2024-08-06 19:14:53 +01:00
parent d05fd00594
commit 6d6f21a20a
2 changed files with 6 additions and 1 deletions

View File

@@ -84,8 +84,11 @@ class LocalTerminalConnection(TerminalClientConnection):
ip_address: str = "Local Connection"
def execute(self, command: Any) -> RequestResponse:
def execute(self, command: Any) -> Optional[RequestResponse]:
"""Execute a given command on local Terminal."""
if self.parent_terminal.operating_state != ServiceOperatingState.RUNNING:
self.parent_terminal.sys_log.warning("Cannot process command as system not running")
return None
if not self.is_active:
self.parent_terminal.sys_log.warning("Connection inactive, cannot execute")
return None

View File

@@ -376,3 +376,5 @@ def test_terminal_rejects_commands_if_disconnect(basic_network):
assert remote_connection.execute(["software_manager", "application", "install", "RansomwareScript"]) is False
assert not computer_b.software_manager.software.get("RansomwareScript")
assert remote_connection.is_active is False