def test_self_signed_cert(self): # start and connect to a local https server using a self-signed cert. local_server = None try: from os.path import dirname, join, realpath host = 'localhost' port = 4443 cert_file_path = join(dirname(dirname(realpath(__file__))), 'self_signed.pem') local_server = SimpleHTTPSServer(cert_file_path=cert_file_path, host=host, port=port) local_server.start() try: urlopen(_make_url(host, port=port)) except URLError as e: if e.reason and type(e.reason) is SSLError: # this is the right error. pass else: raise else: # we don't expect zero errors. self.fail("Didn't encounter expected error") finally: if local_server: local_server.stop()
def test_self_signed_cert(self): # start and connect to a local https server using a self-signed cert. local_server = None try: from os.path import dirname, join, realpath host = "localhost" port = 4443 cert_file_path = join(dirname(dirname(realpath(__file__))), "self_signed.pem") local_server = SimpleHTTPSServer(cert_file_path=cert_file_path, host=host, port=port) local_server.start() try: urlopen(_make_url(host, port=port)) except URLError as e: if e.reason and type(e.reason) is SSLError: # this is the right error. pass else: raise else: # we don't expect zero errors. self.fail("Didn't encounter expected error") finally: if local_server: local_server.stop()
def test_no_https(self): # try http; should complete without any certificate-related error. res = urlopen(_make_url(_SERVER, protocol="http")) self.assertEqual(res.getcode(), _SUCCESS_RESPONSE_CODE)
def test_valid_cert(self): # Connect to server with a valid cert signed by a CA. res = urlopen(_make_url(_SERVER)) self.assertEqual(res.getcode(), _SUCCESS_RESPONSE_CODE)
def error(*args, **kwargs): httpswithverify.urlopen("https://localhost/error")
def error(*args, **kwargs): t.append('e') httpswithverify.urlopen("https://localhost/error")
def error(*args, **kwargs): t.append('e') httpswithverify.urlopen("https://localhost/error")
def error(*args, **kwargs): httpswithverify.urlopen("https://localhost/error")
def test_no_https(self): # try http; should complete without any certificate-related error. res = urlopen(_make_url(_SERVER, protocol="http")) self.assertEqual(res.getcode(), _SUCCESS_RESPONSE_CODE)
def test_valid_cert(self): # Connect to server with a valid cert signed by a CA. res = urlopen(_make_url(_SERVER)) self.assertEqual(res.getcode(), _SUCCESS_RESPONSE_CODE)