Prevent invalid data from being passed to zeroconf (#39009)
This commit is contained in:
parent
7c346c2f7c
commit
5a9246468e
2 changed files with 65 additions and 2 deletions
|
@ -102,6 +102,28 @@ async def test_setup(hass, mock_zeroconf):
|
|||
assert await hass.components.zeroconf.async_get_instance() is mock_zeroconf
|
||||
|
||||
|
||||
async def test_setup_with_overly_long_url_and_name(hass, mock_zeroconf, caplog):
|
||||
"""Test we still setup with long urls and names."""
|
||||
with patch.object(hass.config_entries.flow, "async_init"), patch.object(
|
||||
zeroconf, "HaServiceBrowser", side_effect=service_update_mock
|
||||
) as mock_service_browser, patch(
|
||||
"homeassistant.components.zeroconf.get_url",
|
||||
return_value="https://this.url.is.way.too.long/very/deep/path/that/will/make/us/go/over/the/maximum/string/length/and/would/cause/zeroconf/to/fail/to/startup/because/the/key/and/value/can/only/be/255/bytes/and/this/string/is/a/bit/longer/than/the/maximum/length/that/we/allow/for/a/value",
|
||||
), patch.object(
|
||||
hass.config,
|
||||
"location_name",
|
||||
"\u00dcBER \u00dcber German Umlaut long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string",
|
||||
):
|
||||
mock_zeroconf.get_service_info.side_effect = get_service_info_mock
|
||||
assert await async_setup_component(hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_service_browser.mock_calls) == 1
|
||||
assert "https://this.url.is.way.too.long" in caplog.text
|
||||
assert "German Umlaut" in caplog.text
|
||||
|
||||
|
||||
async def test_setup_with_default_interface(hass, mock_zeroconf):
|
||||
"""Test default interface config."""
|
||||
with patch.object(hass.config_entries.flow, "async_init"), patch.object(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue