mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00: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:
parent
17c6ef5d54
commit
d2b62840f2
@ -185,6 +185,7 @@ class AuthManager:
|
|||||||
credentials=credentials,
|
credentials=credentials,
|
||||||
name=info.name,
|
name=info.name,
|
||||||
is_active=info.is_active,
|
is_active=info.is_active,
|
||||||
|
group_ids=[GROUP_ID_ADMIN],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.hass.bus.async_fire(EVENT_USER_ADDED, {
|
self.hass.bus.async_fire(EVENT_USER_ADDED, {
|
||||||
|
@ -870,3 +870,28 @@ async def test_async_remove_user(hass):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
assert events[0].data['user_id'] == user.id
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user