mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
bpo-44011: Revert "New asyncio ssl implementation (GH-17975)" (GH-25848)
This reverts commit 5fb06edbbb and all
subsequent dependent commits.
This commit is contained in:
parent
39494285e1
commit
7719953b30
12 changed files with 524 additions and 2477 deletions
|
|
@ -1437,51 +1437,44 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
|
|||
self.loop._make_ssl_transport.side_effect = mock_make_ssl_transport
|
||||
ANY = mock.ANY
|
||||
handshake_timeout = object()
|
||||
shutdown_timeout = object()
|
||||
# First try the default server_hostname.
|
||||
self.loop._make_ssl_transport.reset_mock()
|
||||
coro = self.loop.create_connection(
|
||||
MyProto, 'python.org', 80, ssl=True,
|
||||
ssl_handshake_timeout=handshake_timeout,
|
||||
ssl_shutdown_timeout=shutdown_timeout)
|
||||
ssl_handshake_timeout=handshake_timeout)
|
||||
transport, _ = self.loop.run_until_complete(coro)
|
||||
transport.close()
|
||||
self.loop._make_ssl_transport.assert_called_with(
|
||||
ANY, ANY, ANY, ANY,
|
||||
server_side=False,
|
||||
server_hostname='python.org',
|
||||
ssl_handshake_timeout=handshake_timeout,
|
||||
ssl_shutdown_timeout=shutdown_timeout)
|
||||
ssl_handshake_timeout=handshake_timeout)
|
||||
# Next try an explicit server_hostname.
|
||||
self.loop._make_ssl_transport.reset_mock()
|
||||
coro = self.loop.create_connection(
|
||||
MyProto, 'python.org', 80, ssl=True,
|
||||
server_hostname='perl.com',
|
||||
ssl_handshake_timeout=handshake_timeout,
|
||||
ssl_shutdown_timeout=shutdown_timeout)
|
||||
ssl_handshake_timeout=handshake_timeout)
|
||||
transport, _ = self.loop.run_until_complete(coro)
|
||||
transport.close()
|
||||
self.loop._make_ssl_transport.assert_called_with(
|
||||
ANY, ANY, ANY, ANY,
|
||||
server_side=False,
|
||||
server_hostname='perl.com',
|
||||
ssl_handshake_timeout=handshake_timeout,
|
||||
ssl_shutdown_timeout=shutdown_timeout)
|
||||
ssl_handshake_timeout=handshake_timeout)
|
||||
# Finally try an explicit empty server_hostname.
|
||||
self.loop._make_ssl_transport.reset_mock()
|
||||
coro = self.loop.create_connection(
|
||||
MyProto, 'python.org', 80, ssl=True,
|
||||
server_hostname='',
|
||||
ssl_handshake_timeout=handshake_timeout,
|
||||
ssl_shutdown_timeout=shutdown_timeout)
|
||||
ssl_handshake_timeout=handshake_timeout)
|
||||
transport, _ = self.loop.run_until_complete(coro)
|
||||
transport.close()
|
||||
self.loop._make_ssl_transport.assert_called_with(
|
||||
ANY, ANY, ANY, ANY,
|
||||
server_side=False,
|
||||
server_hostname='',
|
||||
ssl_handshake_timeout=handshake_timeout,
|
||||
ssl_shutdown_timeout=shutdown_timeout)
|
||||
ssl_handshake_timeout=handshake_timeout)
|
||||
|
||||
def test_create_connection_no_ssl_server_hostname_errors(self):
|
||||
# When not using ssl, server_hostname must be None.
|
||||
|
|
@ -1888,7 +1881,7 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
|
|||
constants.ACCEPT_RETRY_DELAY,
|
||||
# self.loop._start_serving
|
||||
mock.ANY,
|
||||
MyProto, sock, None, None, mock.ANY, mock.ANY, mock.ANY)
|
||||
MyProto, sock, None, None, mock.ANY, mock.ANY)
|
||||
|
||||
def test_call_coroutine(self):
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
|
|
|
|||
|
|
@ -70,6 +70,44 @@ class BaseSelectorEventLoopTests(test_utils.TestCase):
|
|||
|
||||
close_transport(transport)
|
||||
|
||||
@unittest.skipIf(ssl is None, 'No ssl module')
|
||||
def test_make_ssl_transport(self):
|
||||
m = mock.Mock()
|
||||
self.loop._add_reader = mock.Mock()
|
||||
self.loop._add_reader._is_coroutine = False
|
||||
self.loop._add_writer = mock.Mock()
|
||||
self.loop._remove_reader = mock.Mock()
|
||||
self.loop._remove_writer = mock.Mock()
|
||||
waiter = self.loop.create_future()
|
||||
with test_utils.disable_logger():
|
||||
transport = self.loop._make_ssl_transport(
|
||||
m, asyncio.Protocol(), m, waiter)
|
||||
|
||||
with self.assertRaisesRegex(RuntimeError,
|
||||
r'SSL transport.*not.*initialized'):
|
||||
transport.is_reading()
|
||||
|
||||
# execute the handshake while the logger is disabled
|
||||
# to ignore SSL handshake failure
|
||||
test_utils.run_briefly(self.loop)
|
||||
|
||||
self.assertTrue(transport.is_reading())
|
||||
transport.pause_reading()
|
||||
transport.pause_reading()
|
||||
self.assertFalse(transport.is_reading())
|
||||
transport.resume_reading()
|
||||
transport.resume_reading()
|
||||
self.assertTrue(transport.is_reading())
|
||||
|
||||
# Sanity check
|
||||
class_name = transport.__class__.__name__
|
||||
self.assertIn("ssl", class_name.lower())
|
||||
self.assertIn("transport", class_name.lower())
|
||||
|
||||
transport.close()
|
||||
# execute pending callbacks to close the socket transport
|
||||
test_utils.run_briefly(self.loop)
|
||||
|
||||
@mock.patch('asyncio.selector_events.ssl', None)
|
||||
@mock.patch('asyncio.sslproto.ssl', None)
|
||||
def test_make_ssl_transport_without_ssl_error(self):
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -15,6 +15,7 @@ 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
|
||||
|
||||
|
|
@ -43,13 +44,16 @@ class SslProtoHandshakeTests(test_utils.TestCase):
|
|||
|
||||
def connection_made(self, ssl_proto, *, do_handshake=None):
|
||||
transport = mock.Mock()
|
||||
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)
|
||||
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)
|
||||
return transport
|
||||
|
||||
def test_handshake_timeout_zero(self):
|
||||
|
|
@ -71,10 +75,7 @@ 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,
|
||||
do_handshake=mock.Mock(side_effect=ssl.SSLWantReadError)
|
||||
)
|
||||
self.connection_made(ssl_proto)
|
||||
ssl_proto.eof_received()
|
||||
test_utils.run_briefly(self.loop)
|
||||
self.assertIsInstance(waiter.exception(), ConnectionResetError)
|
||||
|
|
@ -99,10 +100,7 @@ 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,
|
||||
do_handshake=mock.Mock(side_effect=ssl.SSLWantReadError)
|
||||
)
|
||||
self.connection_made(ssl_proto)
|
||||
ssl_proto.connection_lost(ConnectionAbortedError)
|
||||
test_utils.run_briefly(self.loop)
|
||||
self.assertIsInstance(waiter.exception(), ConnectionAbortedError)
|
||||
|
|
@ -112,10 +110,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
|
|||
waiter = self.loop.create_future()
|
||||
ssl_proto = self.ssl_protocol(waiter=waiter)
|
||||
|
||||
transport = self.connection_made(
|
||||
ssl_proto,
|
||||
do_handshake=mock.Mock(side_effect=ssl.SSLWantReadError)
|
||||
)
|
||||
transport = self.connection_made(ssl_proto)
|
||||
test_utils.run_briefly(self.loop)
|
||||
|
||||
ssl_proto._app_transport.close()
|
||||
|
|
@ -148,7 +143,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
|
|||
transp.close()
|
||||
|
||||
# should not raise
|
||||
self.assertIsNone(ssl_proto.buffer_updated(5))
|
||||
self.assertIsNone(ssl_proto.data_received(b'data'))
|
||||
|
||||
def test_write_after_closing(self):
|
||||
ssl_proto = self.ssl_protocol()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue