def test_ssl_verification(self): certfile = os.path.join(HERE, 'keycert.pem') server = self.make_https_server(certfile) url = 'https://localhost:%d/' % server.port req = Request(url) self.index.ssl_verifier = HTTPSHandler(certfile) response = self.index.send_request(req) self.assertEqual(response.code, 200)
def test_download(self): digest = '913093474942c5a564c011f232868517' # for testsrc/README.txt certfile = os.path.join(HERE, 'keycert.pem') server = self.make_https_server(certfile) url = 'https://localhost:%d/README.txt' % server.port fd, fn = tempfile.mkstemp() os.close(fd) self.addCleanup(os.remove, fn) with open(os.path.join(HERE, 'testsrc', 'README.txt'), 'rb') as f: data = f.read() self.index.ssl_verifier = HTTPSHandler(certfile) self.index.download_file(url, fn) # no digest with open(fn, 'rb') as f: self.assertEqual(data, f.read()) self.index.download_file(url, fn, digest) with open(fn, 'rb') as f: self.assertEqual(data, f.read()) reporthook = lambda *args: None self.index.download_file(url, fn, ('md5', digest), reporthook) with open(fn, 'rb') as f: self.assertEqual(data, f.read()) # bad digest self.assertRaises(DistlibException, self.index.download_file, url, fn, digest[:-1] + '8')