Remove strict connection (#117933)
This commit is contained in:
parent
6f81852eb4
commit
cb62f4242e
32 changed files with 39 additions and 1816 deletions
|
@ -7,7 +7,6 @@ from ipaddress import ip_network
|
|||
import logging
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock, patch
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -15,10 +14,7 @@ from homeassistant.auth.providers.legacy_api_password import (
|
|||
LegacyApiPasswordAuthProvider,
|
||||
)
|
||||
from homeassistant.components import http
|
||||
from homeassistant.components.http.const import StrictConnectionMode
|
||||
from homeassistant.config import async_process_ha_core_config
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers.http import KEY_HASS
|
||||
from homeassistant.helpers.network import NoURLAvailableError
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
@ -525,78 +521,3 @@ async def test_logging(
|
|||
response = await client.get("/api/states/logging.entity")
|
||||
assert response.status == HTTPStatus.OK
|
||||
assert "GET /api/states/logging.entity" not in caplog.text
|
||||
|
||||
|
||||
async def test_service_create_temporary_strict_connection_url_strict_connection_disabled(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test service create_temporary_strict_connection_url with strict_connection not enabled."""
|
||||
assert await async_setup_component(hass, http.DOMAIN, {"http": {}})
|
||||
with pytest.raises(
|
||||
ServiceValidationError,
|
||||
match="Strict connection is not enabled for non-cloud requests",
|
||||
):
|
||||
await hass.services.async_call(
|
||||
http.DOMAIN,
|
||||
"create_temporary_strict_connection_url",
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("mode"),
|
||||
[
|
||||
StrictConnectionMode.DROP_CONNECTION,
|
||||
StrictConnectionMode.GUARD_PAGE,
|
||||
],
|
||||
)
|
||||
async def test_service_create_temporary_strict_connection(
|
||||
hass: HomeAssistant, mode: StrictConnectionMode
|
||||
) -> None:
|
||||
"""Test service create_temporary_strict_connection_url."""
|
||||
assert await async_setup_component(
|
||||
hass, http.DOMAIN, {"http": {"strict_connection": mode}}
|
||||
)
|
||||
|
||||
# No external url set
|
||||
assert hass.config.external_url is None
|
||||
assert hass.config.internal_url is None
|
||||
with pytest.raises(ServiceValidationError, match="No external URL available"):
|
||||
await hass.services.async_call(
|
||||
http.DOMAIN,
|
||||
"create_temporary_strict_connection_url",
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
)
|
||||
|
||||
# Raise if only internal url is available
|
||||
hass.config.api = Mock(use_ssl=False, port=8123, local_ip="192.168.123.123")
|
||||
with pytest.raises(ServiceValidationError, match="No external URL available"):
|
||||
await hass.services.async_call(
|
||||
http.DOMAIN,
|
||||
"create_temporary_strict_connection_url",
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
)
|
||||
|
||||
# Set external url too
|
||||
external_url = "https://example.com"
|
||||
await async_process_ha_core_config(
|
||||
hass,
|
||||
{"external_url": external_url},
|
||||
)
|
||||
assert hass.config.external_url == external_url
|
||||
response = await hass.services.async_call(
|
||||
http.DOMAIN,
|
||||
"create_temporary_strict_connection_url",
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
)
|
||||
assert isinstance(response, dict)
|
||||
direct_url_prefix = f"{external_url}/auth/strict_connection/temp_token?authSig="
|
||||
assert response.pop("direct_url").startswith(direct_url_prefix)
|
||||
assert response.pop("url").startswith(
|
||||
f"https://login.home-assistant.io?u={quote_plus(direct_url_prefix)}"
|
||||
)
|
||||
assert response == {} # No more keys in response
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue