Allow CORS requests to token endpoint (#15519)

* Allow CORS requests to token endpoint

* Tests

* Fuck emulated hue

* Clean up

* Only cors existing methods
This commit is contained in:
Paulus Schoutsen authored and Paulus Schoutsen committed 2018-07-19 12:26:08 +02:00
1 parent ca0d4226aa
commit 2fc0d83085
9 files changed
+59 -23

No files matched your search

+17
View File
@@ -93,3 +93,20 @@ async def test_ws_current_user(hass, hass_ws_client, hass_access_token):
assert user_dict['name'] == user.name
assert user_dict['id'] == user.id
assert user_dict['is_owner'] == user.is_owner
async def test_cors_on_token(hass, aiohttp_client):
"""Test logging in with new user and refreshing tokens."""
client = await async_setup_auth(hass, aiohttp_client)
resp = await client.options('/auth/token', headers={
'origin': 'http://example.com',
'Access-Control-Request-Method': 'POST',
})
assert resp.headers['Access-Control-Allow-Origin'] == 'http://example.com'
assert resp.headers['Access-Control-Allow-Methods'] == 'POST'
resp = await client.post('/auth/token', headers={
'origin': 'http://example.com'
})
assert resp.headers['Access-Control-Allow-Origin'] == 'http://example.com'
@@ -130,10 +130,10 @@ def hue_client(loop, hass_hue, aiohttp_client):
}
})
HueUsernameView().register(web_app.router)
HueAllLightsStateView(config).register(web_app.router)
HueOneLightStateView(config).register(web_app.router)
HueOneLightChangeView(config).register(web_app.router)
HueUsernameView().register(web_app, web_app.router)
HueAllLightsStateView(config).register(web_app, web_app.router)
HueOneLightStateView(config).register(web_app, web_app.router)
HueOneLightChangeView(config).register(web_app, web_app.router)
return loop.run_until_complete(aiohttp_client(web_app))
+2 -2
View File
@@ -19,14 +19,14 @@ from homeassistant.components.http.cors import setup_cors
TRUSTED_ORIGIN = 'https://home-assistant.io'
async def test_cors_middleware_not_loaded_by_default(hass):
async def test_cors_middleware_loaded_by_default(hass):
"""Test accessing to server from banned IP when feature is off."""
with patch('homeassistant.components.http.setup_cors') as mock_setup:
await async_setup_component(hass, 'http', {
'http': {}
})
assert len(mock_setup.mock_calls) == 0
assert len(mock_setup.mock_calls) == 1
async def test_cors_middleware_loaded_from_config(hass):
+1 -1
View File
@@ -23,7 +23,7 @@ async def get_client(aiohttp_client, validator):
"""Test method."""
return b''
TestView().register(app.router)
TestView().register(app, app.router)
client = await aiohttp_client(app)
return client