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

Method test_check_hostname_idn

Lib/test/test_ssl.py:3413–3491  ·  view source on GitHub ↗
(self, warnings_filters=True)

Source from the content-addressed store, hash-verified

3411 self.assertTrue(cipher[:2], ('ECDHE', 'ECDSA'))
3412
3413 def test_check_hostname_idn(self, warnings_filters=True):
3414 if support.verbose:
3415 sys.stdout.write("\n")
3416
3417 server_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
3418 server_context.load_cert_chain(IDNSANSFILE)
3419
3420 context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
3421 context.verify_mode = ssl.CERT_REQUIRED
3422 context.check_hostname = True
3423 context.load_verify_locations(SIGNING_CA)
3424
3425 # correct hostname should verify, when specified in several
3426 # different ways
3427 idn_hostnames = [
3428 ('könig.idn.pythontest.net',
3429 'xn--knig-5qa.idn.pythontest.net'),
3430 ('xn--knig-5qa.idn.pythontest.net',
3431 'xn--knig-5qa.idn.pythontest.net'),
3432 (b'xn--knig-5qa.idn.pythontest.net',
3433 'xn--knig-5qa.idn.pythontest.net'),
3434
3435 ('königsgäßchen.idna2003.pythontest.net',
3436 'xn--knigsgsschen-lcb0w.idna2003.pythontest.net'),
3437 ('xn--knigsgsschen-lcb0w.idna2003.pythontest.net',
3438 'xn--knigsgsschen-lcb0w.idna2003.pythontest.net'),
3439 (b'xn--knigsgsschen-lcb0w.idna2003.pythontest.net',
3440 'xn--knigsgsschen-lcb0w.idna2003.pythontest.net'),
3441
3442 # ('königsgäßchen.idna2008.pythontest.net',
3443 # 'xn--knigsgchen-b4a3dun.idna2008.pythontest.net'),
3444 ('xn--knigsgchen-b4a3dun.idna2008.pythontest.net',
3445 'xn--knigsgchen-b4a3dun.idna2008.pythontest.net'),
3446 (b'xn--knigsgchen-b4a3dun.idna2008.pythontest.net',
3447 'xn--knigsgchen-b4a3dun.idna2008.pythontest.net'),
3448
3449 ]
3450 for server_hostname, expected_hostname in idn_hostnames:
3451 server = ThreadedEchoServer(context=server_context, chatty=True)
3452 with server:
3453 with context.wrap_socket(socket.socket(),
3454 server_hostname=server_hostname) as s:
3455 self.assertEqual(s.server_hostname, expected_hostname)
3456 s.connect((HOST, server.port))
3457 cert = s.getpeercert()
3458 self.assertEqual(s.server_hostname, expected_hostname)
3459 self.assertTrue(cert, "Can't get peer certificate.")
3460
3461 # incorrect hostname should raise an exception
3462 server = ThreadedEchoServer(context=server_context, chatty=True)
3463 with server:
3464 with context.wrap_socket(socket.socket(),
3465 server_hostname="python.example.org") as s:
3466 with self.assertRaises(ssl.CertificateError):
3467 s.connect((HOST, server.port))
3468 with (
3469 ThreadedEchoServer(context=server_context, chatty=True) as server,
3470 (

Callers

nothing calls this directly

Calls 10

wrap_socketMethod · 0.95
nullcontextClass · 0.90
ThreadedEchoServerClass · 0.85
socketMethod · 0.80
assertTrueMethod · 0.80
writeMethod · 0.45
assertEqualMethod · 0.45
connectMethod · 0.45
getpeercertMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected