Skip to content

Commit 75a4e45

Browse files
committed
test: fix coverage gaps for relative redirect and unreachable mock branch
Add test for relative Location headers (exercises the is_relative_url branch). Mark unreachable 200-response fallback in blocking test with pragma: no cover. Github-Issue: #2106
1 parent 06d1f1e commit 75a4e45

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tests/shared/test_httpx_utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ async def test_block_scheme_downgrade_allows_http_to_https():
107107
await _check_redirect(response, RedirectPolicy.BLOCK_SCHEME_DOWNGRADE)
108108

109109

110+
async def test_block_scheme_downgrade_allows_relative_redirect():
111+
"""Test BLOCK_SCHEME_DOWNGRADE allows relative Location headers."""
112+
response = httpx.Response(
113+
302,
114+
headers={"Location": "/other-path"},
115+
request=httpx.Request("GET", "https://example.com/start"),
116+
)
117+
await _check_redirect(response, RedirectPolicy.BLOCK_SCHEME_DOWNGRADE)
118+
119+
110120
# --- ENFORCE_HTTPS tests ---
111121

112122

@@ -166,7 +176,7 @@ async def test_redirect_hook_blocks_scheme_downgrade_via_transport():
166176
def mock_handler(request: httpx.Request) -> httpx.Response:
167177
if str(request.url) == "https://example.com/start":
168178
return httpx.Response(302, headers={"Location": "http://evil.com/stolen"})
169-
return httpx.Response(200, text="OK")
179+
return httpx.Response(200, text="OK") # pragma: no cover
170180

171181
async with create_mcp_http_client() as client:
172182
client._transport = httpx.MockTransport(mock_handler)

0 commit comments

Comments
 (0)