Fix CORS when static resources registered (#4727)

pull/4729/head
Paulus Schoutsen 2016-12-04 10:57:24 -08:00 committed by GitHub
parent 93872590b6
commit 1b35f0878e
2 changed files with 12 additions and 1 deletions

View File

@ -277,9 +277,15 @@ class HomeAssistantWSGI(object):
@asyncio.coroutine
def start(self):
"""Start the wsgi server."""
cors_added = set()
if self.cors is not None:
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)
cors_added.add(route)
if self.ssl_certificate:
context = ssl.SSLContext(SSL_VERSION)

View File

@ -44,6 +44,10 @@ def setUpModule():
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()
@ -53,11 +57,12 @@ def tearDownModule():
hass.stop()
class TestHttp:
class TestCors:
"""Test HTTP component."""
def test_cors_allowed_with_password_in_url(self):
"""Test cross origin resource sharing with password in url."""
req = requests.get(_url(const.URL_API),
params={'api_password': API_PASSWORD},
headers={const.HTTP_HEADER_ORIGIN: HTTP_BASE_URL})