diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2017-06-07 18:06:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-07 18:06:08 -0700 |
commit | 2e22a6210c411a0c85a551b2f07afb38624a7457 (patch) | |
tree | ee02be1876742c1a75d2512d1b2af2a55ebb7112 | |
parent | 431756bf12e39c4c7ea48755fd79d8b973e6d3a3 (diff) | |
parent | 500e2641981f504a7a9a744305935360f5973222 (diff) |
Merge pull request #988 from ploxiln/auth_timeout_tests_cleanup
cleanup/simplify auth_timeout tests
-rw-r--r-- | tests/test_auth.py | 22 | ||||
-rw-r--r-- | tests/test_client.py | 16 |
2 files changed, 13 insertions, 25 deletions
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): |