diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 2030c0abbef..d9094fb6316 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -1,4 +1,4 @@ -PyJWT==2.5.0 +PyJWT==2.6.0 PyNaCl==1.5.0 aiodiscover==1.4.13 aiohttp==3.8.1 diff --git a/pyproject.toml b/pyproject.toml index 7ac0909b990..556ca6c5ba4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ dependencies = [ "ifaddr==0.1.7", "jinja2==3.1.2", "lru-dict==1.1.8", - "PyJWT==2.5.0", + "PyJWT==2.6.0", # PyJWT has loose dependency. We want the latest one. "cryptography==38.0.3", "orjson==3.8.1", diff --git a/requirements.txt b/requirements.txt index b4f78582134..e16bf40f60c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ home-assistant-bluetooth==1.9.0 ifaddr==0.1.7 jinja2==3.1.2 lru-dict==1.1.8 -PyJWT==2.5.0 +PyJWT==2.6.0 cryptography==38.0.3 orjson==3.8.1 pip>=21.0,<22.4 diff --git a/tests/common.py b/tests/common.py index 69c569e445f..6420ed90749 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1347,3 +1347,15 @@ def raise_contains_mocks(val): if isinstance(val, list): for dict_value in val: 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) diff --git a/tests/conftest.py b/tests/conftest.py index dda31934f7b..26c1a1fd4a2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -45,7 +45,7 @@ from homeassistant.components.websocket_api.http import URL from homeassistant.const import HASSIO_USER_NAME from homeassistant.core import CoreState, HomeAssistant 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.util import dt as dt_util, location @@ -64,6 +64,7 @@ from tests.common import ( # noqa: E402, isort:skip get_test_home_assistant, init_recorder_component, mock_storage as mock_storage, + create_hass_access_token, ) from tests.test_util.aiohttp import mock_aiohttp_client # 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 async def hass_access_token(hass, hass_admin_user, hass_admin_credential): """Return an access token to access Home Assistant.""" - await hass.auth.async_link_user(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) + return await create_hass_access_token(hass, hass_admin_user, hass_admin_credential) @pytest.fixture @@ -575,13 +571,18 @@ def local_auth(hass): @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.""" async def auth_client(): """Return an authenticated client.""" + access_token = await create_hass_access_token( + hass, hass_admin_user, hass_admin_credential + ) 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 @@ -623,11 +624,17 @@ def current_request_with_host(current_request): @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.""" - async def create_client(hass=hass, access_token=hass_access_token): + async def create_client(hass=hass, access_token=UNDEFINED): """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", {}) client = await aiohttp_client(hass.http.app) websocket = await client.ws_connect(URL)