summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_sslproto.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-01-14 15:56:20 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-01-14 15:56:20 (GMT)
commit177e9f0855ca398bf208a7466ed288e2ae22f6d5 (patch)
tree27c994b28ebad69a451db7937c7fed06e37ff37a /Lib/test/test_asyncio/test_sslproto.py
parentf651a604075c2dc9a2d7f3d3bd74da374ff8a696 (diff)
downloadcpython-177e9f0855ca398bf208a7466ed288e2ae22f6d5.zip
cpython-177e9f0855ca398bf208a7466ed288e2ae22f6d5.tar.gz
cpython-177e9f0855ca398bf208a7466ed288e2ae22f6d5.tar.bz2
Issue #23197, asyncio: On SSL handshake failure, check if the waiter is
cancelled before setting its exception. * Add unit tests for this case. * Cleanup also sslproto.py
Diffstat (limited to 'Lib/test/test_asyncio/test_sslproto.py')
-rw-r--r--Lib/test/test_asyncio/test_sslproto.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py
new file mode 100644
index 0000000..053fefe
--- /dev/null
+++ b/Lib/test/test_asyncio/test_sslproto.py
@@ -0,0 +1,45 @@
+"""Tests for asyncio/sslproto.py."""
+
+import unittest
+from unittest import mock
+
+import asyncio
+from asyncio import sslproto
+from asyncio import test_utils
+
+
+class SslProtoHandshakeTests(test_utils.TestCase):
+
+ def setUp(self):
+ self.loop = asyncio.new_event_loop()
+ self.set_event_loop(self.loop)
+
+ def test_cancel_handshake(self):
+ # Python issue #23197: cancelling an handshake must not raise an
+ # exception or log an error, even if the handshake failed
+ sslcontext = test_utils.dummy_ssl_context()
+ app_proto = asyncio.Protocol()
+ waiter = asyncio.Future(loop=self.loop)
+ ssl_proto = sslproto.SSLProtocol(self.loop, app_proto, sslcontext,
+ waiter)
+ handshake_fut = asyncio.Future(loop=self.loop)
+
+ def do_handshake(callback):
+ exc = Exception()
+ callback(exc)
+ handshake_fut.set_result(None)
+ return []
+
+ waiter.cancel()
+ transport = mock.Mock()
+ sslpipe = mock.Mock()
+ sslpipe.do_handshake.side_effect = do_handshake
+ with mock.patch('asyncio.sslproto._SSLPipe', return_value=sslpipe):
+ ssl_proto.connection_made(transport)
+
+ with test_utils.disable_logger():
+ self.loop.run_until_complete(handshake_fut)
+
+
+if __name__ == '__main__':
+ unittest.main()