Skip to content

Commit

Permalink
[3.7] Return hostnames from ThreadedResolver (#5118) (#5121)
Browse files Browse the repository at this point in the history
Backports the following commits to 3.7:
 - Return hostnames from ThreadedResolver (#5118)

Co-authored-by: Dustin J. Mitchell <dustin@mozilla.com>
  • Loading branch information
aio-libs-github-bot[bot] and djmitche committed Oct 24, 2020
1 parent 0353589 commit 70d8677
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 @@ -26,10 +26,10 @@ def __init__(self, loop: Optional[asyncio.AbstractEventLoop] = None) -> None:
self._loop = get_running_loop(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 @@ -46,7 +46,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 @@ -675,10 +675,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 @@ -130,6 +130,7 @@ async def test_threaded_resolver_positive_lookup() -> None:
loop.getaddrinfo = fake_addrinfo(["127.0.0.1"])
resolver = ThreadedResolver(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 70d8677

Please sign in to comment.