Foundation for users (#13968)

* Add initial user foundation to Home Assistant

* Address comments

* Address comments

* Allow non-ascii passwords

* One more utf-8 hmac compare digest

* Add new line
This commit is contained in:
Paulus Schoutsen 2018-05-01 12:20:41 -04:00 committed by Pascal Vizeli
parent b994c10d7f
commit cdd45e7878
22 changed files with 1774 additions and 59 deletions

View file

@ -10,7 +10,8 @@ import logging
import threading
from contextlib import contextmanager
from homeassistant import core as ha, loader, data_entry_flow, config_entries
from homeassistant import (
auth, core as ha, loader, data_entry_flow, config_entries)
from homeassistant.setup import setup_component, async_setup_component
from homeassistant.config import async_process_component_config
from homeassistant.helpers import (
@ -113,6 +114,9 @@ def async_test_home_assistant(loop):
hass.config_entries = config_entries.ConfigEntries(hass, {})
hass.config_entries._entries = []
hass.config.async_load = Mock()
store = auth.AuthStore(hass)
hass.auth = auth.AuthManager(hass, store, {})
ensure_auth_manager_loaded(hass.auth)
INSTANCES.append(hass)
orig_async_add_job = hass.async_add_job
@ -303,6 +307,34 @@ def mock_registry(hass, mock_entries=None):
return registry
class MockUser(auth.User):
"""Mock a user in Home Assistant."""
def __init__(self, id='mock-id', is_owner=True, is_active=True,
name='Mock User'):
"""Initialize mock user."""
super().__init__(id, is_owner, is_active, name)
def add_to_hass(self, hass):
"""Test helper to add entry to hass."""
return self.add_to_auth_manager(hass.auth)
def add_to_auth_manager(self, auth_mgr):
"""Test helper to add entry to hass."""
auth_mgr._store.users[self.id] = self
return self
@ha.callback
def ensure_auth_manager_loaded(auth_mgr):
"""Ensure an auth manager is considered loaded."""
store = auth_mgr._store
if store.clients is None:
store.clients = {}
if store.users is None:
store.users = {}
class MockModule(object):
"""Representation of a fake module."""