def test_server_hostname(self): https_pool = HTTPSConnectionPool('127.0.0.1', self.port, cert_reqs='CERT_REQUIRED', ca_certs=DEFAULT_CA, server_hostname='localhost') self.addCleanup(https_pool.close) conn = https_pool._new_conn() https_pool._start_conn(conn, connect_timeout=None) # Assert the wrapping socket is using the passed-through SNI name. # pyopenssl doesn't let you pull the server_hostname back off the # socket, so only add this assertion if the attribute is there (i.e. # the python ssl module). # XXX This is highly-specific to SyncBackend # See https://github.com/python-trio/urllib3/pull/54#discussion_r241683895 # for potential solutions sock = conn._sock._sock if hasattr(sock, 'server_hostname'): self.assertEqual(sock.server_hostname, 'localhost')