diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2022-11-04 17:53:44 -0400 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2022-11-04 17:58:06 -0400 |
commit | 3d4e999e240729567663df8a6cddebc68e2983ff (patch) | |
tree | 478d06bebaa0e0b2f0cdbf732115fb7becb10667 | |
parent | 4e7f7e8033b7ca4b2805beb33a1164881adaf80c (diff) |
Write basic test re #2125, including kwarg default value tweak
-rw-r--r-- | paramiko/client.py | 4 | ||||
-rw-r--r-- | tests/test_client.py | 34 |
2 files changed, 37 insertions, 1 deletions
diff --git a/paramiko/client.py b/paramiko/client.py index a866f8b6..b1c60db8 100644 --- a/paramiko/client.py +++ b/paramiko/client.py @@ -237,7 +237,7 @@ class SSHClient(ClosingContextManager): gss_trust_dns=True, passphrase=None, disabled_algorithms=None, - transport_factory=Transport, + transport_factory=None, ): """ Connect to an SSH server and authenticate to it. The server's host key @@ -376,6 +376,8 @@ class SSHClient(ClosingContextManager): if len(errors) == len(to_try): raise NoValidConnectionsError(errors) + if transport_factory is None: + transport_factory = Transport t = self._transport = transport_factory( sock, gss_kex=gss_kex, diff --git a/tests/test_client.py b/tests/test_client.py index fd54140b..3eaad4fb 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -739,6 +739,40 @@ class SSHClientTest(ClientTest): call_arg = Transport.call_args[1]["disabled_algorithms"] assert call_arg == {"keys": ["ssh-dss"]} + @patch("paramiko.client.Transport") + def test_transport_factory_defaults_to_Transport(self, Transport): + sock, kex, creds, algos = Mock(), Mock(), Mock(), Mock() + SSHClient().connect( + "host", + sock=sock, + password="no", + gss_kex=kex, + gss_deleg_creds=creds, + disabled_algorithms=algos, + ) + Transport.assert_called_once_with( + sock, gss_kex=kex, gss_deleg_creds=creds, disabled_algorithms=algos + ) + + @patch("paramiko.client.Transport") + def test_transport_factory_may_be_specified(self, Transport): + factory = Mock() + sock, kex, creds, algos = Mock(), Mock(), Mock(), Mock() + SSHClient().connect( + "host", + sock=sock, + password="no", + gss_kex=kex, + gss_deleg_creds=creds, + disabled_algorithms=algos, + transport_factory=factory, + ) + factory.assert_called_once_with( + sock, gss_kex=kex, gss_deleg_creds=creds, disabled_algorithms=algos + ) + # Safety check + assert not Transport.called + class PasswordPassphraseTests(ClientTest): # TODO: most of these could reasonably be set up to use mocks/assertions |