Skip to content

Commit

Permalink
Return hostnames from ThreadedResolver (#5118)
Browse files Browse the repository at this point in the history
Fix a variable-shadowing bug causing `ThreadedResolver.resolve` to
return the resolved IP as the "hostname" in each record, which prevented
validation of HTTPS connections.  Fixes #2110.
  • Loading branch information
djmitche committed Oct 24, 2020
1 parent db3db67 commit 6fed31f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES/5110.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a variable-shadowing bug causing `ThreadedResolver.resolve` to
return the resolved IP as the "hostname" in each record, which prevented
validation of HTTPS connections.
6 changes: 3 additions & 3 deletions aiohttp/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def __init__(self) -> None:
self._loop = get_running_loop()

async def resolve(
self, host: str, port: int = 0, family: int = socket.AF_INET
self, hostname: str, port: int = 0, family: int = socket.AF_INET
) -> List[Dict[str, Any]]:
infos = await self._loop.getaddrinfo(
host, port, type=socket.SOCK_STREAM, family=family
hostname, port, type=socket.SOCK_STREAM, family=family
)

hosts = []
Expand All @@ -45,7 +45,7 @@ async def resolve(
host, port = address[:2]
hosts.append(
{
"hostname": host,
"hostname": hostname,
"host": host,
"port": port,
"family": family,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,10 @@ async def test_tcp_connector_resolve_host(loop) -> None:
for rec in res:
if rec["family"] == socket.AF_INET:
assert rec["host"] == "127.0.0.1"
assert rec["hostname"] == "127.0.0.1"
assert rec["hostname"] == "localhost"
assert rec["port"] == 8080
elif rec["family"] == socket.AF_INET6:
assert rec["hostname"] == "::1"
assert rec["hostname"] == "localhost"
assert rec["port"] == 8080
if platform.system() == "Darwin":
assert rec["host"] in ("::1", "fe80::1", "fe80::1%lo0")
Expand Down
1 change: 1 addition & 0 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async def test_threaded_resolver_positive_lookup() -> None:
resolver = ThreadedResolver()
resolver._loop = loop
real = await resolver.resolve("www.python.org")
assert real[0]["hostname"] == "www.python.org"
ipaddress.ip_address(real[0]["host"])


Expand Down

0 comments on commit 6fed31f

Please sign in to comment.