From acade4ce88b55ef9a8bccf2435c548ca9df56d70 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 12 Mar 2019 04:32:57 +0000 Subject: [PATCH] ssh: fix issue #271 regression due to refactor, add test. --- mitogen/ssh.py | 8 ++++---- tests/ssh_test.py | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mitogen/ssh.py b/mitogen/ssh.py index 059dec7a..2ba83ed4 100644 --- a/mitogen/ssh.py +++ b/mitogen/ssh.py @@ -83,8 +83,11 @@ HOSTKEY_FAIL_PATTERN = re.compile( ) # [user@host: ] permission denied +# issue #271: work around conflict with user shell reporting 'permission +# denied' e.g. during chdir($HOME) by only matching it at the start of the +# line. PERMDENIED_PATTERN = re.compile( - b('(?:[^@]+@[^:]+: )?' # Absent in OpenSSH <7.5 + b('^(?:[^@]+@[^:]+: )?' # Absent in OpenSSH <7.5 'Permission denied'), re.I ) @@ -122,9 +125,6 @@ class SetupProtocol(mitogen.parent.RegexProtocol): self.stream.conn._fail_connection(HostKeyError(hostkey_failed_msg)) def _on_permission_denied(self, line, match): - # issue #271: work around conflict with user shell reporting - # 'permission denied' e.g. during chdir($HOME) by only matching it at - # the start of the line. if self.stream.conn.options.password is not None and \ self.password_sent: self.stream.conn._fail_connection( diff --git a/tests/ssh_test.py b/tests/ssh_test.py index 6ac7d8bf..1dbbe787 100644 --- a/tests/ssh_test.py +++ b/tests/ssh_test.py @@ -58,6 +58,14 @@ class SshTest(testlib.DockerMixin, testlib.TestCase): expect = "%s: debug1: Reading configuration data" % (context.name,) self.assertTrue(expect in s) + def test_bash_permission_denied(self): + # issue #271: only match Permission Denied at start of line. + context = self.docker_ssh( + username='mitogen__permdenied', + password='permdenied_password', + ssh_debug_level=3, + ) + def test_stream_name(self): context = self.docker_ssh( username='mitogen__has_sudo',