mirror of
https://github.com/home-assistant/core.git
synced 2025-12-25 05:26:47 +00:00
Refactor KNX config flow and validate user input (#69698)
* validate config flow user input * test flow for invalid user input * validate multicast address blocks * Update homeassistant/components/knx/config_flow.py Co-authored-by: Marvin Wichmann <me@marvin-wichmann.de> Co-authored-by: Marvin Wichmann <me@marvin-wichmann.de>
This commit is contained in:
@@ -150,6 +150,26 @@ async def test_routing_setup_advanced(hass: HomeAssistant) -> None:
|
||||
assert result2["step_id"] == "routing"
|
||||
assert not result2["errors"]
|
||||
|
||||
# invalid user input
|
||||
result_invalid_input = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"],
|
||||
{
|
||||
CONF_KNX_MCAST_GRP: "10.1.2.3", # no valid multicast group
|
||||
CONF_KNX_MCAST_PORT: 3675,
|
||||
CONF_KNX_INDIVIDUAL_ADDRESS: "not_a_valid_address",
|
||||
CONF_KNX_LOCAL_IP: "no_local_ip",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result_invalid_input["type"] == RESULT_TYPE_FORM
|
||||
assert result_invalid_input["step_id"] == "routing"
|
||||
assert result_invalid_input["errors"] == {
|
||||
CONF_KNX_MCAST_GRP: "invalid_ip_address",
|
||||
CONF_KNX_INDIVIDUAL_ADDRESS: "invalid_individual_address",
|
||||
CONF_KNX_LOCAL_IP: "invalid_ip_address",
|
||||
}
|
||||
|
||||
# valid user input
|
||||
with patch(
|
||||
"homeassistant.components.knx.async_setup_entry",
|
||||
return_value=True,
|
||||
@@ -297,6 +317,36 @@ async def test_tunneling_setup_for_local_ip(hass: HomeAssistant) -> None:
|
||||
assert result2["step_id"] == "manual_tunnel"
|
||||
assert not result2["errors"]
|
||||
|
||||
# invalid host ip address
|
||||
result_invalid_host = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"],
|
||||
{
|
||||
CONF_KNX_TUNNELING_TYPE: CONF_KNX_LABEL_TUNNELING_UDP,
|
||||
CONF_HOST: DEFAULT_MCAST_GRP, # multicast addresses are invalid
|
||||
CONF_PORT: 3675,
|
||||
CONF_KNX_LOCAL_IP: "192.168.1.112",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result_invalid_host["type"] == RESULT_TYPE_FORM
|
||||
assert result_invalid_host["step_id"] == "manual_tunnel"
|
||||
assert result_invalid_host["errors"] == {CONF_HOST: "invalid_ip_address"}
|
||||
# invalid local ip address
|
||||
result_invalid_local = await hass.config_entries.flow.async_configure(
|
||||
result2["flow_id"],
|
||||
{
|
||||
CONF_KNX_TUNNELING_TYPE: CONF_KNX_LABEL_TUNNELING_UDP,
|
||||
CONF_HOST: "192.168.0.2",
|
||||
CONF_PORT: 3675,
|
||||
CONF_KNX_LOCAL_IP: "asdf",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result_invalid_local["type"] == RESULT_TYPE_FORM
|
||||
assert result_invalid_local["step_id"] == "manual_tunnel"
|
||||
assert result_invalid_local["errors"] == {CONF_KNX_LOCAL_IP: "invalid_ip_address"}
|
||||
|
||||
# valid user input
|
||||
with patch(
|
||||
"homeassistant.components.knx.async_setup_entry",
|
||||
return_value=True,
|
||||
@@ -584,7 +634,7 @@ async def test_configure_secure_knxkeys_file_not_found(hass: HomeAssistant):
|
||||
await hass.async_block_till_done()
|
||||
assert secure_knxkeys["type"] == RESULT_TYPE_FORM
|
||||
assert secure_knxkeys["errors"]
|
||||
assert secure_knxkeys["errors"]["base"] == "file_not_found"
|
||||
assert secure_knxkeys["errors"][CONF_KNX_KNXKEY_FILENAME] == "file_not_found"
|
||||
|
||||
|
||||
async def test_configure_secure_knxkeys_invalid_signature(hass: HomeAssistant):
|
||||
@@ -613,7 +663,7 @@ async def test_configure_secure_knxkeys_invalid_signature(hass: HomeAssistant):
|
||||
await hass.async_block_till_done()
|
||||
assert secure_knxkeys["type"] == RESULT_TYPE_FORM
|
||||
assert secure_knxkeys["errors"]
|
||||
assert secure_knxkeys["errors"]["base"] == "invalid_signature"
|
||||
assert secure_knxkeys["errors"][CONF_KNX_KNXKEY_PASSWORD] == "invalid_signature"
|
||||
|
||||
|
||||
async def test_options_flow(
|
||||
|
||||
Reference in New Issue
Block a user