Ignore non-ASCII keys in zeroconf payloads (#34344)
* Ignore non-ASCII keys in zeroconf payloads * Don't rely on logging for test
This commit is contained in:
parent
2faa3af51f
commit
82784a320c
2 changed files with 21 additions and 4 deletions
|
@ -8,6 +8,14 @@ from homeassistant.components import zeroconf
|
|||
from homeassistant.generated import zeroconf as zc_gen
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
NON_UTF8_VALUE = b"ABCDEF\x8a"
|
||||
NON_ASCII_KEY = b"non-ascii-key\x8a"
|
||||
PROPERTIES = {
|
||||
b"macaddress": b"ABCDEF012345",
|
||||
b"non-utf8-value": NON_UTF8_VALUE,
|
||||
NON_ASCII_KEY: None,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_zeroconf():
|
||||
|
@ -31,7 +39,7 @@ def get_service_info_mock(service_type, name):
|
|||
weight=0,
|
||||
priority=0,
|
||||
server="name.local.",
|
||||
properties={b"macaddress": b"ABCDEF012345", b"non-utf8-value": b"ABCDEF\x8a"},
|
||||
properties=PROPERTIES,
|
||||
)
|
||||
|
||||
|
||||
|
@ -124,13 +132,15 @@ async def test_homekit_match_full(hass, mock_zeroconf):
|
|||
|
||||
|
||||
async def test_info_from_service_non_utf8(hass):
|
||||
"""Test info_from_service handles non UTF-8 property values correctly."""
|
||||
"""Test info_from_service handles non UTF-8 property keys and values correctly."""
|
||||
service_type = "_test._tcp.local."
|
||||
info = zeroconf.info_from_service(
|
||||
get_service_info_mock(service_type, f"test.{service_type}")
|
||||
)
|
||||
raw_info = info["properties"].pop("_raw", False)
|
||||
assert raw_info
|
||||
assert len(raw_info) == len(PROPERTIES) - 1
|
||||
assert NON_ASCII_KEY not in raw_info
|
||||
assert len(info["properties"]) <= len(raw_info)
|
||||
assert "non-utf8-value" not in info["properties"]
|
||||
assert raw_info["non-utf8-value"] is not None
|
||||
assert raw_info["non-utf8-value"] is NON_UTF8_VALUE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue