mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Fix cors on the index view (#24283)
This commit is contained in:
parent
4c88578371
commit
6f903db8c4
@ -1,4 +1,5 @@
|
||||
"""Provide CORS support for the HTTP component."""
|
||||
from aiohttp.web_urldispatcher import Resource, ResourceRoute
|
||||
from aiohttp.hdrs import ACCEPT, CONTENT_TYPE, ORIGIN, AUTHORIZATION
|
||||
|
||||
from homeassistant.const import (
|
||||
@ -8,6 +9,7 @@ from homeassistant.core import callback
|
||||
ALLOWED_CORS_HEADERS = [
|
||||
ORIGIN, ACCEPT, HTTP_HEADER_X_REQUESTED_WITH, CONTENT_TYPE,
|
||||
HTTP_HEADER_HA_AUTH, AUTHORIZATION]
|
||||
VALID_CORS_TYPES = (Resource, ResourceRoute)
|
||||
|
||||
|
||||
@callback
|
||||
@ -31,6 +33,9 @@ def setup_cors(app, origins):
|
||||
else:
|
||||
path = route
|
||||
|
||||
if not isinstance(path, VALID_CORS_TYPES):
|
||||
return
|
||||
|
||||
path = path.canonical
|
||||
|
||||
if path in cors_added:
|
||||
|
@ -140,3 +140,15 @@ async def test_cors_middleware_with_cors_allowed_view(hass):
|
||||
|
||||
hass.http.app._on_startup.freeze()
|
||||
await hass.http.app.startup()
|
||||
|
||||
|
||||
async def test_cors_works_with_frontend(hass, hass_client):
|
||||
"""Test CORS works with the frontend."""
|
||||
assert await async_setup_component(hass, 'frontend', {
|
||||
'http': {
|
||||
'cors_allowed_origins': ['http://home-assistant.io']
|
||||
}
|
||||
})
|
||||
client = await hass_client()
|
||||
resp = await client.get('/')
|
||||
assert resp.status == 200
|
||||
|
Loading…
x
Reference in New Issue
Block a user