mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Use unique_id_mismatch in aseko_pool_live reauth (#128339)
This commit is contained in:
parent
c5046f7809
commit
9f2bdca9ad
@ -29,7 +29,7 @@ class AsekoConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get_account_info(self, email: str, password: str) -> dict:
|
async def get_account_info(self, email: str, password: str) -> dict[str, Any]:
|
||||||
"""Get account info from the mobile API and the web API."""
|
"""Get account info from the mobile API and the web API."""
|
||||||
aseko = Aseko(email, password)
|
aseko = Aseko(email, password)
|
||||||
user = await aseko.login()
|
user = await aseko.login()
|
||||||
@ -70,7 +70,9 @@ class AsekoConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
async def async_store_credentials(self, info: dict[str, Any]) -> ConfigFlowResult:
|
async def async_store_credentials(self, info: dict[str, Any]) -> ConfigFlowResult:
|
||||||
"""Store validated credentials."""
|
"""Store validated credentials."""
|
||||||
|
|
||||||
|
await self.async_set_unique_id(info[CONF_UNIQUE_ID])
|
||||||
if self.source == SOURCE_REAUTH:
|
if self.source == SOURCE_REAUTH:
|
||||||
|
self._abort_if_unique_id_mismatch()
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self._get_reauth_entry(),
|
self._get_reauth_entry(),
|
||||||
title=info[CONF_EMAIL],
|
title=info[CONF_EMAIL],
|
||||||
@ -80,7 +82,6 @@ class AsekoConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.async_set_unique_id(info[CONF_UNIQUE_ID])
|
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
|
@ -21,7 +21,8 @@
|
|||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]",
|
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]",
|
||||||
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
|
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]",
|
||||||
|
"unique_id_mismatch": "The user identifier does not match the previous identifier"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"entity": {
|
"entity": {
|
||||||
|
@ -128,8 +128,9 @@ async def test_async_step_reauth_success(hass: HomeAssistant, user: User) -> Non
|
|||||||
|
|
||||||
mock_entry = MockConfigEntry(
|
mock_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
unique_id="UID",
|
unique_id="a_user_id",
|
||||||
data={CONF_EMAIL: "aseko@example.com"},
|
data={CONF_EMAIL: "aseko@example.com", CONF_PASSWORD: "passw0rd"},
|
||||||
|
version=2,
|
||||||
)
|
)
|
||||||
mock_entry.add_to_hass(hass)
|
mock_entry.add_to_hass(hass)
|
||||||
|
|
||||||
@ -151,13 +152,61 @@ async def test_async_step_reauth_success(hass: HomeAssistant, user: User) -> Non
|
|||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_EMAIL: "aseko@example.com", CONF_PASSWORD: "passw0rd"},
|
{CONF_EMAIL: "aseko@example.com", CONF_PASSWORD: "new_password"},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "reauth_successful"
|
assert result["reason"] == "reauth_successful"
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
assert mock_entry.unique_id == "a_user_id"
|
||||||
|
assert dict(mock_entry.data) == {
|
||||||
|
CONF_EMAIL: "aseko@example.com",
|
||||||
|
CONF_PASSWORD: "new_password",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_step_reauth_mismatch(hass: HomeAssistant, user: User) -> None:
|
||||||
|
"""Test mismatch reauthentication."""
|
||||||
|
|
||||||
|
mock_entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
unique_id="UID",
|
||||||
|
data={CONF_EMAIL: "aseko@example.com", CONF_PASSWORD: "passw0rd"},
|
||||||
|
version=2,
|
||||||
|
)
|
||||||
|
mock_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
result = await mock_entry.start_reauth_flow(hass)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
assert result["step_id"] == "reauth_confirm"
|
||||||
|
assert result["errors"] == {}
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch(
|
||||||
|
"homeassistant.components.aseko_pool_live.config_flow.Aseko.login",
|
||||||
|
return_value=user,
|
||||||
|
),
|
||||||
|
patch(
|
||||||
|
"homeassistant.components.aseko_pool_live.async_setup_entry",
|
||||||
|
return_value=True,
|
||||||
|
) as mock_setup_entry,
|
||||||
|
):
|
||||||
|
result = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{CONF_EMAIL: "aseko@example.com", CONF_PASSWORD: "new_password"},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "unique_id_mismatch"
|
||||||
|
assert len(mock_setup_entry.mock_calls) == 0
|
||||||
|
assert mock_entry.unique_id == "UID"
|
||||||
|
assert dict(mock_entry.data) == {
|
||||||
|
CONF_EMAIL: "aseko@example.com",
|
||||||
|
CONF_PASSWORD: "passw0rd",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user