test_events.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:annotated-py-asyncio 作者: hhstore 项目源码 文件源码
def test_create_server_ssl_match_failed(self):
        proto = MyProto(loop=self.loop)
        server, host, port = self._make_ssl_server(
            lambda: proto, SIGNED_CERTFILE)

        sslcontext_client = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
        sslcontext_client.options |= ssl.OP_NO_SSLv2
        sslcontext_client.verify_mode = ssl.CERT_REQUIRED
        sslcontext_client.load_verify_locations(
            cafile=SIGNING_CA)
        if hasattr(sslcontext_client, 'check_hostname'):
            sslcontext_client.check_hostname = True

        # incorrect server_hostname
        f_c = self.loop.create_connection(MyProto, host, port,
                                          ssl=sslcontext_client)
        with mock.patch.object(self.loop, 'call_exception_handler'):
            with test_utils.disable_logger():
                with self.assertRaisesRegex(
                        ssl.CertificateError,
                        "hostname '127.0.0.1' doesn't match 'localhost'"):
                    self.loop.run_until_complete(f_c)

        # close connection
        proto.transport.close()
        server.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号