Fix auth redirect (#16914)

* Fix auth redirect

* Remove old test
This commit is contained in:
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

View File

@ -344,11 +344,12 @@ class AuthorizeView(HomeAssistantView):
_is_latest(self.js_option, request) _is_latest(self.js_option, request)
if latest: if latest:
location = '/frontend_latest/authorize.html' base = 'frontend_latest'
else: 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={ return web.Response(status=302, headers={
'location': location 'location': location

View File

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