diff options
author | Martijn Pieters <mj@zopatista.com> | 2023-12-20 23:09:01 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-20 15:09:01 -0800 |
commit | 1ff02385944924db7e683a607da2882462594764 (patch) | |
tree | 05a658fb019bc290359c9c3aee69116decdd8f91 /Lib/test/test_asyncio/test_sslproto.py | |
parent | a3e8afe0a3b5868440501edf579d1d4711c0fb18 (diff) | |
download | cpython-1ff02385944924db7e683a607da2882462594764.tar.gz cpython-1ff02385944924db7e683a607da2882462594764.zip |
GH-113214: Fix SSLProto exception handling in SSL-over-SSL scenarios (#113334)
When wrapped, `_SSLProtocolTransport._force_close(exc)` is called just like in the unwrapped scenario `_SelectorTransport._force_close(exc)` or `_ProactorBasePipeTransport._force_close(exc)` would be called, except here the exception needs to be passed through the `SSLProtocol._abort()` method, which didn't accept an exception object.
This commit ensures that this path works, in the same way that the uvloop implementation of SSLProto passes on the exception (on which the current implementation of SSLProto is based).
Diffstat (limited to 'Lib/test/test_asyncio/test_sslproto.py')
-rw-r--r-- | Lib/test/test_asyncio/test_sslproto.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py index 37d01533976..f5f0afeab51 100644 --- a/Lib/test/test_asyncio/test_sslproto.py +++ b/Lib/test/test_asyncio/test_sslproto.py @@ -47,6 +47,7 @@ class SslProtoHandshakeTests(test_utils.TestCase): sslobj = mock.Mock() # emulate reading decompressed data sslobj.read.side_effect = ssl.SSLWantReadError + sslobj.write.side_effect = ssl.SSLWantReadError if do_handshake is not None: sslobj.do_handshake = do_handshake ssl_proto._sslobj = sslobj @@ -120,7 +121,19 @@ class SslProtoHandshakeTests(test_utils.TestCase): test_utils.run_briefly(self.loop) ssl_proto._app_transport.close() - self.assertTrue(transport.abort.called) + self.assertTrue(transport._force_close.called) + + def test_close_during_ssl_over_ssl(self): + # gh-113214: passing exceptions from the inner wrapped SSL protocol to the + # shim transport provided by the outer SSL protocol should not raise + # attribute errors + outer = self.ssl_protocol(proto=self.ssl_protocol()) + self.connection_made(outer) + # Closing the outer app transport should not raise an exception + messages = [] + self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx)) + outer._app_transport.close() + self.assertEqual(messages, []) def test_get_extra_info_on_closed_connection(self): waiter = self.loop.create_future() |