Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions homeassistant/components/auth/login_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"version": 1
}
"""
import aiohttp.web
from aiohttp import web
import voluptuous as vol

from homeassistant import data_entry_flow
Expand Down Expand Up @@ -95,11 +95,20 @@ class AuthProvidersView(HomeAssistantView):

async def get(self, request):
"""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([{
'name': provider.name,
'id': provider.id,
'type': provider.type,
} for provider in request.app['hass'].auth.auth_providers])
} for provider in hass.auth.auth_providers])


def _prepare_result_json(result):
Expand Down Expand Up @@ -139,7 +148,7 @@ def __init__(self, flow_mgr):

async def get(self, request):
"""Do not allow index of flows in progress."""
return aiohttp.web.Response(status=405)
return web.Response(status=405)

@RequestDataValidator(vol.Schema({
vol.Required('client_id'): str,
Expand Down
15 changes: 15 additions & 0 deletions tests/components/auth/test_login_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Tests for the login flow."""
from unittest.mock import patch

from . import async_setup_auth

from tests.common import CLIENT_ID, CLIENT_REDIRECT_URI
Expand All @@ -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):
"""Test we cannot get flows in progress."""
client = await async_setup_auth(hass, aiohttp_client, [])
Expand Down