mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Abort reauth flows on config entry reload (#140931)
* Abort reauth flows on config entry reload
* Don't cancel reauth when reload is triggered by a reauth flow
* Revert "Don't cancel reauth when reload is triggered by a reauth flow"
This reverts commit f37c75621e.
* Don't fail in FlowManager._async_handle_step when the flow was aborted
* Update tplink config flow
* Add tests
* Don't allow create_entry from an aborted flow
* Add comment
* Adjust after merge with dev
This commit is contained in:
@@ -695,7 +695,7 @@ async def test_remove_entry_cancels_reauth(
|
||||
manager: config_entries.ConfigEntries,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
"""Tests that removing a config entry, also aborts existing reauth flows."""
|
||||
"""Tests that removing a config entry also aborts existing reauth flows."""
|
||||
entry = MockConfigEntry(title="test_title", domain="test")
|
||||
|
||||
mock_setup_entry = AsyncMock(side_effect=ConfigEntryAuthFailed())
|
||||
@@ -722,6 +722,40 @@ async def test_remove_entry_cancels_reauth(
|
||||
assert not issue_registry.async_get_issue(HOMEASSISTANT_DOMAIN, issue_id)
|
||||
|
||||
|
||||
async def test_reload_entry_cancels_reauth(
|
||||
hass: HomeAssistant,
|
||||
manager: config_entries.ConfigEntries,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
"""Tests that reloading a config entry also aborts existing reauth flows."""
|
||||
entry = MockConfigEntry(title="test_title", domain="test")
|
||||
|
||||
mock_setup_entry = AsyncMock(side_effect=ConfigEntryAuthFailed())
|
||||
mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry))
|
||||
mock_platform(hass, "test.config_flow", None)
|
||||
|
||||
entry.add_to_hass(hass)
|
||||
await manager.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
flows = hass.config_entries.flow.async_progress_by_handler("test")
|
||||
assert len(flows) == 1
|
||||
assert flows[0]["context"]["entry_id"] == entry.entry_id
|
||||
assert flows[0]["context"]["source"] == config_entries.SOURCE_REAUTH
|
||||
assert entry.state is config_entries.ConfigEntryState.SETUP_ERROR
|
||||
|
||||
issue_id = f"config_entry_reauth_test_{entry.entry_id}"
|
||||
assert issue_registry.async_get_issue(HOMEASSISTANT_DOMAIN, issue_id)
|
||||
|
||||
mock_setup_entry.return_value = True
|
||||
mock_setup_entry.side_effect = None
|
||||
await manager.async_reload(entry.entry_id)
|
||||
|
||||
flows = hass.config_entries.flow.async_progress_by_handler("test")
|
||||
assert len(flows) == 0
|
||||
assert not issue_registry.async_get_issue(HOMEASSISTANT_DOMAIN, issue_id)
|
||||
|
||||
|
||||
async def test_remove_entry_handles_callback_error(
|
||||
hass: HomeAssistant, manager: config_entries.ConfigEntries
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user