From 3b9eaefebb1b2e55b6392d5c55ac07594cc057e3 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Thu, 14 Aug 2014 20:43:55 +0100 Subject: Test banner timeout. --- tests/test_client.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'tests/test_client.py') diff --git a/tests/test_client.py b/tests/test_client.py index 7e5c80b4..1867fb78 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -27,6 +27,7 @@ import unittest import weakref import warnings import os +import time from tests.util import test_path import paramiko from paramiko.common import PY2 @@ -72,12 +73,14 @@ class SSHClientTest (unittest.TestCase): if hasattr(self, attr): getattr(self, attr).close() - def _run(self): + def _run(self, delay=0): self.socks, addr = self.sockl.accept() self.ts = paramiko.Transport(self.socks) host_key = paramiko.RSAKey.from_private_key_file(test_path('test_rsa.key')) self.ts.add_server_key(host_key) server = NullServer() + if delay: + time.sleep(delay) self.ts.start_server(self.event, server) def test_1_client(self): @@ -252,3 +255,25 @@ class SSHClientTest (unittest.TestCase): gc.collect() self.assertTrue(p() is None) + + def test_7_banner_timeout(self): + """ + verify that the SSHClient has a configurable banner timeout. + """ + # Start the thread with a 5 second wait. + threading.Thread(target=self._run, args=(5,)).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 three second banner timeout. + self.assertRaises( + paramiko.SSHException, + self.tc.connect, + self.addr, + self.port, + username='slowdive', + password='pygmalion', + banner_timeout=3 + ) -- cgit v1.2.3 From 021160d8db62b8873f7deda3f7d89750941d2704 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Thu, 14 Aug 2014 21:35:31 +0100 Subject: Use a shorter timeout in banner timeout test. --- tests/test_client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/test_client.py') diff --git a/tests/test_client.py b/tests/test_client.py index 1867fb78..48e2e9b0 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -260,14 +260,14 @@ class SSHClientTest (unittest.TestCase): """ verify that the SSHClient has a configurable banner timeout. """ - # Start the thread with a 5 second wait. - threading.Thread(target=self._run, args=(5,)).start() + # Start the thread with a 1 second wait. + threading.Thread(target=self._run, args=(1,)).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 three second banner timeout. + # Connect with a half second banner timeout. self.assertRaises( paramiko.SSHException, self.tc.connect, @@ -275,5 +275,5 @@ class SSHClientTest (unittest.TestCase): self.port, username='slowdive', password='pygmalion', - banner_timeout=3 + banner_timeout=0.5 ) -- cgit v1.2.3 From f88189835eebab72a3792f67de4aacc7fca68df6 Mon Sep 17 00:00:00 2001 From: Olle Lundberg Date: Fri, 15 Aug 2014 12:21:44 +0200 Subject: Document what is breaking in the client tests. --- tests/test_client.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/test_client.py') diff --git a/tests/test_client.py b/tests/test_client.py index 7e5c80b4..93574fc8 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -221,6 +221,8 @@ class SSHClientTest (unittest.TestCase): """ # Unclear why this is borked on Py3, but it is, and does not seem worth # pursuing at the moment. + # XXX: It's the release of the references to e.g packetizer that fails + # in py3... if not PY2: return threading.Thread(target=self._run).start() -- cgit v1.2.3