Add bare hostname as valid known hostname in get_url helper (#40510)

This commit is contained in:
Franck Nijhof 2020-09-26 09:36:03 +02:00 committed by GitHub
parent 35cfc80dd7
commit c64eec3238
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -88,10 +88,12 @@ def get_url(
scheme=scheme, host=request_host, port=hass.config.api.port
)
known_hostname = None
known_hostnames = ["localhost"]
if hass.components.hassio.is_hassio():
host_info = hass.components.hassio.get_host_info()
known_hostname = f"{host_info['hostname']}.local"
known_hostnames.extend(
[host_info["hostname"], f"{host_info['hostname']}.local"]
)
if (
(
@ -100,7 +102,7 @@ def get_url(
and is_ip_address(request_host)
and is_loopback(ip_address(request_host))
)
or request_host in ["localhost", known_hostname]
or request_host in known_hostnames
)
and (not require_ssl or current_url.scheme == "https")
and (not require_standard_port or current_url.is_default_port())

View File

@ -848,6 +848,14 @@ async def test_get_current_request_url_with_known_host(
== "http://homeassistant.local:8123"
)
with patch(
"homeassistant.helpers.network._get_request_host",
return_value="homeassistant",
):
assert (
get_url(hass, require_current_request=True) == "http://homeassistant:8123"
)
with patch(
"homeassistant.helpers.network._get_request_host", return_value="unknown.local"
), pytest.raises(NoURLAvailableError):