Skip to content
Myr

Stop abusing pytest-httpbin to test commonName support

Before adoption: this commit came in with the history the project adopted, so no landing records it.

pytest-httpbin<1.0 ships with a server certificate with a commonName but no subjectAltName. urllib3 2.0 will stop supporting those in the future, so we want to upgrade pytest-httpbin. Unfortunately, `test_https_warnings` was relying on this broken certificate. With this change, we use `trustme` to create a broken certificate specifically for this test, so that we can upgrade pytest-httpbin and make sure that other tests relying on httpbin TLS support will continue to work with urllib3 2.0.

authored by Quentin Pradet · committed by GitHub · parent f6c0619 · Browse files · 3 files+39 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+39 added−4 removed

  • tests:+37 added−3 removed
  • other:+2 added−1 removed

3 files+39 added−4 removed

modified:tests/conftest.py+34 added
1# -*- coding: utf-8 -*-23try:4 from http.server import HTTPServer5 from http.server import SimpleHTTPRequestHandler6except ImportError:7 from BaseHTTPServer import HTTPServer8 from SimpleHTTPServer import SimpleHTTPRequestHandler 910import ssl11import tempfile12import threading1314import pytest15from requests.compat import urljoin16import trustme171819def prepare_url(value):20 # Issue #1483: Make sure the URL always has a trailing slash
12 unmodified lines
3334@pytest.fixture35def httpbin_secure(httpbin_secure):36 return prepare_url(httpbin_secure)373839@pytest.fixture40def nosan_server(tmp_path_factory):41 tmpdir = tmp_path_factory.mktemp("certs")42 ca = trustme.CA()43 # only commonName, no subjectAltName44 server_cert = ca.issue_cert(common_name=u"localhost")45 ca_bundle = str(tmpdir / "ca.pem")46 ca.cert_pem.write_to_path(ca_bundle)4748 context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)49 server_cert.configure_cert(context)50 server = HTTPServer(("localhost", 0), SimpleHTTPRequestHandler)51 server.socket = context.wrap_socket(server.socket, server_side=True)52 server_thread = threading.Thread(target=server.serve_forever)53 server_thread.start()5455 yield "localhost", server.server_address[1], ca_bundle5657 server.shutdown()58 server_thread.join()
modified:tests/test_requests.py+3 added-3 removed
872 unmodified lines
873 def test_http_with_certificate(self, httpbin):874 r = requests.get(httpbin(), cert='.')875 assert r.status_code == 200876877 def test_https_warnings(self, httpbin_secure, httpbin_ca_bundle):877 def test_https_warnings(self, nosan_server):878 """warnings are emitted with requests.get"""879 host, port, ca_bundle = nosan_server880 if HAS_MODERN_SSL or HAS_PYOPENSSL:881 warnings_expected = ('SubjectAltNameWarning', )882 else:883 warnings_expected = ('SNIMissingWarning',
1 unmodified line
885 'SubjectAltNameWarning', )886887 with pytest.warns(None) as warning_records:888 warnings.simplefilter('always')888 requests.get(httpbin_secure('status', '200'),889 verify=httpbin_ca_bundle)889 requests.get("https://localhost:{}/".format(port), verify=ca_bundle)890891 warning_records = [item for item in warning_records892 if item.category.__name__ != 'ResourceWarning']893
1680 unmodified lines
modified:requirements-dev.txt+2 added-1 removed
1pytest>=2.8.0,<=3.10.12pytest-cov3pytest-httpbin<1.03pytest-httpbin==1.0.04pytest-mock==2.0.05httpbin==0.7.06Flask>=1.0,<2.07trustme8wheel