Handle unexpected versions in forked_daapd zeroconf (#37053)

This commit is contained in:
uvjustin 2020-06-24 20:19:08 +08:00 committed by GitHub
parent e3b90ea3f7
commit 8d69a4968f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 6 deletions

View File

@ -156,14 +156,18 @@ class ForkedDaapdFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
async def async_step_zeroconf(self, discovery_info):
"""Prepare configuration for a discovered forked-daapd device."""
if not (
discovery_info.get("properties")
and int(discovery_info["properties"].get("mtd-version", "0").split(".")[0])
>= 27
and discovery_info["properties"].get("Machine Name")
version_num = 0
if discovery_info.get("properties") and discovery_info["properties"].get(
"Machine Name"
):
try:
version_num = int(
discovery_info["properties"].get("mtd-version", "0").split(".")[0]
)
except ValueError:
pass
if version_num < 27:
return self.async_abort(reason="not_forked_daapd")
await self.async_set_unique_id(discovery_info["properties"]["Machine Name"])
self._abort_if_unique_id_configured()

View File

@ -158,6 +158,17 @@ async def test_config_flow_zeroconf_invalid(hass):
) # doesn't create the entry, tries to show form but gets abort
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "not_forked_daapd"
# test with svn mtd-version from Firefly
discovery_info = {
"host": "127.0.0.1",
"port": 23,
"properties": {"mtd-version": "svn-1676", "Machine Name": "firefly"},
}
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info
) # doesn't create the entry, tries to show form but gets abort
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "not_forked_daapd"
async def test_config_flow_zeroconf_valid(hass):