mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 14:50:16 +00:00
e253eba5ed
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.
59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
try:
|
|
from http.server import HTTPServer
|
|
from http.server import SimpleHTTPRequestHandler
|
|
except ImportError:
|
|
from BaseHTTPServer import HTTPServer
|
|
from SimpleHTTPServer import SimpleHTTPRequestHandler
|
|
|
|
import ssl
|
|
import tempfile
|
|
import threading
|
|
|
|
import pytest
|
|
from requests.compat import urljoin
|
|
import trustme
|
|
|
|
|
|
def prepare_url(value):
|
|
# Issue #1483: Make sure the URL always has a trailing slash
|
|
httpbin_url = value.url.rstrip('/') + '/'
|
|
|
|
def inner(*suffix):
|
|
return urljoin(httpbin_url, '/'.join(suffix))
|
|
|
|
return inner
|
|
|
|
|
|
@pytest.fixture
|
|
def httpbin(httpbin):
|
|
return prepare_url(httpbin)
|
|
|
|
|
|
@pytest.fixture
|
|
def httpbin_secure(httpbin_secure):
|
|
return prepare_url(httpbin_secure)
|
|
|
|
|
|
@pytest.fixture
|
|
def nosan_server(tmp_path_factory):
|
|
tmpdir = tmp_path_factory.mktemp("certs")
|
|
ca = trustme.CA()
|
|
# only commonName, no subjectAltName
|
|
server_cert = ca.issue_cert(common_name=u"localhost")
|
|
ca_bundle = str(tmpdir / "ca.pem")
|
|
ca.cert_pem.write_to_path(ca_bundle)
|
|
|
|
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
|
|
server_cert.configure_cert(context)
|
|
server = HTTPServer(("localhost", 0), SimpleHTTPRequestHandler)
|
|
server.socket = context.wrap_socket(server.socket, server_side=True)
|
|
server_thread = threading.Thread(target=server.serve_forever)
|
|
server_thread.start()
|
|
|
|
yield "localhost", server.server_address[1], ca_bundle
|
|
|
|
server.shutdown()
|
|
server_thread.join()
|