Skip to content

Commit 70d8677

Browse files
[3.7] Return hostnames from ThreadedResolver (#5118) (#5121)
Backports the following commits to 3.7: - Return hostnames from ThreadedResolver (#5118) Co-authored-by: Dustin J. Mitchell <[email protected]>
1 parent 0353589 commit 70d8677

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

CHANGES/5110.bugfix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a variable-shadowing bug causing `ThreadedResolver.resolve` to
2+
return the resolved IP as the "hostname" in each record, which prevented
3+
validation of HTTPS connections.

aiohttp/resolver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def __init__(self, loop: Optional[asyncio.AbstractEventLoop] = None) -> None:
2626
self._loop = get_running_loop(loop)
2727

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

3535
hosts = []
@@ -46,7 +46,7 @@ async def resolve(
4646
host, port = address[:2]
4747
hosts.append(
4848
{
49-
"hostname": host,
49+
"hostname": hostname,
5050
"host": host,
5151
"port": port,
5252
"family": family,

tests/test_connector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,10 @@ async def test_tcp_connector_resolve_host(loop) -> None:
675675
for rec in res:
676676
if rec["family"] == socket.AF_INET:
677677
assert rec["host"] == "127.0.0.1"
678-
assert rec["hostname"] == "127.0.0.1"
678+
assert rec["hostname"] == "localhost"
679679
assert rec["port"] == 8080
680680
elif rec["family"] == socket.AF_INET6:
681-
assert rec["hostname"] == "::1"
681+
assert rec["hostname"] == "localhost"
682682
assert rec["port"] == 8080
683683
if platform.system() == "Darwin":
684684
assert rec["host"] in ("::1", "fe80::1", "fe80::1%lo0")

tests/test_resolver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ async def test_threaded_resolver_positive_lookup() -> None:
130130
loop.getaddrinfo = fake_addrinfo(["127.0.0.1"])
131131
resolver = ThreadedResolver(loop=loop)
132132
real = await resolver.resolve("www.python.org")
133+
assert real[0]["hostname"] == "www.python.org"
133134
ipaddress.ip_address(real[0]["host"])
134135

135136

0 commit comments

Comments
 (0)