aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_asyncio/test_sslproto.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2021-05-03 00:34:15 +0300
committerGitHub <noreply@github.com>2021-05-03 00:34:15 +0300
commit5fb06edbbb769561e245d0fe13002bab50e2ae60 (patch)
treea6341e32a1140447b2d37a3a47fedb9d5043c75d /Lib/test/test_asyncio/test_sslproto.py
parentc96cc089f60d2bf7e003c27413c3239ee9de2990 (diff)
downloadcpython-5fb06edbbb769561e245d0fe13002bab50e2ae60.tar.gz
cpython-5fb06edbbb769561e245d0fe13002bab50e2ae60.zip
bpo-44011: New asyncio ssl implementation (#17975)
Diffstat (limited to 'Lib/test/test_asyncio/test_sslproto.py')
-rw-r--r--Lib/test/test_asyncio/test_sslproto.py35
1 files changed, 20 insertions, 15 deletions
diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py
index e87863eb712..79a81bd8c39 100644
--- a/Lib/test/test_asyncio/test_sslproto.py
+++ b/Lib/test/test_asyncio/test_sslproto.py
@@ -15,7 +15,6 @@ import asyncio
from asyncio import log
from asyncio import protocols
from asyncio import sslproto
-from test import support
from test.test_asyncio import utils as test_utils
from test.test_asyncio import functional as func_tests
@@ -44,16 +43,13 @@ class SslProtoHandshakeTests(test_utils.TestCase):
def connection_made(self, ssl_proto, *, do_handshake=None):
transport = mock.Mock()
- sslpipe = mock.Mock()
- sslpipe.shutdown.return_value = b''
- if do_handshake:
- sslpipe.do_handshake.side_effect = do_handshake
- else:
- def mock_handshake(callback):
- return []
- sslpipe.do_handshake.side_effect = mock_handshake
- with mock.patch('asyncio.sslproto._SSLPipe', return_value=sslpipe):
- ssl_proto.connection_made(transport)
+ sslobj = mock.Mock()
+ # emulate reading decompressed data
+ sslobj.read.side_effect = ssl.SSLWantReadError
+ if do_handshake is not None:
+ sslobj.do_handshake = do_handshake
+ ssl_proto._sslobj = sslobj
+ ssl_proto.connection_made(transport)
return transport
def test_handshake_timeout_zero(self):
@@ -75,7 +71,10 @@ class SslProtoHandshakeTests(test_utils.TestCase):
def test_eof_received_waiter(self):
waiter = self.loop.create_future()
ssl_proto = self.ssl_protocol(waiter=waiter)
- self.connection_made(ssl_proto)
+ self.connection_made(
+ ssl_proto,
+ do_handshake=mock.Mock(side_effect=ssl.SSLWantReadError)
+ )
ssl_proto.eof_received()
test_utils.run_briefly(self.loop)
self.assertIsInstance(waiter.exception(), ConnectionResetError)
@@ -100,7 +99,10 @@ class SslProtoHandshakeTests(test_utils.TestCase):
# yield from waiter hang if lost_connection was called.
waiter = self.loop.create_future()
ssl_proto = self.ssl_protocol(waiter=waiter)
- self.connection_made(ssl_proto)
+ self.connection_made(
+ ssl_proto,
+ do_handshake=mock.Mock(side_effect=ssl.SSLWantReadError)
+ )
ssl_proto.connection_lost(ConnectionAbortedError)
test_utils.run_briefly(self.loop)
self.assertIsInstance(waiter.exception(), ConnectionAbortedError)
@@ -110,7 +112,10 @@ class SslProtoHandshakeTests(test_utils.TestCase):
waiter = self.loop.create_future()
ssl_proto = self.ssl_protocol(waiter=waiter)
- transport = self.connection_made(ssl_proto)
+ transport = self.connection_made(
+ ssl_proto,
+ do_handshake=mock.Mock(side_effect=ssl.SSLWantReadError)
+ )
test_utils.run_briefly(self.loop)
ssl_proto._app_transport.close()
@@ -143,7 +148,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
transp.close()
# should not raise
- self.assertIsNone(ssl_proto.data_received(b'data'))
+ self.assertIsNone(ssl_proto.buffer_updated(5))
def test_write_after_closing(self):
ssl_proto = self.ssl_protocol()