diff options
author | Tim Savage <tim.savage@westpacdatabank.com.au> | 2016-12-23 09:34:35 +1100 |
---|---|---|
committer | Tim Savage <tim.savage@westpacdatabank.com.au> | 2016-12-23 09:34:35 +1100 |
commit | 1b62fb782346069aa905fb4f9602a43d9362a547 (patch) | |
tree | 451f21119dc8b04eeb4d76533a2b2a6b7f21ae44 /tests/test_auth.py | |
parent | ff5dd4823b3c7ed976a62842af6cefcf330a7496 (diff) |
Added test for authentication timeout from a non-responsive server
Diffstat (limited to 'tests/test_auth.py')
-rw-r--r-- | tests/test_auth.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/test_auth.py b/tests/test_auth.py index 23517790..5c0bd264 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -23,6 +23,7 @@ Some unit tests for authenticating over a Transport. import sys import threading import unittest +from time import sleep from paramiko import Transport, ServerInterface, RSAKey, DSSKey, \ BadAuthenticationType, InteractiveQuery, \ @@ -73,6 +74,9 @@ class NullServer (ServerInterface): return AUTH_SUCCESSFUL if username == 'bad-server': raise Exception("Ack!") + if username == 'unresponsive-server': + sleep(5) + return AUTH_SUCCESSFUL return AUTH_FAILED def check_auth_publickey(self, username, key): @@ -232,3 +236,24 @@ class AuthTest (unittest.TestCase): except: etype, evalue, etb = sys.exc_info() self.assertTrue(issubclass(etype, AuthenticationException)) + + def test_9_auth_non_responsive(self): + """ + 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 + + 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.assertIn('Authentication timeout', str(evalue)) + finally: + # Restore value + self.tc.auth_timeout = auth_timeout |