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

Method test_connect_with_context

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

Source from the content-addressed store, hash-verified

2135 self.assertTrue(s.getpeercert())
2136
2137 def test_connect_with_context(self):
2138 # Same as test_connect, but with a separately created context
2139 ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
2140 ctx.check_hostname = False
2141 ctx.verify_mode = ssl.CERT_NONE
2142 with ctx.wrap_socket(socket.socket(socket.AF_INET)) as s:
2143 s.connect(self.server_addr)
2144 self.assertEqual({}, s.getpeercert())
2145 # Same with a server hostname
2146 with ctx.wrap_socket(socket.socket(socket.AF_INET),
2147 server_hostname="dummy") as s:
2148 s.connect(self.server_addr)
2149 ctx.verify_mode = ssl.CERT_REQUIRED
2150 # This should succeed because we specify the root cert
2151 ctx.load_verify_locations(SIGNING_CA)
2152 with ctx.wrap_socket(socket.socket(socket.AF_INET)) as s:
2153 s.connect(self.server_addr)
2154 cert = s.getpeercert()
2155 self.assertTrue(cert)
2156
2157 def test_connect_with_context_fail(self):
2158 # This should fail because we have no verification certs. Connection

Callers

nothing calls this directly

Calls 6

wrap_socketMethod · 0.95
socketMethod · 0.80
assertTrueMethod · 0.80
connectMethod · 0.45
assertEqualMethod · 0.45
getpeercertMethod · 0.45

Tested by

no test coverage detected