Skip to content

Commit

Permalink
test is_https_redirect via public api (encode#3064)
Browse files Browse the repository at this point in the history
* test `is_https_redirect` via public api

* Update tests/test_utils.py
  • Loading branch information
T-256 authored and shepilov-vladislav committed Mar 28, 2024
1 parent cf15732 commit fc4b7e3
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
URLPattern,
get_ca_bundle_from_env,
get_environment_proxies,
is_https_redirect,
same_origin,
)

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit fc4b7e3

Please sign in to comment.