Skip to content

Commit

Permalink
Adjust tests to temporary failures with CPython 3.13.0a5 (#3371)
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-v committed Mar 28, 2024
1 parent 2df2003 commit 84b0c47
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ pytest==8.0.2
pytest-timeout==2.1.0
pyOpenSSL==24.0.0
idna==3.4
trustme==1.1.0
# As of v1.1.0, child CA certificates generated by trustme fail
# verification by CPython 3.13.
# https://github.com/python-trio/trustme/pull/642
trustme @ git+https://github.com/python-trio/trustme@b3a767f336e20600f30c9ff78385a58352ff6ee3
cryptography==42.0.4
backports.zoneinfo==0.2.1;python_version<"3.9"
towncrier==23.6.0
Expand Down
39 changes: 39 additions & 0 deletions test/with_dummyserver/test_proxy_poolmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import shutil
import socket
import ssl
import sys
import tempfile
from test import LONG_TIMEOUT, SHORT_TIMEOUT, resolvesLocalhostFQDN, withPyOpenSSL
from test.conftest import ServerConfig
Expand Down Expand Up @@ -42,6 +43,11 @@

from .. import TARPIT_HOST, requires_network

_broken_on_python313a5 = pytest.mark.xfail(
sys.version_info == (3, 13, 0, "alpha", 5),
reason="https://github.com/python/cpython/issues/116764",
)


def assert_is_verified(pm: ProxyManager, *, proxy: bool, target: bool) -> None:
pool = list(pm.pools._container.values())[-1] # retrieve last pool entry
Expand Down Expand Up @@ -77,6 +83,7 @@ def teardown_class(cls) -> None:
super().teardown_class()
shutil.rmtree(cls.certs_dir)

@_broken_on_python313a5
def test_basic_proxy(self) -> None:
with proxy_from_url(self.proxy_url, ca_certs=DEFAULT_CA) as http:
r = http.request("GET", f"{self.http_url}/")
Expand All @@ -85,6 +92,7 @@ def test_basic_proxy(self) -> None:
r = http.request("GET", f"{self.https_url}/")
assert r.status == 200

@_broken_on_python313a5
def test_https_proxy(self) -> None:
with proxy_from_url(self.https_proxy_url, ca_certs=DEFAULT_CA) as https:
r = https.request("GET", f"{self.https_url}/")
Expand All @@ -93,6 +101,7 @@ def test_https_proxy(self) -> None:
r = https.request("GET", f"{self.http_url}/")
assert r.status == 200

@_broken_on_python313a5
def test_is_verified_http_proxy_to_http_target(self) -> None:
with proxy_from_url(self.proxy_url, ca_certs=DEFAULT_CA) as http:
r = http.request("GET", f"{self.http_url}/")
Expand All @@ -105,6 +114,7 @@ def test_is_verified_http_proxy_to_https_target(self) -> None:
assert r.status == 200
assert_is_verified(http, proxy=False, target=True)

@_broken_on_python313a5
def test_is_verified_https_proxy_to_http_target(self) -> None:
with proxy_from_url(self.https_proxy_url, ca_certs=DEFAULT_CA) as https:
r = https.request("GET", f"{self.http_url}/")
Expand All @@ -117,6 +127,7 @@ def test_is_verified_https_proxy_to_https_target(self) -> None:
assert r.status == 200
assert_is_verified(https, proxy=True, target=True)

@_broken_on_python313a5
def test_http_and_https_kwarg_ca_cert_data_proxy(self) -> None:
with open(DEFAULT_CA) as pem_file:
pem_file_data = pem_file.read()
Expand All @@ -127,6 +138,7 @@ def test_http_and_https_kwarg_ca_cert_data_proxy(self) -> None:
r = https.request("GET", f"{self.http_url}/")
assert r.status == 200

@_broken_on_python313a5
def test_https_proxy_with_proxy_ssl_context(self) -> None:
proxy_ssl_context = create_urllib3_context()
proxy_ssl_context.load_verify_locations(DEFAULT_CA)
Expand All @@ -142,6 +154,7 @@ def test_https_proxy_with_proxy_ssl_context(self) -> None:
assert r.status == 200

@withPyOpenSSL
@_broken_on_python313a5
def test_https_proxy_pyopenssl_not_supported(self) -> None:
with proxy_from_url(self.https_proxy_url, ca_certs=DEFAULT_CA) as https:
r = https.request("GET", f"{self.http_url}/")
Expand All @@ -152,6 +165,7 @@ def test_https_proxy_pyopenssl_not_supported(self) -> None:
):
https.request("GET", f"{self.https_url}/")

@_broken_on_python313a5
def test_https_proxy_forwarding_for_https(self) -> None:
with proxy_from_url(
self.https_proxy_url,
Expand All @@ -164,6 +178,7 @@ def test_https_proxy_forwarding_for_https(self) -> None:
r = https.request("GET", f"{self.https_url}/")
assert r.status == 200

@_broken_on_python313a5
def test_nagle_proxy(self) -> None:
"""Test that proxy connections do not have TCP_NODELAY turned on"""
with ProxyManager(self.proxy_url) as http:
Expand Down Expand Up @@ -202,6 +217,7 @@ def test_proxy_conn_fail_from_dns(
e.value.reason.original_error, urllib3.exceptions.NameResolutionError
)

@_broken_on_python313a5
def test_oldapi(self) -> None:
with ProxyManager(
connection_from_url(self.proxy_url), ca_certs=DEFAULT_CA # type: ignore[arg-type]
Expand Down Expand Up @@ -258,6 +274,7 @@ def test_proxy_verified(self) -> None:
https_fail_pool.request("GET", "/", retries=0)
assert isinstance(e.value.reason, SSLError)

@_broken_on_python313a5
def test_redirect(self) -> None:
with proxy_from_url(self.proxy_url) as http:
r = http.request(
Expand All @@ -278,6 +295,7 @@ def test_redirect(self) -> None:
assert r.status == 200
assert r.data == b"Dummy server!"

@_broken_on_python313a5
def test_cross_host_redirect(self) -> None:
with proxy_from_url(self.proxy_url) as http:
cross_host_location = f"{self.http_url_alt}/echo?a=b"
Expand All @@ -299,6 +317,7 @@ def test_cross_host_redirect(self) -> None:
assert r._pool is not None
assert r._pool.host != self.http_host_alt

@_broken_on_python313a5
def test_cross_protocol_redirect(self) -> None:
with proxy_from_url(self.proxy_url, ca_certs=DEFAULT_CA) as http:
cross_protocol_location = f"{self.https_url}/echo?a=b"
Expand All @@ -320,6 +339,7 @@ def test_cross_protocol_redirect(self) -> None:
assert r._pool is not None
assert r._pool.host == self.https_host

@_broken_on_python313a5
def test_headers(self) -> None:
with proxy_from_url(
self.proxy_url,
Expand Down Expand Up @@ -395,6 +415,7 @@ def test_headers(self) -> None:
returned_headers.get("Host") == f"{self.https_host}:{self.https_port}"
)

@_broken_on_python313a5
def test_https_headers(self) -> None:
with proxy_from_url(
self.https_proxy_url,
Expand Down Expand Up @@ -427,6 +448,7 @@ def test_https_headers(self) -> None:
returned_headers.get("Host") == f"{self.https_host}:{self.https_port}"
)

@_broken_on_python313a5
def test_https_headers_forwarding_for_https(self) -> None:
with proxy_from_url(
self.https_proxy_url,
Expand All @@ -443,6 +465,7 @@ def test_https_headers_forwarding_for_https(self) -> None:
returned_headers.get("Host") == f"{self.https_host}:{self.https_port}"
)

@_broken_on_python313a5
def test_headerdict(self) -> None:
default_headers = HTTPHeaderDict(a="b")
proxy_headers = HTTPHeaderDict()
Expand Down Expand Up @@ -500,6 +523,10 @@ def test_proxy_pooling_ext(self) -> None:
assert sc3 == sc4

@requires_network()
@pytest.mark.xfail(
sys.version_info == (3, 13, 0, "alpha", 5) and sys.platform == "win32",
reason="https://github.com/python/cpython/issues/116764",
)
@pytest.mark.parametrize(
["proxy_scheme", "target_scheme", "use_forwarding_for_https"],
[
Expand Down Expand Up @@ -668,6 +695,7 @@ def test_proxy_https_target_tls_error(
# stdlib http.client.HTTPConnection._tunnel() causes a ResourceWarning
# see https://github.com/python/cpython/issues/103472
@pytest.mark.filterwarnings("default::ResourceWarning")
@_broken_on_python313a5
def test_scheme_host_case_insensitive(self) -> None:
"""Assert that upper-case schemes and hosts are normalized."""
with proxy_from_url(self.proxy_url.upper(), ca_certs=DEFAULT_CA) as http:
Expand Down Expand Up @@ -716,6 +744,7 @@ def setup_class(cls) -> None:
# stdlib http.client.HTTPConnection._tunnel() causes a ResourceWarning
# see https://github.com/python/cpython/issues/103472
@pytest.mark.filterwarnings("default::ResourceWarning")
@_broken_on_python313a5
def test_basic_ipv6_proxy(self) -> None:
with proxy_from_url(self.proxy_url, ca_certs=DEFAULT_CA) as http:
r = http.request("GET", f"{self.http_url}/")
Expand Down Expand Up @@ -750,6 +779,7 @@ def _get_certificate_formatted_proxy_host(host: str) -> str:
# stdlib http.client.HTTPConnection._tunnel() causes a ResourceWarning
# see https://github.com/python/cpython/issues/103472
@pytest.mark.filterwarnings("default::ResourceWarning")
@_broken_on_python313a5
def test_https_proxy_assert_fingerprint_md5(
self, no_san_proxy_with_server: tuple[ServerConfig, ServerConfig]
) -> None:
Expand Down Expand Up @@ -792,6 +822,7 @@ def test_https_proxy_assert_fingerprint_md5_non_matching(
# stdlib http.client.HTTPConnection._tunnel() causes a ResourceWarning
# see https://github.com/python/cpython/issues/103472
@pytest.mark.filterwarnings("default::ResourceWarning")
@_broken_on_python313a5
def test_https_proxy_assert_hostname(
self, san_proxy_with_server: tuple[ServerConfig, ServerConfig]
) -> None:
Expand All @@ -809,6 +840,11 @@ def test_https_proxy_assert_hostname(
def test_https_proxy_assert_hostname_non_matching(
self, san_proxy_with_server: tuple[ServerConfig, ServerConfig]
) -> None:
if (
sys.version_info == (3, 13, 0, "alpha", 5)
and san_proxy_with_server[0].host == "::1"
):
pytest.xfail(reason="https://github.com/python/cpython/issues/116764")
proxy, server = san_proxy_with_server
destination_url = f"https://{server.host}:{server.port}"

Expand Down Expand Up @@ -860,6 +896,7 @@ def test_https_proxy_hostname_verification(
# stdlib http.client.HTTPConnection._tunnel() causes a ResourceWarning
# see https://github.com/python/cpython/issues/103472
@pytest.mark.filterwarnings("default::ResourceWarning")
@_broken_on_python313a5
def test_https_proxy_ipv4_san(
self, ipv4_san_proxy_with_server: tuple[ServerConfig, ServerConfig]
) -> None:
Expand All @@ -870,6 +907,7 @@ def test_https_proxy_ipv4_san(
r = https.request("GET", destination_url)
assert r.status == 200

@_broken_on_python313a5
def test_https_proxy_ipv6_san(
self, ipv6_san_proxy_with_server: tuple[ServerConfig, ServerConfig]
) -> None:
Expand Down Expand Up @@ -903,6 +941,7 @@ def test_https_proxy_no_san(
ssl_error
)

@_broken_on_python313a5
def test_https_proxy_no_san_hostname_checks_common_name(
self, no_san_proxy_with_server: tuple[ServerConfig, ServerConfig]
) -> None:
Expand Down

0 comments on commit 84b0c47

Please sign in to comment.