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

Method test_connect_with_context

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

Source from the content-addressed store, hash-verified

1918 self.assertTrue(s.getpeercert())
1919
1920 def test_connect_with_context(self):
1921 # Same as test_connect, but with a separately created context
1922 ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
1923 ctx.check_hostname = False
1924 ctx.verify_mode = ssl.CERT_NONE
1925 with ctx.wrap_socket(socket.socket(socket.AF_INET)) as s:
1926 s.connect(self.server_addr)
1927 self.assertEqual({}, s.getpeercert())
1928 # Same with a server hostname
1929 with ctx.wrap_socket(socket.socket(socket.AF_INET),
1930 server_hostname="dummy") as s:
1931 s.connect(self.server_addr)
1932 ctx.verify_mode = ssl.CERT_REQUIRED
1933 # This should succeed because we specify the root cert
1934 ctx.load_verify_locations(SIGNING_CA)
1935 with ctx.wrap_socket(socket.socket(socket.AF_INET)) as s:
1936 s.connect(self.server_addr)
1937 cert = s.getpeercert()
1938 self.assertTrue(cert)
1939
1940 def test_connect_with_context_fail(self):
1941 # This should fail because we have no verification certs. Connection

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected