Add current user WS command (#15485)
This commit is contained in:
1 parent
55f8b0a2f5
commit
a14d8057ed
4 files changed
+62
-1
No files matched your search
@@ -2,6 +2,7 @@
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
from homeassistant.components import auth
|
||||
|
||||
@@ -66,3 +67,29 @@ def test_credential_store_expiration():
|
||||
with patch('homeassistant.util.dt.utcnow',
|
||||
return_value=now + timedelta(minutes=9, seconds=59)):
|
||||
assert retrieve(client_id, code) == credentials
|
||||
|
||||
|
||||
async def test_ws_current_user(hass, hass_ws_client, hass_access_token):
|
||||
"""Test the current user command."""
|
||||
assert await async_setup_component(hass, 'auth', {
|
||||
'http': {
|
||||
'api_password': 'bla'
|
||||
}
|
||||
})
|
||||
with patch('homeassistant.auth.AuthManager.active', return_value=True):
|
||||
client = await hass_ws_client(hass, hass_access_token)
|
||||
|
||||
await client.send_json({
|
||||
'id': 5,
|
||||
'type': auth.WS_TYPE_CURRENT_USER,
|
||||
})
|
||||
|
||||
result = await client.receive_json()
|
||||
assert result['success'], result
|
||||
|
||||
user = hass_access_token.refresh_token.user
|
||||
user_dict = result['result']
|
||||
|
||||
assert user_dict['name'] == user.name
|
||||
assert user_dict['id'] == user.id
|
||||
assert user_dict['is_owner'] == user.is_owner
|
||||
Reference in new issue
Block a user