def test_invalid_url_type(self): try: self.client.open('htp://example.org') except HTTPClientError as e: assert_re(e.args[0], r'No response .* "htp://example.*": unknown url type') else: assert False, 'expected HTTPClientError'
def test_unknown_host(self): try: self.client.open('http://thishostshouldnotexist000136really42.org') except HTTPClientError as e: assert_re(e.args[0], r'No response .* "http://thishost.*": .*') else: assert False, 'expected HTTPClientError'
def test_no_connect(self): try: self.client.open('http://localhost:53871') except HTTPClientError as e: assert_re(e.args[0], r'No response .* "http://localhost.*": Connection refused') else: assert False, 'expected HTTPClientError'
def test_invalid_url(self): try: self.client.open('this is not a url') except HTTPClientError as e: assert_re(e.args[0], r'URL not correct "this is not.*": unknown url type') else: assert False, 'expected HTTPClientError'
def test_https_untrusted_root(self): if not supports_ssl_default_context: raise pytest.skip("old python versions require ssl_ca_certs") self.client = HTTPClient('https://untrusted-root.badssl.com/') try: self.client.open('https://untrusted-root.badssl.com/') except HTTPClientError as e: assert_re(e.args[0], r'Could not verify connection to URL')
def test_no_connect(self): try: self.client.open('http://localhost:53871') except HTTPClientError as e: assert_re( e.args[0], r'No response .* "http://localhost.*": Connection refused') else: assert False, 'expected HTTPClientError'
def test_internal_error_response(self): try: with mock_httpd(TESTSERVER_ADDRESS, [({'path': '/'}, {'status': '500', 'body': b''})]): self.client.open(TESTSERVER_URL + '/') except HTTPClientError as e: assert_re(e.args[0], r'HTTP Error ".*": 500') else: assert False, 'expected HTTPClientError'
def test_https_untrusted_root(self): if not supports_ssl_default_context: # old python versions require ssl_ca_certs raise SkipTest() self.client = HTTPClient('https://untrusted-root.badssl.com/') try: self.client.open('https://untrusted-root.badssl.com/') except HTTPClientError as e: assert_re(e.args[0], r'Could not verify connection to URL')
def test_https_invalid_cert(self): # load 'wrong' root cert with TempFile() as tmp: with open(tmp, 'wb') as f: f.write(GOOGLE_ROOT_CERT) self.client = HTTPClient('https://untrusted-root.badssl.com/', ssl_ca_certs=tmp) try: self.client.open('https://untrusted-root.badssl.com/') except HTTPClientError as e: assert_re(e.args[0], r'Could not verify connection to URL')
def test_https_invalid_cert(self): # load 'wrong' root cert with TempFile() as tmp: with open(tmp, 'wb') as f: f.write(GOOGLE_ROOT_CERT) self.client = HTTPClient( 'https://untrusted-root.badssl.com/', ssl_ca_certs=tmp) try: self.client.open('https://untrusted-root.badssl.com/') except HTTPClientError as e: assert_re(e.args[0], r'Could not verify connection to URL')
def test_https_invalid_cert(self): try: import ssl; ssl except ImportError: raise SkipTest() with TempFile() as tmp: self.client = HTTPClient('https://www.google.com/', ssl_ca_certs=tmp) try: self.client.open('https://www.google.com/') except HTTPClientError as e: assert_re(e.args[0], r'Could not verify connection to URL')
def test_internal_error_hide_exception_url(self): try: with mock_httpd(TESTSERVER_ADDRESS, [({ 'path': '/' }, { 'status': '500', 'body': b'' })]): HTTPClient(hide_exception_url=True).open(TESTSERVER_URL + '/') except HTTPClientError as e: assert_re(e.args[0], r'HTTP Error: 500') else: assert False, 'expected HTTPClientError'
def test_https_invalid_cert(self): try: import ssl ssl except ImportError: raise SkipTest() with TempFile() as tmp: self.client = HTTPClient('https://www.google.com/', ssl_ca_certs=tmp) try: self.client.open('https://www.google.com/') except HTTPClientError as e: assert_re(e.args[0], r'Could not verify connection to URL')
def test_internal_error_hide_error_details(self): try: with mock_httpd(TESTSERVER_ADDRESS, [({ 'path': '/' }, { 'status': '500', 'body': b'' })]): HTTPClient(hide_error_details=True).open(TESTSERVER_URL + '/') except HTTPClientError as e: assert_re(e.args[0], r'HTTP Error \(see logs for URL and reason\).') else: assert False, 'expected HTTPClientError'