mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 00:37:13 +00:00
Ensure SimpliSafe re-auth only looks at SimpliSafe config entries (#71009)
* Ensure SimpliSafe re-auth only looks at SimpliSafe config entries * Add a test * Trigger Build * Linting * Comment * Simplify test
This commit is contained in:
parent
ce9d000cd8
commit
d0f1168ff0
@ -126,7 +126,8 @@ class SimpliSafeFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
if existing_entries := [
|
if existing_entries := [
|
||||||
entry
|
entry
|
||||||
for entry in self.hass.config_entries.async_entries()
|
for entry in self.hass.config_entries.async_entries()
|
||||||
if entry.unique_id in (self._username, user_id)
|
if entry.domain == DOMAIN
|
||||||
|
and entry.unique_id in (self._username, user_id)
|
||||||
]:
|
]:
|
||||||
existing_entry = existing_entries[0]
|
existing_entry = existing_entries[0]
|
||||||
self.hass.config_entries.async_update_entry(
|
self.hass.config_entries.async_update_entry(
|
||||||
|
@ -12,6 +12,8 @@ from homeassistant.const import CONF_CODE, CONF_TOKEN, CONF_USERNAME
|
|||||||
|
|
||||||
from .common import REFRESH_TOKEN, USER_ID, USERNAME
|
from .common import REFRESH_TOKEN, USER_ID, USERNAME
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
CONF_USER_ID = "user_id"
|
CONF_USER_ID = "user_id"
|
||||||
|
|
||||||
|
|
||||||
@ -57,9 +59,15 @@ async def test_options_flow(hass, config_entry):
|
|||||||
|
|
||||||
@pytest.mark.parametrize("unique_id", [USERNAME, USER_ID])
|
@pytest.mark.parametrize("unique_id", [USERNAME, USER_ID])
|
||||||
async def test_step_reauth(
|
async def test_step_reauth(
|
||||||
hass, config, config_entry, reauth_config, setup_simplisafe, sms_config
|
hass, config, config_entry, reauth_config, setup_simplisafe, sms_config, unique_id
|
||||||
):
|
):
|
||||||
"""Test the re-auth step (testing both username and user ID as unique ID)."""
|
"""Test the re-auth step (testing both username and user ID as unique ID)."""
|
||||||
|
# Add a second config entry (tied to a random domain, but with the same unique ID
|
||||||
|
# that could exist in a SimpliSafe entry) to ensure that this reauth process only
|
||||||
|
# touches the SimpliSafe entry:
|
||||||
|
entry = MockConfigEntry(domain="random", unique_id=USERNAME, data={"some": "data"})
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_REAUTH}, data=config
|
DOMAIN, context={"source": SOURCE_REAUTH}, data=config
|
||||||
)
|
)
|
||||||
@ -78,11 +86,17 @@ async def test_step_reauth(
|
|||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "reauth_successful"
|
assert result["reason"] == "reauth_successful"
|
||||||
|
|
||||||
assert len(hass.config_entries.async_entries()) == 1
|
assert len(hass.config_entries.async_entries()) == 2
|
||||||
|
|
||||||
|
# Test that the SimpliSafe config flow is updated:
|
||||||
[config_entry] = hass.config_entries.async_entries(DOMAIN)
|
[config_entry] = hass.config_entries.async_entries(DOMAIN)
|
||||||
assert config_entry.unique_id == USER_ID
|
assert config_entry.unique_id == USER_ID
|
||||||
assert config_entry.data == config
|
assert config_entry.data == config
|
||||||
|
|
||||||
|
# Test that the non-SimpliSafe config flow remains the same:
|
||||||
|
[config_entry] = hass.config_entries.async_entries("random")
|
||||||
|
assert config_entry == entry
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"exc,error_string",
|
"exc,error_string",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user