MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_unwrap

Method test_unwrap

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

Source from the content-addressed store, hash-verified

1800 ssl.SSLObject(bio, bio)
1801
1802 def test_unwrap(self):
1803 client_ctx, server_ctx, hostname = testing_context()
1804 c_in = ssl.MemoryBIO()
1805 c_out = ssl.MemoryBIO()
1806 s_in = ssl.MemoryBIO()
1807 s_out = ssl.MemoryBIO()
1808 client = client_ctx.wrap_bio(c_in, c_out, server_hostname=hostname)
1809 server = server_ctx.wrap_bio(s_in, s_out, server_side=True)
1810
1811 # Loop on the handshake for a bit to get it settled
1812 for _ in range(5):
1813 try:
1814 client.do_handshake()
1815 except ssl.SSLWantReadError:
1816 pass
1817 if c_out.pending:
1818 s_in.write(c_out.read())
1819 try:
1820 server.do_handshake()
1821 except ssl.SSLWantReadError:
1822 pass
1823 if s_out.pending:
1824 c_in.write(s_out.read())
1825 # Now the handshakes should be complete (don't raise WantReadError)
1826 client.do_handshake()
1827 server.do_handshake()
1828
1829 # Now if we unwrap one side unilaterally, it should send close-notify
1830 # and raise WantReadError:
1831 with self.assertRaises(ssl.SSLWantReadError):
1832 client.unwrap()
1833
1834 # But server.unwrap() does not raise, because it reads the client's
1835 # close-notify:
1836 s_in.write(c_out.read())
1837 server.unwrap()
1838
1839 # And now that the client gets the server's close-notify, it doesn't
1840 # raise either.
1841 c_in.write(s_out.read())
1842 client.unwrap()
1843
1844class SimpleBackgroundTests(unittest.TestCase):
1845 """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