Fix auth redirect ()

* Fix auth redirect

* Remove old test
pull/16908/head
Paulus Schoutsen 2018-09-27 18:02:50 +02:00 committed by Jason Hu
parent d1ad2cc225
commit 81e21b90c9
2 changed files with 18 additions and 9 deletions
homeassistant/components/frontend
tests/components/frontend

View File

@ -344,11 +344,12 @@ class AuthorizeView(HomeAssistantView):
_is_latest(self.js_option, request)
if latest:
location = '/frontend_latest/authorize.html'
base = 'frontend_latest'
else:
location = '/frontend_es5/authorize.html'
base = 'frontend_es5'
location += '?{}'.format(request.query_string)
location = "/{}/authorize.html{}".format(
base, str(request.url.relative())[15:])
return web.Response(status=302, headers={
'location': location

View File

@ -294,10 +294,18 @@ async def test_onboarding_load(mock_http_client):
async def test_auth_authorize(mock_http_client):
"""Test the authorize endpoint works."""
resp = await mock_http_client.get('/auth/authorize?hello=world')
assert resp.url.query_string == 'hello=world'
assert resp.url.path == '/frontend_es5/authorize.html'
resp = await mock_http_client.get(
'/auth/authorize?response_type=code&client_id=https://localhost/&'
'redirect_uri=https://localhost/&state=123%23456')
resp = await mock_http_client.get('/auth/authorize?latest&hello=world')
assert resp.url.query_string == 'latest&hello=world'
assert resp.url.path == '/frontend_latest/authorize.html'
assert str(resp.url.relative()) == (
'/frontend_es5/authorize.html?response_type=code&client_id='
'https://localhost/&redirect_uri=https://localhost/&state=123%23456')
resp = await mock_http_client.get(
'/auth/authorize?latest&response_type=code&client_id='
'https://localhost/&redirect_uri=https://localhost/&state=123%23456')
assert str(resp.url.relative()) == (
'/frontend_latest/authorize.html?latest&response_type=code&client_id='
'https://localhost/&redirect_uri=https://localhost/&state=123%23456')