mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Add test for is_internal_request (#43841)
This commit is contained in:
parent
cf286d1c51
commit
891edec73b
@ -12,6 +12,7 @@ from homeassistant.helpers.network import (
|
||||
_get_internal_url,
|
||||
_get_request_host,
|
||||
get_url,
|
||||
is_internal_request,
|
||||
)
|
||||
|
||||
from tests.async_mock import Mock, patch
|
||||
@ -860,3 +861,40 @@ async def test_get_current_request_url_with_known_host(
|
||||
"homeassistant.helpers.network._get_request_host", return_value="unknown.local"
|
||||
), pytest.raises(NoURLAvailableError):
|
||||
get_url(hass, require_current_request=True)
|
||||
|
||||
|
||||
async def test_is_internal_request(hass: HomeAssistant):
|
||||
"""Test if accessing an instance on its internal URL."""
|
||||
# Test with internal URL: http://example.local:8123
|
||||
await async_process_ha_core_config(
|
||||
hass,
|
||||
{"internal_url": "http://example.local:8123"},
|
||||
)
|
||||
|
||||
assert hass.config.internal_url == "http://example.local:8123"
|
||||
assert not is_internal_request(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.helpers.network._get_request_host", return_value="example.local"
|
||||
):
|
||||
assert is_internal_request(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.helpers.network._get_request_host",
|
||||
return_value="no_match.example.local",
|
||||
):
|
||||
assert not is_internal_request(hass)
|
||||
|
||||
# Test with internal URL: http://192.168.0.1:8123
|
||||
await async_process_ha_core_config(
|
||||
hass,
|
||||
{"internal_url": "http://192.168.0.1:8123"},
|
||||
)
|
||||
|
||||
assert hass.config.internal_url == "http://192.168.0.1:8123"
|
||||
assert not is_internal_request(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.helpers.network._get_request_host", return_value="192.168.0.1"
|
||||
):
|
||||
assert is_internal_request(hass)
|
||||
|
Loading…
x
Reference in New Issue
Block a user