]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
test `is_https_redirect` via public api (#3064)
authorT-256 <132141463+T-256@users.noreply.github.com>
Fri, 23 Feb 2024 14:11:43 +0000 (17:41 +0330)
committerGitHub <noreply@github.com>
Fri, 23 Feb 2024 14:11:43 +0000 (14:11 +0000)
* test `is_https_redirect` via public api

* Update tests/test_utils.py

tests/test_utils.py

index 0ef87d18d82f80b06a644d26601edd4ae0a1b860..2341a7c7b3f0cef5aa00ce2c247fc69042ef5b6c 100644 (file)
@@ -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(