]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
test `same_origin` via public api (#3062)
authorT-256 <132141463+T-256@users.noreply.github.com>
Fri, 23 Feb 2024 14:16:03 +0000 (17:46 +0330)
committerGitHub <noreply@github.com>
Fri, 23 Feb 2024 14:16:03 +0000 (14:16 +0000)
Co-authored-by: Tom Christie <tom@tomchristie.com>
tests/test_utils.py

index 2341a7c7b3f0cef5aa00ce2c247fc69042ef5b6c..f98a18f2cd6bd9d514b48610d00c584cbd5aca1e 100644 (file)
@@ -11,7 +11,6 @@ from httpx._utils import (
     URLPattern,
     get_ca_bundle_from_env,
     get_environment_proxies,
-    same_origin,
 )
 
 from .common import TESTS_DIR
@@ -224,15 +223,23 @@ def test_obfuscate_sensitive_headers(headers, output):
 
 
 def test_same_origin():
-    origin1 = httpx.URL("https://example.com")
-    origin2 = httpx.URL("HTTPS://EXAMPLE.COM:443")
-    assert same_origin(origin1, origin2)
+    origin = httpx.URL("https://example.com")
+    request = httpx.Request("GET", "HTTPS://EXAMPLE.COM:443")
+
+    client = httpx.Client()
+    headers = client._redirect_headers(request, origin, "GET")
+
+    assert headers["Host"] == request.url.netloc.decode("ascii")
 
 
 def test_not_same_origin():
-    origin1 = httpx.URL("https://example.com")
-    origin2 = httpx.URL("HTTP://EXAMPLE.COM")
-    assert not same_origin(origin1, origin2)
+    origin = httpx.URL("https://example.com")
+    request = httpx.Request("GET", "HTTP://EXAMPLE.COM:80")
+
+    client = httpx.Client()
+    headers = client._redirect_headers(request, origin, "GET")
+
+    assert headers["Host"] == origin.netloc.decode("ascii")
 
 
 def test_is_https_redirect():