mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Fix CORS when static resources registered (#4727)
This commit is contained in:
parent
93872590b6
commit
1b35f0878e
@ -277,9 +277,15 @@ class HomeAssistantWSGI(object):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start the wsgi server."""
|
"""Start the wsgi server."""
|
||||||
|
cors_added = set()
|
||||||
if self.cors is not None:
|
if self.cors is not None:
|
||||||
for route in list(self.app.router.routes()):
|
for route in list(self.app.router.routes()):
|
||||||
|
if hasattr(route, 'resource'):
|
||||||
|
route = route.resource
|
||||||
|
if route in cors_added:
|
||||||
|
continue
|
||||||
self.cors.add(route)
|
self.cors.add(route)
|
||||||
|
cors_added.add(route)
|
||||||
|
|
||||||
if self.ssl_certificate:
|
if self.ssl_certificate:
|
||||||
context = ssl.SSLContext(SSL_VERSION)
|
context = ssl.SSLContext(SSL_VERSION)
|
||||||
|
@ -44,6 +44,10 @@ def setUpModule():
|
|||||||
|
|
||||||
bootstrap.setup_component(hass, 'api')
|
bootstrap.setup_component(hass, 'api')
|
||||||
|
|
||||||
|
# Registering static path as it caused CORS to blow up
|
||||||
|
hass.http.register_static_path(
|
||||||
|
'/custom_components', hass.config.path('custom_components'))
|
||||||
|
|
||||||
hass.start()
|
hass.start()
|
||||||
|
|
||||||
|
|
||||||
@ -53,11 +57,12 @@ def tearDownModule():
|
|||||||
hass.stop()
|
hass.stop()
|
||||||
|
|
||||||
|
|
||||||
class TestHttp:
|
class TestCors:
|
||||||
"""Test HTTP component."""
|
"""Test HTTP component."""
|
||||||
|
|
||||||
def test_cors_allowed_with_password_in_url(self):
|
def test_cors_allowed_with_password_in_url(self):
|
||||||
"""Test cross origin resource sharing with password in url."""
|
"""Test cross origin resource sharing with password in url."""
|
||||||
|
|
||||||
req = requests.get(_url(const.URL_API),
|
req = requests.get(_url(const.URL_API),
|
||||||
params={'api_password': API_PASSWORD},
|
params={'api_password': API_PASSWORD},
|
||||||
headers={const.HTTP_HEADER_ORIGIN: HTTP_BASE_URL})
|
headers={const.HTTP_HEADER_ORIGIN: HTTP_BASE_URL})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user