Skip to content

Commit

Permalink
Add users added via credentials to admin group too (home-assistant#18922
Browse files Browse the repository at this point in the history
)

* Add users added via credentials to admin group too

* Update test_init.py
  • Loading branch information
balloob authored Dec 3, 2018
1 parent 17c6ef5 commit d2b6284
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions homeassistant/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ async def async_get_or_create_user(self, credentials: models.Credentials) \
credentials=credentials,
name=info.name,
is_active=info.is_active,
group_ids=[GROUP_ID_ADMIN],
)

self.hass.bus.async_fire(EVENT_USER_ADDED, {
Expand Down
25 changes: 25 additions & 0 deletions tests/auth/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,3 +870,28 @@ def user_removed(event):
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

0 comments on commit d2b6284

Please sign in to comment.