From: T-256 <132141463+T-256@users.noreply.github.com> Date: Fri, 23 Feb 2024 14:11:43 +0000 (+0330) Subject: test `is_https_redirect` via public api (#3064) X-Git-Tag: 0.27.1~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e745060c75d06a7a6c1c90007120af2a43b3fffc;p=thirdparty%2Fhttpx.git test `is_https_redirect` via public api (#3064) * test `is_https_redirect` via public api * Update tests/test_utils.py --- diff --git a/tests/test_utils.py b/tests/test_utils.py index 0ef87d18..2341a7c7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -11,7 +11,6 @@ from httpx._utils import ( URLPattern, get_ca_bundle_from_env, get_environment_proxies, - is_https_redirect, same_origin, ) @@ -237,21 +236,39 @@ def test_not_same_origin(): def test_is_https_redirect(): - url = httpx.URL("http://example.com") - location = httpx.URL("https://example.com") - assert is_https_redirect(url, location) + url = httpx.URL("https://example.com") + request = httpx.Request( + "GET", "http://example.com", headers={"Authorization": "empty"} + ) + + client = httpx.Client() + headers = client._redirect_headers(request, url, "GET") + + assert "Authorization" in headers def test_is_not_https_redirect(): - url = httpx.URL("http://example.com") - location = httpx.URL("https://www.example.com") - assert not is_https_redirect(url, location) + url = httpx.URL("https://www.example.com") + request = httpx.Request( + "GET", "http://example.com", headers={"Authorization": "empty"} + ) + + client = httpx.Client() + headers = client._redirect_headers(request, url, "GET") + + assert "Authorization" not in headers def test_is_not_https_redirect_if_not_default_ports(): - url = httpx.URL("http://example.com:9999") - location = httpx.URL("https://example.com:1337") - assert not is_https_redirect(url, location) + url = httpx.URL("https://example.com:1337") + request = httpx.Request( + "GET", "http://example.com:9999", headers={"Authorization": "empty"} + ) + + client = httpx.Client() + headers = client._redirect_headers(request, url, "GET") + + assert "Authorization" not in headers @pytest.mark.parametrize(