summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2017-12-20 18:24:43 (GMT)
committerGitHub <noreply@github.com>2017-12-20 18:24:43 (GMT)
commit51eb1c6b9c0b382dfd6e0428eacff0c7891a6fc3 (patch)
treec9043b4a9f959fe562a695ec35cb0718101110e9 /Lib/test/test_asyncio
parenta7a751dd7b08a5bb6cb399c1b2a6ca7b24aba51d (diff)
downloadcpython-51eb1c6b9c0b382dfd6e0428eacff0c7891a6fc3.zip
cpython-51eb1c6b9c0b382dfd6e0428eacff0c7891a6fc3.tar.gz
cpython-51eb1c6b9c0b382dfd6e0428eacff0c7891a6fc3.tar.bz2
bpo-29970: Make ssh_handshake_timeout None by default (#4939)
* Make ssh_handshake_timeout None by default. * Raise ValueError if ssl_handshake_timeout is used without ssl. * Raise ValueError if ssl_handshake_timeout is not positive.
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_base_events.py16
-rw-r--r--Lib/test/test_asyncio/test_events.py10
-rw-r--r--Lib/test/test_asyncio/test_sslproto.py16
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py17
4 files changed, 59 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index 488257b..1fc7473 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -1053,6 +1053,14 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
'A Stream Socket was expected'):
self.loop.run_until_complete(coro)
+ def test_create_server_ssl_timeout_for_plain_socket(self):
+ coro = self.loop.create_server(
+ MyProto, 'example.com', 80, ssl_handshake_timeout=1)
+ with self.assertRaisesRegex(
+ ValueError,
+ 'ssl_handshake_timeout is only meaningful with ssl'):
+ self.loop.run_until_complete(coro)
+
@unittest.skipUnless(hasattr(socket, 'SOCK_NONBLOCK'),
'no socket.SOCK_NONBLOCK (linux only)')
def test_create_server_stream_bittype(self):
@@ -1362,6 +1370,14 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
self.addCleanup(sock.close)
self.assertRaises(ValueError, self.loop.run_until_complete, coro)
+ def test_create_connection_ssl_timeout_for_plain_socket(self):
+ coro = self.loop.create_connection(
+ MyProto, 'example.com', 80, ssl_handshake_timeout=1)
+ with self.assertRaisesRegex(
+ ValueError,
+ 'ssl_handshake_timeout is only meaningful with ssl'):
+ self.loop.run_until_complete(coro)
+
def test_create_server_empty_host(self):
# if host is empty string use None instead
host = object()
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 58e94d4..aefa33b 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -852,6 +852,16 @@ class EventLoopTestsMixin:
self.test_connect_accepted_socket(server_context, client_context)
+ def test_connect_accepted_socket_ssl_timeout_for_plain_socket(self):
+ sock = socket.socket()
+ self.addCleanup(sock.close)
+ coro = self.loop.connect_accepted_socket(
+ MyProto, sock, ssl_handshake_timeout=1)
+ with self.assertRaisesRegex(
+ ValueError,
+ 'ssl_handshake_timeout is only meaningful with ssl'):
+ self.loop.run_until_complete(coro)
+
@mock.patch('asyncio.base_events.socket')
def create_server_multiple_hosts(self, family, hosts, mock_sock):
@asyncio.coroutine
diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py
index 1c42a35..a7498e8 100644
--- a/Lib/test/test_asyncio/test_sslproto.py
+++ b/Lib/test/test_asyncio/test_sslproto.py
@@ -75,6 +75,22 @@ class SslProtoHandshakeTests(test_utils.TestCase):
self.loop.run_until_complete(tasks.sleep(0.2, loop=self.loop))
self.assertTrue(transport.abort.called)
+ def test_handshake_timeout_zero(self):
+ sslcontext = test_utils.dummy_ssl_context()
+ app_proto = mock.Mock()
+ waiter = mock.Mock()
+ with self.assertRaisesRegex(ValueError, 'a positive number'):
+ sslproto.SSLProtocol(self.loop, app_proto, sslcontext, waiter,
+ ssl_handshake_timeout=0)
+
+ def test_handshake_timeout_negative(self):
+ sslcontext = test_utils.dummy_ssl_context()
+ app_proto = mock.Mock()
+ waiter = mock.Mock()
+ with self.assertRaisesRegex(ValueError, 'a positive number'):
+ sslproto.SSLProtocol(self.loop, app_proto, sslcontext, waiter,
+ ssl_handshake_timeout=-10)
+
def test_eof_received_waiter(self):
waiter = asyncio.Future(loop=self.loop)
ssl_proto = self.ssl_protocol(waiter)
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index e13cc37..097d0ef7 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -327,6 +327,14 @@ class SelectorEventLoopUnixSocketTests(test_utils.TestCase):
finally:
os.unlink(fn)
+ def test_create_unix_server_ssl_timeout_with_plain_sock(self):
+ coro = self.loop.create_unix_server(lambda: None, path='spam',
+ ssl_handshake_timeout=1)
+ with self.assertRaisesRegex(
+ ValueError,
+ 'ssl_handshake_timeout is only meaningful with ssl'):
+ self.loop.run_until_complete(coro)
+
def test_create_unix_connection_path_inetsock(self):
sock = socket.socket()
with sock:
@@ -383,6 +391,15 @@ class SelectorEventLoopUnixSocketTests(test_utils.TestCase):
self.loop.run_until_complete(coro)
+ def test_create_unix_connection_ssl_timeout_with_plain_sock(self):
+ coro = self.loop.create_unix_connection(lambda: None, path='spam',
+ ssl_handshake_timeout=1)
+ with self.assertRaisesRegex(
+ ValueError,
+ 'ssl_handshake_timeout is only meaningful with ssl'):
+ self.loop.run_until_complete(coro)
+
+
class UnixReadPipeTransportTests(test_utils.TestCase):