1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-26 05:57:01 +00:00

Get_url to prefer external URL if SSL configured (#66039)

This commit is contained in:
Paulus Schoutsen
2022-02-07 15:44:02 -08:00
committed by GitHub
parent 7cc6770f83
commit 95a890c6e1
3 changed files with 30 additions and 5 deletions

View File

@@ -480,6 +480,12 @@ async def test_get_url(hass: HomeAssistant):
get_url(hass, prefer_external=True, allow_external=False)
== "http://example.local"
)
# Prefer external defaults to True if use_ssl=True
hass.config.api = Mock(use_ssl=True)
assert get_url(hass) == "https://example.com"
hass.config.api = Mock(use_ssl=False)
assert get_url(hass) == "http://example.local"
hass.config.api = None
with pytest.raises(NoURLAvailableError):
get_url(hass, allow_external=False, require_ssl=True)
@@ -519,6 +525,19 @@ async def test_get_url(hass: HomeAssistant):
), pytest.raises(NoURLAvailableError):
_get_internal_url(hass, require_current_request=True)
# Test allow_ip defaults when SSL specified
await async_process_ha_core_config(
hass,
{"external_url": "https://1.1.1.1"},
)
assert hass.config.external_url == "https://1.1.1.1"
assert get_url(hass, allow_internal=False) == "https://1.1.1.1"
hass.config.api = Mock(use_ssl=False)
assert get_url(hass, allow_internal=False) == "https://1.1.1.1"
hass.config.api = Mock(use_ssl=True)
with pytest.raises(NoURLAvailableError):
assert get_url(hass, allow_internal=False)
async def test_get_request_host(hass: HomeAssistant):
"""Test getting the host of the current web request from the request context."""