2
from http.server import HTTPServer, SimpleHTTPRequestHandler
4
from BaseHTTPServer import HTTPServer
5
from SimpleHTTPServer import SimpleHTTPRequestHandler
12
from requests.compat import urljoin
15
def prepare_url(value):
16
# Issue #1483: Make sure the URL always has a trailing slash
17
httpbin_url = value.url.rstrip("/") + "/"
20
return urljoin(httpbin_url, "/".join(suffix))
25
@pytest.fixture(autouse=True)
26
def clean_proxy_environ(monkeypatch):
27
"""Remove proxy related environment variables for every test."""
28
proxy_vars = ("http_proxy", "https_proxy", "no_proxy", "ftp_proxy", "all_proxy")
29
for var in proxy_vars:
30
monkeypatch.delenv(var, raising=False)
31
monkeypatch.delenv(var.upper(), raising=False)
36
return prepare_url(httpbin)
40
def httpbin_secure(httpbin_secure):
41
return prepare_url(httpbin_secure)
45
def nosan_server(tmp_path_factory):
46
# delay importing until the fixture in order to make it possible
47
# to deselect the test via command-line when trustme is not available
50
tmpdir = tmp_path_factory.mktemp("certs")
52
# only commonName, no subjectAltName
53
server_cert = ca.issue_cert(common_name="localhost")
54
ca_bundle = str(tmpdir / "ca.pem")
55
ca.cert_pem.write_to_path(ca_bundle)
52
# only commonName, no subjectAltName
53
server_cert = ca.issue_cert(common_name="localhost")
54
ca_bundle = str(tmpdir / "ca.pem")
55
ca.cert_pem.write_to_path(ca_bundle)
57
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
58
server_cert.configure_cert(context)
59
server = HTTPServer(("localhost", 0), SimpleHTTPRequestHandler)
60
server.socket = context.wrap_socket(server.socket, server_side=True)
61
server_thread = threading.Thread(target=server.serve_forever)
64
yield "localhost", server.server_address[1], ca_bundle