mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Verify cloud user exists during boot (#25119)
This commit is contained in:
parent
59f6fd7630
commit
8ec75cf883
@ -157,7 +157,13 @@ async def async_setup(hass, config):
|
|||||||
await prefs.async_initialize()
|
await prefs.async_initialize()
|
||||||
|
|
||||||
# Cloud user
|
# Cloud user
|
||||||
if not prefs.cloud_user:
|
user = None
|
||||||
|
if prefs.cloud_user:
|
||||||
|
# Fetch the user. It can happen that the user no longer exists if
|
||||||
|
# an image was restored without restoring the cloud prefs.
|
||||||
|
user = await hass.auth.async_get_user(prefs.cloud_user)
|
||||||
|
|
||||||
|
if user is None:
|
||||||
user = await hass.auth.async_create_system_user(
|
user = await hass.auth.async_create_system_user(
|
||||||
'Home Assistant Cloud', [GROUP_ID_ADMIN])
|
'Home Assistant Cloud', [GROUP_ID_ADMIN])
|
||||||
await prefs.async_update(cloud_user=user.id)
|
await prefs.async_update(cloud_user=user.id)
|
||||||
|
@ -127,6 +127,36 @@ async def test_setup_existing_cloud_user(hass, hass_storage):
|
|||||||
assert hass_storage[STORAGE_KEY]['data']['cloud_user'] == user.id
|
assert hass_storage[STORAGE_KEY]['data']['cloud_user'] == user.id
|
||||||
|
|
||||||
|
|
||||||
|
async def test_setup_invalid_cloud_user(hass, hass_storage):
|
||||||
|
"""Test setup with API push default data."""
|
||||||
|
hass_storage[STORAGE_KEY] = {
|
||||||
|
'version': 1,
|
||||||
|
'data': {
|
||||||
|
'cloud_user': 'non-existing'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
with patch('hass_nabucasa.Cloud.start', return_value=mock_coro()):
|
||||||
|
result = await async_setup_component(hass, 'cloud', {
|
||||||
|
'http': {},
|
||||||
|
'cloud': {
|
||||||
|
cloud.CONF_MODE: cloud.MODE_DEV,
|
||||||
|
'cognito_client_id': 'test-cognito_client_id',
|
||||||
|
'user_pool_id': 'test-user_pool_id',
|
||||||
|
'region': 'test-region',
|
||||||
|
'relayer': 'test-relayer',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
assert result
|
||||||
|
|
||||||
|
assert hass_storage[STORAGE_KEY]['data']['cloud_user'] != 'non-existing'
|
||||||
|
cloud_user = await hass.auth.async_get_user(
|
||||||
|
hass_storage[STORAGE_KEY]['data']['cloud_user']
|
||||||
|
)
|
||||||
|
|
||||||
|
assert cloud_user
|
||||||
|
assert cloud_user.groups[0].id == GROUP_ID_ADMIN
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_setup_cloud_user(hass, hass_storage):
|
async def test_setup_setup_cloud_user(hass, hass_storage):
|
||||||
"""Test setup with API push default data."""
|
"""Test setup with API push default data."""
|
||||||
hass_storage[STORAGE_KEY] = {
|
hass_storage[STORAGE_KEY] = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user