def shutdown(self): self.running = False try: secure_urlopen(self.base_url, timeout=1).read() except Exception: pass self.socket.close() self.runthread.join() del self.runthread del self.base_url
def test_secure_urlopen(self): server = TestingServer() server.start() try: kwds = {"timeout": 1} # We don't trust the server's certificate, so this fails. self.assertRaises(urllib2.URLError, secure_urlopen, server.base_url, **kwds) # The certificate doesn't belong to localhost, so this fails. kwds["ca_certs"] = server.certfile self.assertRaises(urllib2.URLError, secure_urlopen, server.base_url, **kwds) # Set a valid cert for local host, trust it, we succeed. server.certfile = _filepath("certs/localhost.crt") server.keyfile = _filepath("certs/localhost.key") kwds["ca_certs"] = server.certfile self.assertEquals(secure_urlopen(server.base_url, **kwds).read(), "OK") finally: server.shutdown()