1
mirror of https://github.com/home-assistant/core synced 2024-10-01 05:30:36 +02:00

Add users added via credentials to admin group too (#18922)

* Add users added via credentials to admin group too

* Update test_init.py
This commit is contained in:
Paulus Schoutsen 2018-12-03 11:34:01 +01:00 committed by GitHub
parent 17c6ef5d54
commit d2b62840f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -185,6 +185,7 @@ class AuthManager:
credentials=credentials,
name=info.name,
is_active=info.is_active,
group_ids=[GROUP_ID_ADMIN],
)
self.hass.bus.async_fire(EVENT_USER_ADDED, {

View File

@ -870,3 +870,28 @@ async def test_async_remove_user(hass):
await hass.async_block_till_done()
assert len(events) == 1
assert events[0].data['user_id'] == user.id
async def test_new_users_admin(mock_hass):
"""Test newly created users are admin."""
manager = await auth.auth_manager_from_config(mock_hass, [{
'type': 'insecure_example',
'users': [{
'username': 'test-user',
'password': 'test-pass',
'name': 'Test Name'
}]
}], [])
ensure_auth_manager_loaded(manager)
user = await manager.async_create_user('Hello')
assert user.is_admin
user_cred = await manager.async_get_or_create_user(auth_models.Credentials(
id='mock-id',
auth_provider_type='insecure_example',
auth_provider_id=None,
data={'username': 'test-user'},
is_new=True,
))
assert user_cred.is_admin