-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore client auth clashes caused by redirects
Fixes #9436
- Loading branch information
Pierre-Louis Peeters
committed
Oct 18, 2024
1 parent
13dc020
commit 9e10136
Showing
2 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2927,6 +2927,64 @@ async def test_creds_in_auth_and_url() -> None: | |
await session.close() | ||
|
||
|
||
async def test_creds_in_auth_and_redirect_url( | ||
create_server_for_url_and_handler: Callable[[URL, Handler], Awaitable[TestServer]], | ||
) -> None: | ||
url_from = URL("http://example.com") | ||
url_to = URL("http://[email protected]") | ||
redirected = False | ||
|
||
async def srv(request: web.Request) -> web.Response: | ||
nonlocal redirected | ||
|
||
assert request.host == url_from.host | ||
|
||
if not redirected: | ||
redirected = True | ||
raise web.HTTPMovedPermanently(url_to) | ||
|
||
return web.Response() | ||
|
||
server = await create_server_for_url_and_handler(url_from, srv) | ||
|
||
etc_hosts = { | ||
(url_from.host, 80): server, | ||
} | ||
|
||
class FakeResolver(AbstractResolver): | ||
async def resolve( | ||
self, | ||
host: str, | ||
port: int = 0, | ||
family: socket.AddressFamily = socket.AF_INET, | ||
) -> List[ResolveResult]: | ||
server = etc_hosts[(host, port)] | ||
assert server.port is not None | ||
|
||
return [ | ||
{ | ||
"hostname": host, | ||
"host": server.host, | ||
"port": server.port, | ||
"family": socket.AF_INET, | ||
"proto": 0, | ||
"flags": socket.AI_NUMERICHOST, | ||
} | ||
] | ||
|
||
async def close(self) -> None: | ||
"""Dummy""" | ||
|
||
connector = aiohttp.TCPConnector(resolver=FakeResolver(), ssl=False) | ||
|
||
async with aiohttp.ClientSession(connector=connector) as client, client.get( | ||
url_from, auth=aiohttp.BasicAuth("user", "pass") | ||
) as resp: | ||
assert len(resp.history) == 1 | ||
assert str(resp.url) == "http://example.com" | ||
assert resp.status == 200 | ||
|
||
|
||
@pytest.fixture | ||
def create_server_for_url_and_handler( | ||
aiohttp_server: AiohttpServer, tls_certificate_authority: trustme.CA | ||
|