* Backend tweaks to make authorization work * Lint * Add test * Validate redirect uris * Fix tests * Fix tests * Lint
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
"""Tests for the auth component."""
|
|
from aiohttp.helpers import BasicAuth
|
|
|
|
from homeassistant import auth
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
from tests.common import ensure_auth_manager_loaded
|
|
|
|
|
|
BASE_CONFIG = [{
|
|
'name': 'Example',
|
|
'type': 'insecure_example',
|
|
'users': [{
|
|
'username': 'test-user',
|
|
'password': 'test-pass',
|
|
'name': 'Test Name'
|
|
}]
|
|
}]
|
|
CLIENT_ID = 'test-id'
|
|
CLIENT_SECRET = 'test-secret'
|
|
CLIENT_AUTH = BasicAuth(CLIENT_ID, CLIENT_SECRET)
|
|
CLIENT_REDIRECT_URI = 'http://example.com/callback'
|
|
|
|
|
|
async def async_setup_auth(hass, aiohttp_client, provider_configs=BASE_CONFIG,
|
|
setup_api=False):
|
|
"""Helper to setup authentication and create a HTTP client."""
|
|
hass.auth = await auth.auth_manager_from_config(hass, provider_configs)
|
|
ensure_auth_manager_loaded(hass.auth)
|
|
await async_setup_component(hass, 'auth', {
|
|
'http': {
|
|
'api_password': 'bla'
|
|
}
|
|
})
|
|
client = auth.Client('Test Client', CLIENT_ID, CLIENT_SECRET,
|
|
redirect_uris=[CLIENT_REDIRECT_URI])
|
|
hass.auth._store.clients[client.id] = client
|
|
if setup_api:
|
|
await async_setup_component(hass, 'api', {})
|
|
return await aiohttp_client(hass.http.app)
|