diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index 4e62df3a024..fae50f97a33 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -37,7 +37,7 @@ from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import storage import homeassistant.helpers.config_validation as cv from homeassistant.helpers.http import ( - KEY_ALLOW_CONFIGRED_CORS, + KEY_ALLOW_CONFIGURED_CORS, KEY_AUTHENTICATED, # noqa: F401 KEY_HASS, HomeAssistantView, @@ -427,7 +427,7 @@ class HomeAssistantHTTP: # Should be instance of aiohttp.web_exceptions._HTTPMove. raise redirect_exc(redirect_to) # type: ignore[arg-type,misc] - self.app[KEY_ALLOW_CONFIGRED_CORS]( + self.app[KEY_ALLOW_CONFIGURED_CORS]( self.app.router.add_route("GET", url, redirect) ) @@ -461,7 +461,7 @@ class HomeAssistantHTTP: ) -> None: """Register a folders or files to serve as a static path.""" app = self.app - allow_cors = app[KEY_ALLOW_CONFIGRED_CORS] + allow_cors = app[KEY_ALLOW_CONFIGURED_CORS] for config in configs: if resource := resources[config.url_path]: app.router.register_resource(resource) diff --git a/homeassistant/components/http/cors.py b/homeassistant/components/http/cors.py index d97ac9922a2..69e7c7ea2d5 100644 --- a/homeassistant/components/http/cors.py +++ b/homeassistant/components/http/cors.py @@ -19,7 +19,7 @@ from homeassistant.const import HTTP_HEADER_X_REQUESTED_WITH from homeassistant.core import callback from homeassistant.helpers.http import ( KEY_ALLOW_ALL_CORS, - KEY_ALLOW_CONFIGRED_CORS, + KEY_ALLOW_CONFIGURED_CORS, AllowCorsType, ) @@ -82,6 +82,6 @@ def setup_cors(app: Application, origins: list[str]) -> None: ) if origins: - app[KEY_ALLOW_CONFIGRED_CORS] = cast(AllowCorsType, _allow_cors) + app[KEY_ALLOW_CONFIGURED_CORS] = cast(AllowCorsType, _allow_cors) else: - app[KEY_ALLOW_CONFIGRED_CORS] = lambda _: None + app[KEY_ALLOW_CONFIGURED_CORS] = lambda _: None diff --git a/homeassistant/helpers/http.py b/homeassistant/helpers/http.py index bbe4e26f4e5..22f8e2acbeb 100644 --- a/homeassistant/helpers/http.py +++ b/homeassistant/helpers/http.py @@ -33,7 +33,7 @@ _LOGGER = logging.getLogger(__name__) type AllowCorsType = Callable[[AbstractRoute | AbstractResource], None] KEY_AUTHENTICATED: Final = "ha_authenticated" KEY_ALLOW_ALL_CORS = AppKey[AllowCorsType]("allow_all_cors") -KEY_ALLOW_CONFIGRED_CORS = AppKey[AllowCorsType]("allow_configured_cors") +KEY_ALLOW_CONFIGURED_CORS = AppKey[AllowCorsType]("allow_configured_cors") KEY_HASS: AppKey[HomeAssistant] = AppKey("hass") current_request: ContextVar[Request | None] = ContextVar( @@ -181,7 +181,7 @@ class HomeAssistantView: if self.cors_allowed: allow_cors = app.get(KEY_ALLOW_ALL_CORS) else: - allow_cors = app.get(KEY_ALLOW_CONFIGRED_CORS) + allow_cors = app.get(KEY_ALLOW_CONFIGURED_CORS) if allow_cors: for route in routes: diff --git a/tests/components/http/test_cors.py b/tests/components/http/test_cors.py index 04f5db753c9..1188131cc0f 100644 --- a/tests/components/http/test_cors.py +++ b/tests/components/http/test_cors.py @@ -20,7 +20,7 @@ import pytest from homeassistant.components.http.cors import setup_cors from homeassistant.components.http.view import HomeAssistantView from homeassistant.core import HomeAssistant -from homeassistant.helpers.http import KEY_ALLOW_CONFIGRED_CORS +from homeassistant.helpers.http import KEY_ALLOW_CONFIGURED_CORS from homeassistant.setup import async_setup_component from . import HTTP_HEADER_HA_AUTH @@ -62,7 +62,7 @@ def client( """Fixture to set up a web.Application.""" app = web.Application() setup_cors(app, [TRUSTED_ORIGIN]) - app[KEY_ALLOW_CONFIGRED_CORS](app.router.add_get("/", mock_handler)) + app[KEY_ALLOW_CONFIGURED_CORS](app.router.add_get("/", mock_handler)) return event_loop.run_until_complete(aiohttp_client(app)) diff --git a/tests/components/http/test_data_validator.py b/tests/components/http/test_data_validator.py index 9a4e80052f6..b415e54af04 100644 --- a/tests/components/http/test_data_validator.py +++ b/tests/components/http/test_data_validator.py @@ -8,7 +8,7 @@ import voluptuous as vol from homeassistant.components.http import KEY_HASS, HomeAssistantView from homeassistant.components.http.data_validator import RequestDataValidator -from homeassistant.helpers.http import KEY_ALLOW_CONFIGRED_CORS +from homeassistant.helpers.http import KEY_ALLOW_CONFIGURED_CORS from tests.typing import ClientSessionGenerator @@ -17,7 +17,7 @@ async def get_client(aiohttp_client, validator): """Generate a client that hits a view decorated with validator.""" app = web.Application() app[KEY_HASS] = Mock(is_stopping=False) - app[KEY_ALLOW_CONFIGRED_CORS] = lambda _: None + app[KEY_ALLOW_CONFIGURED_CORS] = lambda _: None class TestView(HomeAssistantView): url = "/" diff --git a/tests/components/http/test_static.py b/tests/components/http/test_static.py index 92e92cdb4a7..3e3f21d5002 100644 --- a/tests/components/http/test_static.py +++ b/tests/components/http/test_static.py @@ -10,7 +10,7 @@ import pytest from homeassistant.components.http import StaticPathConfig from homeassistant.components.http.static import CachingStaticResource, _get_file_path from homeassistant.core import EVENT_HOMEASSISTANT_START, HomeAssistant -from homeassistant.helpers.http import KEY_ALLOW_CONFIGRED_CORS +from homeassistant.helpers.http import KEY_ALLOW_CONFIGURED_CORS from homeassistant.setup import async_setup_component from tests.typing import ClientSessionGenerator @@ -51,7 +51,7 @@ async def test_static_path_blocks_anchors( resource = CachingStaticResource(url, str(tmp_path)) assert resource.canonical == canonical_url app.router.register_resource(resource) - app[KEY_ALLOW_CONFIGRED_CORS](resource) + app[KEY_ALLOW_CONFIGURED_CORS](resource) resp = await mock_http_client.get(canonical_url, allow_redirects=False) assert resp.status == 403