|
|
|
@ -1,225 +1,230 @@
|
|
|
|
|
"""Test the Aladdin Connect Garage Door config flow."""
|
|
|
|
|
|
|
|
|
|
from unittest.mock import AsyncMock
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from homeassistant.components.aladdin_connect.const import (
|
|
|
|
|
DOMAIN,
|
|
|
|
|
OAUTH2_AUTHORIZE,
|
|
|
|
|
OAUTH2_TOKEN,
|
|
|
|
|
)
|
|
|
|
|
from homeassistant.components.application_credentials import (
|
|
|
|
|
ClientCredential,
|
|
|
|
|
async_import_client_credential,
|
|
|
|
|
)
|
|
|
|
|
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER, ConfigFlowResult
|
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
from homeassistant.data_entry_flow import FlowResultType
|
|
|
|
|
from homeassistant.helpers import config_entry_oauth2_flow
|
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
|
|
|
from tests.typing import ClientSessionGenerator
|
|
|
|
|
|
|
|
|
|
CLIENT_ID = "1234"
|
|
|
|
|
CLIENT_SECRET = "5678"
|
|
|
|
|
|
|
|
|
|
EXAMPLE_TOKEN = (
|
|
|
|
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhYWFhYWFhYS1iYmJiLWNjY2MtZGRk"
|
|
|
|
|
"ZC1lZWVlZWVlZWVlZWUiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjIsInVzZXJuYW"
|
|
|
|
|
"1lIjoidGVzdEB0ZXN0LmNvbSJ9.CTU1YItIrUl8nSM3koJxlFJr5CjLghgc9gS6h45D8dE"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
async def setup_credentials(hass: HomeAssistant) -> None:
|
|
|
|
|
"""Fixture to setup credentials."""
|
|
|
|
|
assert await async_setup_component(hass, "application_credentials", {})
|
|
|
|
|
await async_import_client_credential(
|
|
|
|
|
hass,
|
|
|
|
|
DOMAIN,
|
|
|
|
|
ClientCredential(CLIENT_ID, CLIENT_SECRET),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def _oauth_actions(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
result: ConfigFlowResult,
|
|
|
|
|
hass_client_no_auth: ClientSessionGenerator,
|
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
|
) -> None:
|
|
|
|
|
state = config_entry_oauth2_flow._encode_jwt(
|
|
|
|
|
hass,
|
|
|
|
|
{
|
|
|
|
|
"flow_id": result["flow_id"],
|
|
|
|
|
"redirect_uri": "https://example.com/auth/external/callback",
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert result["url"] == (
|
|
|
|
|
f"{OAUTH2_AUTHORIZE}?response_type=code&client_id={CLIENT_ID}"
|
|
|
|
|
"&redirect_uri=https://example.com/auth/external/callback"
|
|
|
|
|
f"&state={state}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
client = await hass_client_no_auth()
|
|
|
|
|
resp = await client.get(f"/auth/external/callback?code=abcd&state={state}")
|
|
|
|
|
assert resp.status == 200
|
|
|
|
|
assert resp.headers["content-type"] == "text/html; charset=utf-8"
|
|
|
|
|
|
|
|
|
|
aioclient_mock.post(
|
|
|
|
|
OAUTH2_TOKEN,
|
|
|
|
|
json={
|
|
|
|
|
"refresh_token": "mock-refresh-token",
|
|
|
|
|
"access_token": EXAMPLE_TOKEN,
|
|
|
|
|
"type": "Bearer",
|
|
|
|
|
"expires_in": 60,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures("current_request_with_host")
|
|
|
|
|
async def test_full_flow(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
hass_client_no_auth: ClientSessionGenerator,
|
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
|
setup_credentials: None,
|
|
|
|
|
mock_setup_entry: AsyncMock,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Check full flow."""
|
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
|
)
|
|
|
|
|
await _oauth_actions(hass, result, hass_client_no_auth, aioclient_mock)
|
|
|
|
|
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
|
|
|
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
|
|
|
assert result["title"] == "test@test.com"
|
|
|
|
|
assert result["data"]["token"]["access_token"] == EXAMPLE_TOKEN
|
|
|
|
|
assert result["data"]["token"]["refresh_token"] == "mock-refresh-token"
|
|
|
|
|
assert result["result"].unique_id == "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
|
|
|
|
|
|
|
|
|
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures("current_request_with_host")
|
|
|
|
|
async def test_duplicate_entry(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
hass_client_no_auth: ClientSessionGenerator,
|
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
|
setup_credentials: None,
|
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test we abort with duplicate entry."""
|
|
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
|
)
|
|
|
|
|
await _oauth_actions(hass, result, hass_client_no_auth, aioclient_mock)
|
|
|
|
|
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
|
|
|
|
assert result["type"] is FlowResultType.ABORT
|
|
|
|
|
assert result["reason"] == "already_configured"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures("current_request_with_host")
|
|
|
|
|
async def test_reauth(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
hass_client_no_auth: ClientSessionGenerator,
|
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
|
setup_credentials: None,
|
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
|
mock_setup_entry: AsyncMock,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test reauthentication."""
|
|
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
|
DOMAIN,
|
|
|
|
|
context={
|
|
|
|
|
"source": SOURCE_REAUTH,
|
|
|
|
|
"entry_id": mock_config_entry.entry_id,
|
|
|
|
|
},
|
|
|
|
|
data=mock_config_entry.data,
|
|
|
|
|
)
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["step_id"] == "reauth_confirm"
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
|
|
|
|
await _oauth_actions(hass, result, hass_client_no_auth, aioclient_mock)
|
|
|
|
|
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
|
|
|
|
assert result["type"] is FlowResultType.ABORT
|
|
|
|
|
assert result["reason"] == "reauth_successful"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures("current_request_with_host")
|
|
|
|
|
async def test_reauth_wrong_account(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
hass_client_no_auth: ClientSessionGenerator,
|
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
|
setup_credentials: None,
|
|
|
|
|
mock_setup_entry: AsyncMock,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test reauthentication with wrong account."""
|
|
|
|
|
config_entry = MockConfigEntry(
|
|
|
|
|
domain=DOMAIN,
|
|
|
|
|
data={},
|
|
|
|
|
title="test@test.com",
|
|
|
|
|
unique_id="aaaaaaaa-bbbb-ffff-dddd-eeeeeeeeeeee",
|
|
|
|
|
version=2,
|
|
|
|
|
)
|
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
|
DOMAIN,
|
|
|
|
|
context={
|
|
|
|
|
"source": SOURCE_REAUTH,
|
|
|
|
|
"entry_id": config_entry.entry_id,
|
|
|
|
|
},
|
|
|
|
|
data=config_entry.data,
|
|
|
|
|
)
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["step_id"] == "reauth_confirm"
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
|
|
|
|
await _oauth_actions(hass, result, hass_client_no_auth, aioclient_mock)
|
|
|
|
|
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
|
|
|
|
assert result["type"] is FlowResultType.ABORT
|
|
|
|
|
assert result["reason"] == "wrong_account"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures("current_request_with_host")
|
|
|
|
|
async def test_reauth_old_account(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
hass_client_no_auth: ClientSessionGenerator,
|
|
|
|
|
aioclient_mock: AiohttpClientMocker,
|
|
|
|
|
setup_credentials: None,
|
|
|
|
|
mock_setup_entry: AsyncMock,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test reauthentication with old account."""
|
|
|
|
|
config_entry = MockConfigEntry(
|
|
|
|
|
domain=DOMAIN,
|
|
|
|
|
data={},
|
|
|
|
|
title="test@test.com",
|
|
|
|
|
unique_id="test@test.com",
|
|
|
|
|
version=2,
|
|
|
|
|
)
|
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
|
DOMAIN,
|
|
|
|
|
context={
|
|
|
|
|
"source": SOURCE_REAUTH,
|
|
|
|
|
"entry_id": config_entry.entry_id,
|
|
|
|
|
},
|
|
|
|
|
data=config_entry.data,
|
|
|
|
|
)
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["step_id"] == "reauth_confirm"
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
|
|
|
|
await _oauth_actions(hass, result, hass_client_no_auth, aioclient_mock)
|
|
|
|
|
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
|
|
|
|
assert result["type"] is FlowResultType.ABORT
|
|
|
|
|
assert result["reason"] == "reauth_successful"
|
|
|
|
|
assert config_entry.unique_id == "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
|
|
|
|
|
# from unittest.mock import AsyncMock
|
|
|
|
|
#
|
|
|
|
|
# import pytest
|
|
|
|
|
#
|
|
|
|
|
# from homeassistant.components.aladdin_connect.const import (
|
|
|
|
|
# DOMAIN,
|
|
|
|
|
# OAUTH2_AUTHORIZE,
|
|
|
|
|
# OAUTH2_TOKEN,
|
|
|
|
|
# )
|
|
|
|
|
# from homeassistant.components.application_credentials import (
|
|
|
|
|
# ClientCredential,
|
|
|
|
|
# async_import_client_credential,
|
|
|
|
|
# )
|
|
|
|
|
# from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER, ConfigFlowResult
|
|
|
|
|
# from homeassistant.core import HomeAssistant
|
|
|
|
|
# from homeassistant.data_entry_flow import FlowResultType
|
|
|
|
|
# from homeassistant.helpers import config_entry_oauth2_flow
|
|
|
|
|
# from homeassistant.setup import async_setup_component
|
|
|
|
|
#
|
|
|
|
|
# from tests.common import MockConfigEntry
|
|
|
|
|
# from tests.test_util.aiohttp import AiohttpClientMocker
|
|
|
|
|
# from tests.typing import ClientSessionGenerator
|
|
|
|
|
#
|
|
|
|
|
# CLIENT_ID = "1234"
|
|
|
|
|
# CLIENT_SECRET = "5678"
|
|
|
|
|
#
|
|
|
|
|
# EXAMPLE_TOKEN = (
|
|
|
|
|
# "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhYWFhYWFhYS1iYmJiLWNjY2MtZGRk"
|
|
|
|
|
# "ZC1lZWVlZWVlZWVlZWUiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjIsInVzZXJuYW"
|
|
|
|
|
# "1lIjoidGVzdEB0ZXN0LmNvbSJ9.CTU1YItIrUl8nSM3koJxlFJr5CjLghgc9gS6h45D8dE"
|
|
|
|
|
# )
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# @pytest.fixture
|
|
|
|
|
# async def setup_credentials(hass: HomeAssistant) -> None:
|
|
|
|
|
# """Fixture to setup credentials."""
|
|
|
|
|
# assert await async_setup_component(hass, "application_credentials", {})
|
|
|
|
|
# await async_import_client_credential(
|
|
|
|
|
# hass,
|
|
|
|
|
# DOMAIN,
|
|
|
|
|
# ClientCredential(CLIENT_ID, CLIENT_SECRET),
|
|
|
|
|
# )
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# async def _oauth_actions(
|
|
|
|
|
# hass: HomeAssistant,
|
|
|
|
|
# result: ConfigFlowResult,
|
|
|
|
|
# hass_client_no_auth: ClientSessionGenerator,
|
|
|
|
|
# aioclient_mock: AiohttpClientMocker,
|
|
|
|
|
# ) -> None:
|
|
|
|
|
# state = config_entry_oauth2_flow._encode_jwt(
|
|
|
|
|
# hass,
|
|
|
|
|
# {
|
|
|
|
|
# "flow_id": result["flow_id"],
|
|
|
|
|
# "redirect_uri": "https://example.com/auth/external/callback",
|
|
|
|
|
# },
|
|
|
|
|
# )
|
|
|
|
|
#
|
|
|
|
|
# assert result["url"] == (
|
|
|
|
|
# f"{OAUTH2_AUTHORIZE}?response_type=code&client_id={CLIENT_ID}"
|
|
|
|
|
# "&redirect_uri=https://example.com/auth/external/callback"
|
|
|
|
|
# f"&state={state}"
|
|
|
|
|
# )
|
|
|
|
|
#
|
|
|
|
|
# client = await hass_client_no_auth()
|
|
|
|
|
# resp = await client.get(f"/auth/external/callback?code=abcd&state={state}")
|
|
|
|
|
# assert resp.status == 200
|
|
|
|
|
# assert resp.headers["content-type"] == "text/html; charset=utf-8"
|
|
|
|
|
#
|
|
|
|
|
# aioclient_mock.post(
|
|
|
|
|
# OAUTH2_TOKEN,
|
|
|
|
|
# json={
|
|
|
|
|
# "refresh_token": "mock-refresh-token",
|
|
|
|
|
# "access_token": EXAMPLE_TOKEN,
|
|
|
|
|
# "type": "Bearer",
|
|
|
|
|
# "expires_in": 60,
|
|
|
|
|
# },
|
|
|
|
|
# )
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# @pytest.mark.skip(reason="Integration disabled")
|
|
|
|
|
# @pytest.mark.usefixtures("current_request_with_host")
|
|
|
|
|
# async def test_full_flow(
|
|
|
|
|
# hass: HomeAssistant,
|
|
|
|
|
# hass_client_no_auth: ClientSessionGenerator,
|
|
|
|
|
# aioclient_mock: AiohttpClientMocker,
|
|
|
|
|
# setup_credentials: None,
|
|
|
|
|
# mock_setup_entry: AsyncMock,
|
|
|
|
|
# ) -> None:
|
|
|
|
|
# """Check full flow."""
|
|
|
|
|
# result = await hass.config_entries.flow.async_init(
|
|
|
|
|
# DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
|
# )
|
|
|
|
|
# await _oauth_actions(hass, result, hass_client_no_auth, aioclient_mock)
|
|
|
|
|
#
|
|
|
|
|
# result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
|
|
|
|
# assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
|
|
|
# assert result["title"] == "test@test.com"
|
|
|
|
|
# assert result["data"]["token"]["access_token"] == EXAMPLE_TOKEN
|
|
|
|
|
# assert result["data"]["token"]["refresh_token"] == "mock-refresh-token"
|
|
|
|
|
# assert result["result"].unique_id == "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
|
|
|
|
|
#
|
|
|
|
|
# assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
|
|
|
|
# assert len(mock_setup_entry.mock_calls) == 1
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# @pytest.mark.skip(reason="Integration disabled")
|
|
|
|
|
# @pytest.mark.usefixtures("current_request_with_host")
|
|
|
|
|
# async def test_duplicate_entry(
|
|
|
|
|
# hass: HomeAssistant,
|
|
|
|
|
# hass_client_no_auth: ClientSessionGenerator,
|
|
|
|
|
# aioclient_mock: AiohttpClientMocker,
|
|
|
|
|
# setup_credentials: None,
|
|
|
|
|
# mock_config_entry: MockConfigEntry,
|
|
|
|
|
# ) -> None:
|
|
|
|
|
# """Test we abort with duplicate entry."""
|
|
|
|
|
# mock_config_entry.add_to_hass(hass)
|
|
|
|
|
# result = await hass.config_entries.flow.async_init(
|
|
|
|
|
# DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
|
# )
|
|
|
|
|
# await _oauth_actions(hass, result, hass_client_no_auth, aioclient_mock)
|
|
|
|
|
#
|
|
|
|
|
# result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
|
|
|
|
# assert result["type"] is FlowResultType.ABORT
|
|
|
|
|
# assert result["reason"] == "already_configured"
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# @pytest.mark.skip(reason="Integration disabled")
|
|
|
|
|
# @pytest.mark.usefixtures("current_request_with_host")
|
|
|
|
|
# async def test_reauth(
|
|
|
|
|
# hass: HomeAssistant,
|
|
|
|
|
# hass_client_no_auth: ClientSessionGenerator,
|
|
|
|
|
# aioclient_mock: AiohttpClientMocker,
|
|
|
|
|
# setup_credentials: None,
|
|
|
|
|
# mock_config_entry: MockConfigEntry,
|
|
|
|
|
# mock_setup_entry: AsyncMock,
|
|
|
|
|
# ) -> None:
|
|
|
|
|
# """Test reauthentication."""
|
|
|
|
|
# mock_config_entry.add_to_hass(hass)
|
|
|
|
|
# result = await hass.config_entries.flow.async_init(
|
|
|
|
|
# DOMAIN,
|
|
|
|
|
# context={
|
|
|
|
|
# "source": SOURCE_REAUTH,
|
|
|
|
|
# "entry_id": mock_config_entry.entry_id,
|
|
|
|
|
# },
|
|
|
|
|
# data=mock_config_entry.data,
|
|
|
|
|
# )
|
|
|
|
|
# assert result["type"] is FlowResultType.FORM
|
|
|
|
|
# assert result["step_id"] == "reauth_confirm"
|
|
|
|
|
# result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
|
|
|
|
# await _oauth_actions(hass, result, hass_client_no_auth, aioclient_mock)
|
|
|
|
|
#
|
|
|
|
|
# result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
|
|
|
|
# assert result["type"] is FlowResultType.ABORT
|
|
|
|
|
# assert result["reason"] == "reauth_successful"
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# @pytest.mark.skip(reason="Integration disabled")
|
|
|
|
|
# @pytest.mark.usefixtures("current_request_with_host")
|
|
|
|
|
# async def test_reauth_wrong_account(
|
|
|
|
|
# hass: HomeAssistant,
|
|
|
|
|
# hass_client_no_auth: ClientSessionGenerator,
|
|
|
|
|
# aioclient_mock: AiohttpClientMocker,
|
|
|
|
|
# setup_credentials: None,
|
|
|
|
|
# mock_setup_entry: AsyncMock,
|
|
|
|
|
# ) -> None:
|
|
|
|
|
# """Test reauthentication with wrong account."""
|
|
|
|
|
# config_entry = MockConfigEntry(
|
|
|
|
|
# domain=DOMAIN,
|
|
|
|
|
# data={},
|
|
|
|
|
# title="test@test.com",
|
|
|
|
|
# unique_id="aaaaaaaa-bbbb-ffff-dddd-eeeeeeeeeeee",
|
|
|
|
|
# version=2,
|
|
|
|
|
# )
|
|
|
|
|
# config_entry.add_to_hass(hass)
|
|
|
|
|
# result = await hass.config_entries.flow.async_init(
|
|
|
|
|
# DOMAIN,
|
|
|
|
|
# context={
|
|
|
|
|
# "source": SOURCE_REAUTH,
|
|
|
|
|
# "entry_id": config_entry.entry_id,
|
|
|
|
|
# },
|
|
|
|
|
# data=config_entry.data,
|
|
|
|
|
# )
|
|
|
|
|
# assert result["type"] is FlowResultType.FORM
|
|
|
|
|
# assert result["step_id"] == "reauth_confirm"
|
|
|
|
|
# result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
|
|
|
|
# await _oauth_actions(hass, result, hass_client_no_auth, aioclient_mock)
|
|
|
|
|
#
|
|
|
|
|
# result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
|
|
|
|
# assert result["type"] is FlowResultType.ABORT
|
|
|
|
|
# assert result["reason"] == "wrong_account"
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# @pytest.mark.skip(reason="Integration disabled")
|
|
|
|
|
# @pytest.mark.usefixtures("current_request_with_host")
|
|
|
|
|
# async def test_reauth_old_account(
|
|
|
|
|
# hass: HomeAssistant,
|
|
|
|
|
# hass_client_no_auth: ClientSessionGenerator,
|
|
|
|
|
# aioclient_mock: AiohttpClientMocker,
|
|
|
|
|
# setup_credentials: None,
|
|
|
|
|
# mock_setup_entry: AsyncMock,
|
|
|
|
|
# ) -> None:
|
|
|
|
|
# """Test reauthentication with old account."""
|
|
|
|
|
# config_entry = MockConfigEntry(
|
|
|
|
|
# domain=DOMAIN,
|
|
|
|
|
# data={},
|
|
|
|
|
# title="test@test.com",
|
|
|
|
|
# unique_id="test@test.com",
|
|
|
|
|
# version=2,
|
|
|
|
|
# )
|
|
|
|
|
# config_entry.add_to_hass(hass)
|
|
|
|
|
# result = await hass.config_entries.flow.async_init(
|
|
|
|
|
# DOMAIN,
|
|
|
|
|
# context={
|
|
|
|
|
# "source": SOURCE_REAUTH,
|
|
|
|
|
# "entry_id": config_entry.entry_id,
|
|
|
|
|
# },
|
|
|
|
|
# data=config_entry.data,
|
|
|
|
|
# )
|
|
|
|
|
# assert result["type"] is FlowResultType.FORM
|
|
|
|
|
# assert result["step_id"] == "reauth_confirm"
|
|
|
|
|
# result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
|
|
|
|
# await _oauth_actions(hass, result, hass_client_no_auth, aioclient_mock)
|
|
|
|
|
#
|
|
|
|
|
# result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
|
|
|
|
# assert result["type"] is FlowResultType.ABORT
|
|
|
|
|
# assert result["reason"] == "reauth_successful"
|
|
|
|
|
# assert config_entry.unique_id == "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
|
|
|
|
|