mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Fix typo in KEY_ALLOW_CONFIGRED_CORS (#119905)
This commit is contained in:
parent
d2faaa1531
commit
419dcbf9a1
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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))
|
||||
|
||||
|
||||
|
@ -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 = "/"
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user