mirror of
https://github.com/home-assistant/core.git
synced 2026-09-27 18:08:37 -04:00
Onboarding to generate auth code (#21777)
This commit is contained in:
@@ -8,7 +8,7 @@ from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import onboarding
|
||||
from homeassistant.components.onboarding import views
|
||||
|
||||
from tests.common import register_auth_provider
|
||||
from tests.common import CLIENT_ID, register_auth_provider
|
||||
|
||||
from . import mock_storage
|
||||
|
||||
@@ -59,6 +59,7 @@ async def test_onboarding_user_already_done(hass, hass_storage,
|
||||
client = await aiohttp_client(hass.http.app)
|
||||
|
||||
resp = await client.post('/api/onboarding/users', json={
|
||||
'client_id': CLIENT_ID,
|
||||
'name': 'Test Name',
|
||||
'username': 'test-user',
|
||||
'password': 'test-pass',
|
||||
@@ -79,12 +80,16 @@ async def test_onboarding_user(hass, hass_storage, aiohttp_client):
|
||||
client = await aiohttp_client(hass.http.app)
|
||||
|
||||
resp = await client.post('/api/onboarding/users', json={
|
||||
'client_id': CLIENT_ID,
|
||||
'name': 'Test Name',
|
||||
'username': 'test-user',
|
||||
'password': 'test-pass',
|
||||
})
|
||||
|
||||
assert resp.status == 200
|
||||
data = await resp.json()
|
||||
assert 'auth_code' in data
|
||||
|
||||
users = await hass.auth.async_get_users()
|
||||
assert len(users) == 1
|
||||
user = users[0]
|
||||
@@ -93,6 +98,21 @@ async def test_onboarding_user(hass, hass_storage, aiohttp_client):
|
||||
assert user.credentials[0].data['username'] == 'test-user'
|
||||
assert len(hass.data['person'].storage_data) == 1
|
||||
|
||||
# Request refresh tokens
|
||||
resp = await client.post('/auth/token', data={
|
||||
'client_id': CLIENT_ID,
|
||||
'grant_type': 'authorization_code',
|
||||
'code': data['auth_code']
|
||||
})
|
||||
|
||||
assert resp.status == 200
|
||||
tokens = await resp.json()
|
||||
|
||||
assert (
|
||||
await hass.auth.async_validate_access_token(tokens['access_token'])
|
||||
is not None
|
||||
)
|
||||
|
||||
|
||||
async def test_onboarding_user_invalid_name(hass, hass_storage,
|
||||
aiohttp_client):
|
||||
@@ -106,6 +126,7 @@ async def test_onboarding_user_invalid_name(hass, hass_storage,
|
||||
client = await aiohttp_client(hass.http.app)
|
||||
|
||||
resp = await client.post('/api/onboarding/users', json={
|
||||
'client_id': CLIENT_ID,
|
||||
'username': 'test-user',
|
||||
'password': 'test-pass',
|
||||
})
|
||||
@@ -124,11 +145,13 @@ async def test_onboarding_user_race(hass, hass_storage, aiohttp_client):
|
||||
client = await aiohttp_client(hass.http.app)
|
||||
|
||||
resp1 = client.post('/api/onboarding/users', json={
|
||||
'client_id': CLIENT_ID,
|
||||
'name': 'Test 1',
|
||||
'username': '1-user',
|
||||
'password': '1-pass',
|
||||
})
|
||||
resp2 = client.post('/api/onboarding/users', json={
|
||||
'client_id': CLIENT_ID,
|
||||
'name': 'Test 2',
|
||||
'username': '2-user',
|
||||
'password': '2-pass',
|
||||
|
||||
Reference in New Issue
Block a user