From 4fc07cb5f603e04ebaaf58ce72b66834c7eda452 Mon Sep 17 00:00:00 2001 From: Aaron John Date: Sun, 14 Apr 2024 18:10:46 +0000 Subject: [PATCH 1/2] close serial connection when bad password raises error --- lib/jnpr/junos/transport/tty.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/jnpr/junos/transport/tty.py b/lib/jnpr/junos/transport/tty.py index b356ee61e..9fce52f0a 100644 --- a/lib/jnpr/junos/transport/tty.py +++ b/lib/jnpr/junos/transport/tty.py @@ -207,6 +207,7 @@ def _ev_bad_passwd(): self.write("\n") self._badpasswd += 1 if self._badpasswd == 2: + self._tty_close() # raise RuntimeError("Bad username/password") raise EzErrors.ConnectAuthError(self, "Bad username/password") # return through and try again ... could have been From c428e0b08822887405b9a145dea5793fd3f2703d Mon Sep 17 00:00:00 2001 From: Aaron John Date: Sun, 14 Apr 2024 18:15:05 +0000 Subject: [PATCH 2/2] Updated test case --- tests/unit/transport/test_tty.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/transport/test_tty.py b/tests/unit/transport/test_tty.py index 87f1c2b51..520556e55 100644 --- a/tests/unit/transport/test_tty.py +++ b/tests/unit/transport/test_tty.py @@ -29,6 +29,7 @@ def test_login_bad_password_ConnectAuthError(self): self.terminal.read_prompt = MagicMock() self.terminal.read_prompt.return_value = (None, "badpasswd") self.terminal.write = MagicMock() + self.terminal._tty_close = MagicMock() self.assertRaises(EzErrors.ConnectAuthError, self.terminal._login_state_machine) @patch("jnpr.junos.transport.tty.sleep")