Remove strict connection (#116396)

pull/117910/head
Robert Resch 2024-04-29 19:33:31 +02:00 committed by GitHub
parent b3c1a86194
commit dfc198cae0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 12 additions and 40 deletions

View File

@ -30,7 +30,6 @@ from homeassistant.core import (
HomeAssistant,
ServiceCall,
ServiceResponse,
SupportsResponse,
callback,
)
from homeassistant.exceptions import (
@ -458,10 +457,3 @@ def _setup_services(hass: HomeAssistant, prefs: CloudPreferences) -> None:
"url": f"https://login.home-assistant.io?u={quote_plus(url)}",
"direct_url": url,
}
hass.services.async_register(
DOMAIN,
"create_temporary_strict_connection_url",
create_temporary_strict_connection_url,
supports_response=SupportsResponse.ONLY,
)

View File

@ -365,16 +365,7 @@ class CloudPreferences:
@property
def strict_connection(self) -> http.const.StrictConnectionMode:
"""Return the strict connection mode."""
mode = self._prefs.get(PREF_STRICT_CONNECTION)
if mode is None:
# Set to default value
# We store None in the store as the default value to detect if the user has changed the
# value or not.
mode = http.const.StrictConnectionMode.DISABLED
elif not isinstance(mode, http.const.StrictConnectionMode):
mode = http.const.StrictConnectionMode(mode)
return mode
return http.const.StrictConnectionMode.DISABLED
async def get_cloud_user(self) -> str:
"""Return ID of Home Assistant Cloud system user."""

View File

@ -10,7 +10,7 @@ import os
import socket
import ssl
from tempfile import NamedTemporaryFile
from typing import Any, Final, Required, TypedDict, cast
from typing import Any, Final, TypedDict, cast
from urllib.parse import quote_plus, urljoin
from aiohttp import web
@ -36,7 +36,6 @@ from homeassistant.core import (
HomeAssistant,
ServiceCall,
ServiceResponse,
SupportsResponse,
callback,
)
from homeassistant.exceptions import (
@ -146,9 +145,6 @@ HTTP_SCHEMA: Final = vol.All(
[SSL_INTERMEDIATE, SSL_MODERN]
),
vol.Optional(CONF_USE_X_FRAME_OPTIONS, default=True): cv.boolean,
vol.Optional(
CONF_STRICT_CONNECTION, default=StrictConnectionMode.DISABLED
): vol.Coerce(StrictConnectionMode),
}
),
)
@ -172,7 +168,6 @@ class ConfData(TypedDict, total=False):
login_attempts_threshold: int
ip_ban_enabled: bool
ssl_profile: str
strict_connection: Required[StrictConnectionMode]
@bind_hass
@ -239,7 +234,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
login_threshold=login_threshold,
is_ban_enabled=is_ban_enabled,
use_x_frame_options=use_x_frame_options,
strict_connection_non_cloud=conf[CONF_STRICT_CONNECTION],
strict_connection_non_cloud=StrictConnectionMode.DISABLED,
)
async def stop_server(event: Event) -> None:
@ -620,7 +615,7 @@ def _setup_services(hass: HomeAssistant, conf: ConfData) -> None:
if not user.is_admin:
raise Unauthorized(context=call.context)
if conf[CONF_STRICT_CONNECTION] is StrictConnectionMode.DISABLED:
if StrictConnectionMode.DISABLED is StrictConnectionMode.DISABLED:
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key="strict_connection_not_enabled_non_cloud",
@ -652,10 +647,3 @@ def _setup_services(hass: HomeAssistant, conf: ConfData) -> None:
"url": f"https://login.home-assistant.io?u={quote_plus(url)}",
"direct_url": url,
}
hass.services.async_register(
DOMAIN,
"create_temporary_strict_connection_url",
create_temporary_strict_connection_url,
supports_response=SupportsResponse.ONLY,
)

View File

@ -915,7 +915,6 @@ async def test_websocket_update_preferences(
"google_secure_devices_pin": "1234",
"tts_default_voice": ["en-GB", "RyanNeural"],
"remote_allow_remote_enable": False,
"strict_connection": StrictConnectionMode.DROP_CONNECTION,
}
)
response = await client.receive_json()
@ -926,7 +925,6 @@ async def test_websocket_update_preferences(
assert cloud.client.prefs.google_secure_devices_pin == "1234"
assert cloud.client.prefs.remote_allow_remote_enable is False
assert cloud.client.prefs.tts_default_voice == ("en-GB", "RyanNeural")
assert cloud.client.prefs.strict_connection is StrictConnectionMode.DROP_CONNECTION
@pytest.mark.parametrize(

View File

@ -303,6 +303,7 @@ async def test_cloud_logout(
assert cloud.is_logged_in is False
@pytest.mark.skip(reason="Remove strict connection config option")
async def test_service_create_temporary_strict_connection_url_strict_connection_disabled(
hass: HomeAssistant,
) -> None:
@ -323,6 +324,7 @@ async def test_service_create_temporary_strict_connection_url_strict_connection_
)
@pytest.mark.skip(reason="Remove strict connection config option")
@pytest.mark.parametrize(
("mode"),
[

View File

@ -181,6 +181,7 @@ async def test_tts_default_voice_legacy_gender(
assert cloud.client.prefs.tts_default_voice == (expected_language, voice)
@pytest.mark.skip(reason="Remove strict connection config option")
@pytest.mark.parametrize("mode", list(StrictConnectionMode))
async def test_strict_connection_convertion(
hass: HomeAssistant,

View File

@ -226,6 +226,7 @@ async def _guard_page_unauthorized_request(
assert await req.text() == await hass.async_add_executor_job(read_guard_page)
@pytest.mark.skip(reason="Remove strict connection config option")
@pytest.mark.parametrize(
"test_func",
[

View File

@ -527,6 +527,7 @@ async def test_logging(
assert "GET /api/states/logging.entity" not in caplog.text
@pytest.mark.skip(reason="Remove strict connection config option")
async def test_service_create_temporary_strict_connection_url_strict_connection_disabled(
hass: HomeAssistant,
) -> None:
@ -544,6 +545,7 @@ async def test_service_create_temporary_strict_connection_url_strict_connection_
)
@pytest.mark.skip(reason="Remove strict connection config option")
@pytest.mark.parametrize(
("mode"),
[

View File

@ -800,11 +800,10 @@ async def test_async_get_all_descriptions(hass: HomeAssistant) -> None:
assert proxy_load_services_files.mock_calls[0][1][1] == unordered(
[
await async_get_integration(hass, DOMAIN_GROUP),
await async_get_integration(hass, "http"), # system_health requires http
]
)
assert len(descriptions) == 2
assert len(descriptions) == 1
assert DOMAIN_GROUP in descriptions
assert "description" in descriptions[DOMAIN_GROUP]["reload"]
assert "fields" in descriptions[DOMAIN_GROUP]["reload"]
@ -838,7 +837,7 @@ async def test_async_get_all_descriptions(hass: HomeAssistant) -> None:
await async_setup_component(hass, DOMAIN_LOGGER, logger_config)
descriptions = await service.async_get_all_descriptions(hass)
assert len(descriptions) == 3
assert len(descriptions) == 2
assert DOMAIN_LOGGER in descriptions
assert descriptions[DOMAIN_LOGGER]["set_default_level"]["name"] == "Translated name"
assert (

View File

@ -5,7 +5,6 @@ from unittest.mock import patch
import pytest
from homeassistant.components.http.const import StrictConnectionMode
from homeassistant.config import YAML_CONFIG_FILE
from homeassistant.scripts import check_config
@ -135,7 +134,6 @@ def test_secrets(mock_is_file, event_loop, mock_hass_config_yaml: None) -> None:
"login_attempts_threshold": -1,
"server_port": 8123,
"ssl_profile": "modern",
"strict_connection": StrictConnectionMode.DISABLED,
"use_x_frame_options": True,
"server_host": ["0.0.0.0", "::"],
}