Fix mqtt reconfigure does not use broker entry password when it is not changed (#137169)

This commit is contained in:
Jan Bouwhuis 2025-02-02 16:21:40 +01:00 committed by GitHub
parent cb3ed506ad
commit 839e2881e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 56 additions and 1 deletions

View File

@ -485,7 +485,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
errors,
):
if is_reconfigure:
update_password_from_user_input(
validated_user_input = update_password_from_user_input(
reconfigure_entry.data.get(CONF_PASSWORD), validated_user_input
)

View File

@ -2193,6 +2193,61 @@ async def test_reconfigure_flow_form(
await hass.async_block_till_done(wait_background_tasks=True)
@pytest.mark.usefixtures("mock_ssl_context", "mock_process_uploaded_file")
@pytest.mark.parametrize(
"mqtt_config_entry_data",
[
{
mqtt.CONF_BROKER: "test-broker",
CONF_USERNAME: "mqtt-user",
CONF_PASSWORD: "mqtt-password",
CONF_PORT: 1234,
mqtt.CONF_TRANSPORT: "websockets",
mqtt.CONF_WS_HEADERS: {"header_1": "custom_header1"},
mqtt.CONF_WS_PATH: "/some_path",
}
],
)
async def test_reconfigure_no_changed_password(
hass: HomeAssistant,
mock_try_connection: MagicMock,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None:
"""Test reconfigure flow."""
await mqtt_mock_entry()
entry: MockConfigEntry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
result = await entry.start_reconfigure_flow(hass, show_advanced_options=True)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "broker"
assert result["errors"] == {}
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
mqtt.CONF_BROKER: "10.10.10,10",
CONF_USERNAME: "mqtt-user",
CONF_PASSWORD: PWD_NOT_CHANGED,
CONF_PORT: 1234,
mqtt.CONF_TRANSPORT: "websockets",
mqtt.CONF_WS_HEADERS: '{"header_1": "custom_header1"}',
mqtt.CONF_WS_PATH: "/some_new_path",
},
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reconfigure_successful"
assert entry.data == {
mqtt.CONF_BROKER: "10.10.10,10",
CONF_USERNAME: "mqtt-user",
CONF_PASSWORD: "mqtt-password",
CONF_PORT: 1234,
mqtt.CONF_TRANSPORT: "websockets",
mqtt.CONF_WS_HEADERS: {"header_1": "custom_header1"},
mqtt.CONF_WS_PATH: "/some_new_path",
}
await hass.async_block_till_done(wait_background_tasks=True)
@pytest.mark.parametrize(
(
"version",