Update Notion auth to store refresh tokens instead of account passwords (#109670)
This commit is contained in:
parent
92c3c401b9
commit
e3c838d512
12 changed files with 142 additions and 47 deletions
|
@ -17,6 +17,8 @@ from tests.common import MockConfigEntry, load_fixture
|
|||
|
||||
TEST_USERNAME = "user@host.com"
|
||||
TEST_PASSWORD = "password123"
|
||||
TEST_REFRESH_TOKEN = "abcde12345"
|
||||
TEST_USER_UUID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -47,6 +49,7 @@ def client_fixture(data_bridge, data_listener, data_sensor, data_user_preference
|
|||
]
|
||||
)
|
||||
),
|
||||
refresh_token=TEST_REFRESH_TOKEN,
|
||||
sensor=Mock(
|
||||
async_all=AsyncMock(
|
||||
return_value=[
|
||||
|
@ -61,6 +64,7 @@ def client_fixture(data_bridge, data_listener, data_sensor, data_user_preference
|
|||
)
|
||||
)
|
||||
),
|
||||
user_uuid=TEST_USER_UUID,
|
||||
)
|
||||
|
||||
|
||||
|
@ -107,7 +111,7 @@ def data_user_preferences_fixture():
|
|||
|
||||
@pytest.fixture(name="get_client")
|
||||
def get_client_fixture(client):
|
||||
"""Define a fixture to mock the async_get_client method."""
|
||||
"""Define a fixture to mock the client retrieval methods."""
|
||||
return AsyncMock(return_value=client)
|
||||
|
||||
|
||||
|
@ -115,10 +119,13 @@ def get_client_fixture(client):
|
|||
async def mock_aionotion_fixture(client):
|
||||
"""Define a fixture to patch aionotion."""
|
||||
with patch(
|
||||
"homeassistant.components.notion.async_get_client",
|
||||
"homeassistant.components.notion.async_get_client_with_credentials",
|
||||
AsyncMock(return_value=client),
|
||||
), patch(
|
||||
"homeassistant.components.notion.config_flow.async_get_client",
|
||||
"homeassistant.components.notion.async_get_client_with_refresh_token",
|
||||
AsyncMock(return_value=client),
|
||||
), patch(
|
||||
"homeassistant.components.notion.config_flow.async_get_client_with_credentials",
|
||||
AsyncMock(return_value=client),
|
||||
):
|
||||
yield
|
||||
|
|
|
@ -5,12 +5,12 @@ from aionotion.errors import InvalidCredentialsError, NotionError
|
|||
import pytest
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.notion import DOMAIN
|
||||
from homeassistant.components.notion import CONF_REFRESH_TOKEN, CONF_USER_UUID, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .conftest import TEST_PASSWORD, TEST_USERNAME
|
||||
from .conftest import TEST_REFRESH_TOKEN, TEST_USER_UUID, TEST_USERNAME
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
|
@ -40,7 +40,7 @@ async def test_create_entry(
|
|||
|
||||
# Test errors that can arise when getting a Notion API client:
|
||||
with patch(
|
||||
"homeassistant.components.notion.config_flow.async_get_client",
|
||||
"homeassistant.components.notion.config_flow.async_get_client_with_credentials",
|
||||
get_client_with_exception,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -55,8 +55,9 @@ async def test_create_entry(
|
|||
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == TEST_USERNAME
|
||||
assert result["data"] == {
|
||||
CONF_REFRESH_TOKEN: TEST_REFRESH_TOKEN,
|
||||
CONF_USERNAME: TEST_USERNAME,
|
||||
CONF_PASSWORD: TEST_PASSWORD,
|
||||
CONF_USER_UUID: TEST_USER_UUID,
|
||||
}
|
||||
|
||||
|
||||
|
@ -99,7 +100,7 @@ async def test_reauth(
|
|||
|
||||
# Test errors that can arise when getting a Notion API client:
|
||||
with patch(
|
||||
"homeassistant.components.notion.config_flow.async_get_client",
|
||||
"homeassistant.components.notion.config_flow.async_get_client_with_credentials",
|
||||
get_client_with_exception,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
|
|
|
@ -21,7 +21,11 @@ async def test_entry_diagnostics(
|
|||
"minor_version": 1,
|
||||
"domain": DOMAIN,
|
||||
"title": REDACTED,
|
||||
"data": {"username": REDACTED, "password": REDACTED},
|
||||
"data": {
|
||||
"refresh_token": REDACTED,
|
||||
"user_uuid": REDACTED,
|
||||
"username": REDACTED,
|
||||
},
|
||||
"options": {},
|
||||
"pref_disable_new_entities": False,
|
||||
"pref_disable_polling": False,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue