Compare commits
3 commits
dev
...
frenck-202
Author | SHA1 | Date | |
---|---|---|---|
|
af1fc922c6 | ||
|
1a992f1d2a | ||
|
f517b14b21 |
5 changed files with 33 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
||||||
PyJWT==2.5.0
|
PyJWT==2.6.0
|
||||||
PyNaCl==1.5.0
|
PyNaCl==1.5.0
|
||||||
aiodiscover==1.4.13
|
aiodiscover==1.4.13
|
||||||
aiohttp==3.8.1
|
aiohttp==3.8.1
|
||||||
|
|
|
@ -40,7 +40,7 @@ dependencies = [
|
||||||
"ifaddr==0.1.7",
|
"ifaddr==0.1.7",
|
||||||
"jinja2==3.1.2",
|
"jinja2==3.1.2",
|
||||||
"lru-dict==1.1.8",
|
"lru-dict==1.1.8",
|
||||||
"PyJWT==2.5.0",
|
"PyJWT==2.6.0",
|
||||||
# PyJWT has loose dependency. We want the latest one.
|
# PyJWT has loose dependency. We want the latest one.
|
||||||
"cryptography==38.0.3",
|
"cryptography==38.0.3",
|
||||||
"orjson==3.8.1",
|
"orjson==3.8.1",
|
||||||
|
|
|
@ -15,7 +15,7 @@ home-assistant-bluetooth==1.9.0
|
||||||
ifaddr==0.1.7
|
ifaddr==0.1.7
|
||||||
jinja2==3.1.2
|
jinja2==3.1.2
|
||||||
lru-dict==1.1.8
|
lru-dict==1.1.8
|
||||||
PyJWT==2.5.0
|
PyJWT==2.6.0
|
||||||
cryptography==38.0.3
|
cryptography==38.0.3
|
||||||
orjson==3.8.1
|
orjson==3.8.1
|
||||||
pip>=21.0,<22.4
|
pip>=21.0,<22.4
|
||||||
|
|
|
@ -1347,3 +1347,15 @@ def raise_contains_mocks(val):
|
||||||
if isinstance(val, list):
|
if isinstance(val, list):
|
||||||
for dict_value in val:
|
for dict_value in val:
|
||||||
raise_contains_mocks(dict_value)
|
raise_contains_mocks(dict_value)
|
||||||
|
|
||||||
|
|
||||||
|
async def create_hass_access_token(
|
||||||
|
hass: HomeAssistant, user: auth_models.User, credential: auth_models.Credentials
|
||||||
|
) -> str:
|
||||||
|
"""Return an access token to access Home Assistant."""
|
||||||
|
await hass.auth.async_link_user(user, credential)
|
||||||
|
|
||||||
|
refresh_token = await hass.auth.async_create_refresh_token(
|
||||||
|
user, CLIENT_ID, credential=credential
|
||||||
|
)
|
||||||
|
return hass.auth.async_create_access_token(refresh_token)
|
||||||
|
|
|
@ -45,7 +45,7 @@ from homeassistant.components.websocket_api.http import URL
|
||||||
from homeassistant.const import HASSIO_USER_NAME
|
from homeassistant.const import HASSIO_USER_NAME
|
||||||
from homeassistant.core import CoreState, HomeAssistant
|
from homeassistant.core import CoreState, HomeAssistant
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow, recorder as recorder_helper
|
from homeassistant.helpers import config_entry_oauth2_flow, recorder as recorder_helper
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import UNDEFINED, ConfigType
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import dt as dt_util, location
|
from homeassistant.util import dt as dt_util, location
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ from tests.common import ( # noqa: E402, isort:skip
|
||||||
get_test_home_assistant,
|
get_test_home_assistant,
|
||||||
init_recorder_component,
|
init_recorder_component,
|
||||||
mock_storage as mock_storage,
|
mock_storage as mock_storage,
|
||||||
|
create_hass_access_token,
|
||||||
)
|
)
|
||||||
from tests.test_util.aiohttp import mock_aiohttp_client # noqa: E402, isort:skip
|
from tests.test_util.aiohttp import mock_aiohttp_client # noqa: E402, isort:skip
|
||||||
from tests.components.recorder.common import ( # noqa: E402, isort:skip
|
from tests.components.recorder.common import ( # noqa: E402, isort:skip
|
||||||
|
@ -479,12 +480,7 @@ async def hass_admin_credential(hass, local_auth):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def hass_access_token(hass, hass_admin_user, hass_admin_credential):
|
async def hass_access_token(hass, hass_admin_user, hass_admin_credential):
|
||||||
"""Return an access token to access Home Assistant."""
|
"""Return an access token to access Home Assistant."""
|
||||||
await hass.auth.async_link_user(hass_admin_user, hass_admin_credential)
|
return await create_hass_access_token(hass, hass_admin_user, hass_admin_credential)
|
||||||
|
|
||||||
refresh_token = await hass.auth.async_create_refresh_token(
|
|
||||||
hass_admin_user, CLIENT_ID, credential=hass_admin_credential
|
|
||||||
)
|
|
||||||
return hass.auth.async_create_access_token(refresh_token)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -575,13 +571,18 @@ def local_auth(hass):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hass_client(hass, aiohttp_client, hass_access_token, socket_enabled):
|
def hass_client(
|
||||||
|
hass, aiohttp_client, hass_admin_user, hass_admin_credential, socket_enabled
|
||||||
|
):
|
||||||
"""Return an authenticated HTTP client."""
|
"""Return an authenticated HTTP client."""
|
||||||
|
|
||||||
async def auth_client():
|
async def auth_client():
|
||||||
"""Return an authenticated client."""
|
"""Return an authenticated client."""
|
||||||
|
access_token = await create_hass_access_token(
|
||||||
|
hass, hass_admin_user, hass_admin_credential
|
||||||
|
)
|
||||||
return await aiohttp_client(
|
return await aiohttp_client(
|
||||||
hass.http.app, headers={"Authorization": f"Bearer {hass_access_token}"}
|
hass.http.app, headers={"Authorization": f"Bearer {access_token}"}
|
||||||
)
|
)
|
||||||
|
|
||||||
return auth_client
|
return auth_client
|
||||||
|
@ -623,11 +624,17 @@ def current_request_with_host(current_request):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hass_ws_client(aiohttp_client, hass_access_token, hass, socket_enabled):
|
def hass_ws_client(
|
||||||
|
aiohttp_client, hass_admin_user, hass_admin_credential, hass, socket_enabled
|
||||||
|
):
|
||||||
"""Websocket client fixture connected to websocket server."""
|
"""Websocket client fixture connected to websocket server."""
|
||||||
|
|
||||||
async def create_client(hass=hass, access_token=hass_access_token):
|
async def create_client(hass=hass, access_token=UNDEFINED):
|
||||||
"""Create a websocket client."""
|
"""Create a websocket client."""
|
||||||
|
if access_token == UNDEFINED:
|
||||||
|
access_token = await create_hass_access_token(
|
||||||
|
hass, hass_admin_user, hass_admin_credential
|
||||||
|
)
|
||||||
assert await async_setup_component(hass, "websocket_api", {})
|
assert await async_setup_component(hass, "websocket_api", {})
|
||||||
client = await aiohttp_client(hass.http.app)
|
client = await aiohttp_client(hass.http.app)
|
||||||
websocket = await client.ws_connect(URL)
|
websocket = await client.ws_connect(URL)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue