MCPcopy Index your code
hub / github.com/python/cpython / test_unwrap

Method test_unwrap

Lib/test/test_ssl.py:2019–2059  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2017 ssl.SSLObject(bio, bio)
2018
2019 def test_unwrap(self):
2020 client_ctx, server_ctx, hostname = testing_context()
2021 c_in = ssl.MemoryBIO()
2022 c_out = ssl.MemoryBIO()
2023 s_in = ssl.MemoryBIO()
2024 s_out = ssl.MemoryBIO()
2025 client = client_ctx.wrap_bio(c_in, c_out, server_hostname=hostname)
2026 server = server_ctx.wrap_bio(s_in, s_out, server_side=True)
2027
2028 # Loop on the handshake for a bit to get it settled
2029 for _ in range(5):
2030 try:
2031 client.do_handshake()
2032 except ssl.SSLWantReadError:
2033 pass
2034 if c_out.pending:
2035 s_in.write(c_out.read())
2036 try:
2037 server.do_handshake()
2038 except ssl.SSLWantReadError:
2039 pass
2040 if s_out.pending:
2041 c_in.write(s_out.read())
2042 # Now the handshakes should be complete (don't raise WantReadError)
2043 client.do_handshake()
2044 server.do_handshake()
2045
2046 # Now if we unwrap one side unilaterally, it should send close-notify
2047 # and raise WantReadError:
2048 with self.assertRaises(ssl.SSLWantReadError):
2049 client.unwrap()
2050
2051 # But server.unwrap() does not raise, because it reads the client's
2052 # close-notify:
2053 s_in.write(c_out.read())
2054 server.unwrap()
2055
2056 # And now that the client gets the server's close-notify, it doesn't
2057 # raise either.
2058 c_in.write(s_out.read())
2059 client.unwrap()
2060
2061class SimpleBackgroundTests(unittest.TestCase):
2062 """Tests that connect to a simple server running in the background"""

Callers

nothing calls this directly

Calls 7

testing_contextFunction · 0.85
wrap_bioMethod · 0.80
do_handshakeMethod · 0.45
writeMethod · 0.45
readMethod · 0.45
assertRaisesMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected