From ea01666ad545f4229ed9c45eb83760d352065c6d Mon Sep 17 00:00:00 2001 From: Tim Savage Date: Fri, 23 Dec 2016 10:19:35 +1100 Subject: Added a test to check that the auth_timeout argument is passed through and applied. --- tests/test_client.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/test_client.py') diff --git a/tests/test_client.py b/tests/test_client.py index 32d9ac60..2949d242 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -60,6 +60,9 @@ class NullServer (paramiko.ServerInterface): def check_auth_password(self, username, password): if (username == 'slowdive') and (password == 'pygmalion'): return paramiko.AUTH_SUCCESSFUL + if (username == 'slowdive') and (password == 'unresponsive-server'): + time.sleep(5) + return paramiko.AUTH_SUCCESSFUL return paramiko.AUTH_FAILED def check_auth_publickey(self, username, key): @@ -380,6 +383,24 @@ class SSHClientTest (unittest.TestCase): ) self._test_connection(**kwargs) + def test_9_auth_timeout(self): + """ + verify that the SSHClient has a configurable auth timeout + """ + threading.Thread(target=self._run).start() + host_key = paramiko.RSAKey.from_private_key_file(test_path('test_rsa.key')) + public_host_key = paramiko.RSAKey(data=host_key.asbytes()) + + self.tc = paramiko.SSHClient() + self.tc.get_host_keys().add('[%s]:%d' % (self.addr, self.port), 'ssh-rsa', public_host_key) + # Connect with a half second auth timeout + kwargs = dict(self.connect_kwargs, password='unresponsive-server', auth_timeout=0.5) + self.assertRaises( + paramiko.AuthenticationException, + self.tc.connect, + **kwargs + ) + def test_update_environment(self): """ Verify that environment variables can be set by the client. -- cgit v1.2.3 From 978b652cc4385f7706c49f3391bf2d91e93d4b18 Mon Sep 17 00:00:00 2001 From: Pierce Lopez Date: Fri, 2 Jun 2017 03:18:00 -0400 Subject: re-enable client cleanup test for python3 --- tests/test_client.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'tests/test_client.py') diff --git a/tests/test_client.py b/tests/test_client.py index 9c5761d6..f2f2ea45 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -280,13 +280,10 @@ class SSHClientTest (unittest.TestCase): verify that when an SSHClient is collected, its transport (and the transport's packetizer) is closed. """ - # Unclear why this is borked on Py3, but it is, and does not seem worth - # pursuing at the moment. Skipped on PyPy because it fails on travis - # for unknown reasons, works fine locally. - # XXX: It's the release of the references to e.g packetizer that fails - # in py3... - if not PY2 or platform.python_implementation() == "PyPy": + # Skipped on PyPy because it fails on travis for unknown reasons + if platform.python_implementation() == "PyPy": return + threading.Thread(target=self._run).start() self.tc = paramiko.SSHClient() @@ -304,8 +301,8 @@ class SSHClientTest (unittest.TestCase): del self.tc # force a collection to see whether the SSHClient object is deallocated - # correctly. 2 GCs are needed to make sure it's really collected on - # PyPy + # 2 GCs are needed on PyPy, time is needed for Python 3 + time.sleep(0.3) gc.collect() gc.collect() -- cgit v1.2.3 From 500e2641981f504a7a9a744305935360f5973222 Mon Sep 17 00:00:00 2001 From: Pierce Lopez Date: Tue, 6 Jun 2017 18:13:30 -0400 Subject: cleanup/simplify auth_timeout tests --- tests/test_auth.py | 22 ++++++++-------------- tests/test_client.py | 16 +++++----------- 2 files changed, 13 insertions(+), 25 deletions(-) (limited to 'tests/test_client.py') diff --git a/tests/test_auth.py b/tests/test_auth.py index 58b2f44f..e78397c6 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -243,18 +243,12 @@ class AuthTest (unittest.TestCase): verify that authentication times out if server takes to long to respond (or never responds). """ - auth_timeout = self.tc.auth_timeout - self.tc.auth_timeout = 2 # Reduce to 2 seconds to speed up test - + self.tc.auth_timeout = 1 # 1 second, to speed up test + self.start_server() + self.tc.connect() try: - self.start_server() - self.tc.connect() - try: - remain = self.tc.auth_password('unresponsive-server', 'hello') - except: - etype, evalue, etb = sys.exc_info() - self.assertTrue(issubclass(etype, AuthenticationException)) - self.assertTrue('Authentication timeout' in str(evalue)) - finally: - # Restore value - self.tc.auth_timeout = auth_timeout + remain = self.tc.auth_password('unresponsive-server', 'hello') + except: + etype, evalue, etb = sys.exc_info() + self.assertTrue(issubclass(etype, AuthenticationException)) + self.assertTrue('Authentication timeout' in str(evalue)) diff --git a/tests/test_client.py b/tests/test_client.py index aa3ff59b..ad0561f2 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -36,7 +36,7 @@ from tests.util import test_path import paramiko from paramiko.common import PY2 -from paramiko.ssh_exception import SSHException +from paramiko.ssh_exception import SSHException, AuthenticationException FINGERPRINTS = { @@ -391,18 +391,12 @@ class SSHClientTest (unittest.TestCase): """ verify that the SSHClient has a configurable auth timeout """ - threading.Thread(target=self._run).start() - host_key = paramiko.RSAKey.from_private_key_file(test_path('test_rsa.key')) - public_host_key = paramiko.RSAKey(data=host_key.asbytes()) - - self.tc = paramiko.SSHClient() - self.tc.get_host_keys().add('[%s]:%d' % (self.addr, self.port), 'ssh-rsa', public_host_key) # Connect with a half second auth timeout - kwargs = dict(self.connect_kwargs, password='unresponsive-server', auth_timeout=0.5) self.assertRaises( - paramiko.AuthenticationException, - self.tc.connect, - **kwargs + AuthenticationException, + self._test_connection, + password='unresponsive-server', + auth_timeout=0.5, ) def test_update_environment(self): -- cgit v1.2.3