mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Add bare hostname as valid known hostname in get_url helper (#40510)
This commit is contained in:
parent
35cfc80dd7
commit
c64eec3238
@ -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())
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user