diff --git a/src/primaite/simulator/system/services/terminal/terminal.py b/src/primaite/simulator/system/services/terminal/terminal.py index 0ebae491..4be2c501 100644 --- a/src/primaite/simulator/system/services/terminal/terminal.py +++ b/src/primaite/simulator/system/services/terminal/terminal.py @@ -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 diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_terminal.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_terminal.py index cdd0ebb3..9286fa49 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_terminal.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_terminal.py @@ -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