mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Fail fetch auth providers if onboarding required (#16454)
This commit is contained in:
parent
dcd7b9a529
commit
cfe5db4350
@ -66,7 +66,7 @@ associate with an credential if "type" set to "link_user" in
|
|||||||
"version": 1
|
"version": 1
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
import aiohttp.web
|
from aiohttp import web
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
@ -95,11 +95,20 @@ class AuthProvidersView(HomeAssistantView):
|
|||||||
|
|
||||||
async def get(self, request):
|
async def get(self, request):
|
||||||
"""Get available auth providers."""
|
"""Get available auth providers."""
|
||||||
|
hass = request.app['hass']
|
||||||
|
|
||||||
|
if not hass.components.onboarding.async_is_onboarded():
|
||||||
|
return self.json_message(
|
||||||
|
message='Onboarding not finished',
|
||||||
|
status_code=400,
|
||||||
|
message_code='onboarding_required'
|
||||||
|
)
|
||||||
|
|
||||||
return self.json([{
|
return self.json([{
|
||||||
'name': provider.name,
|
'name': provider.name,
|
||||||
'id': provider.id,
|
'id': provider.id,
|
||||||
'type': provider.type,
|
'type': provider.type,
|
||||||
} for provider in request.app['hass'].auth.auth_providers])
|
} for provider in hass.auth.auth_providers])
|
||||||
|
|
||||||
|
|
||||||
def _prepare_result_json(result):
|
def _prepare_result_json(result):
|
||||||
@ -139,7 +148,7 @@ class LoginFlowIndexView(HomeAssistantView):
|
|||||||
|
|
||||||
async def get(self, request):
|
async def get(self, request):
|
||||||
"""Do not allow index of flows in progress."""
|
"""Do not allow index of flows in progress."""
|
||||||
return aiohttp.web.Response(status=405)
|
return web.Response(status=405)
|
||||||
|
|
||||||
@RequestDataValidator(vol.Schema({
|
@RequestDataValidator(vol.Schema({
|
||||||
vol.Required('client_id'): str,
|
vol.Required('client_id'): str,
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
"""Tests for the login flow."""
|
"""Tests for the login flow."""
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from . import async_setup_auth
|
from . import async_setup_auth
|
||||||
|
|
||||||
from tests.common import CLIENT_ID, CLIENT_REDIRECT_URI
|
from tests.common import CLIENT_ID, CLIENT_REDIRECT_URI
|
||||||
@ -16,6 +18,19 @@ async def test_fetch_auth_providers(hass, aiohttp_client):
|
|||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_fetch_auth_providers_onboarding(hass, aiohttp_client):
|
||||||
|
"""Test fetching auth providers."""
|
||||||
|
client = await async_setup_auth(hass, aiohttp_client)
|
||||||
|
with patch('homeassistant.components.onboarding.async_is_onboarded',
|
||||||
|
return_value=False):
|
||||||
|
resp = await client.get('/auth/providers')
|
||||||
|
assert resp.status == 400
|
||||||
|
assert await resp.json() == {
|
||||||
|
'message': 'Onboarding not finished',
|
||||||
|
'code': 'onboarding_required',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_cannot_get_flows_in_progress(hass, aiohttp_client):
|
async def test_cannot_get_flows_in_progress(hass, aiohttp_client):
|
||||||
"""Test we cannot get flows in progress."""
|
"""Test we cannot get flows in progress."""
|
||||||
client = await async_setup_auth(hass, aiohttp_client, [])
|
client = await async_setup_auth(hass, aiohttp_client, [])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user