Skip to content

Commit 0ab8f28

Browse files
committed
coverage
1 parent 4ea3c5f commit 0ab8f28

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

tests/utils/test_name.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,27 @@
1010
from zeroconf import BadTypeInNameException
1111

1212

13-
def test_service_type_name():
14-
"""Test overlong service_type_name."""
13+
def test_service_type_name_overlong_type():
14+
"""Test overlong service_type_name type."""
1515
with pytest.raises(BadTypeInNameException):
1616
nameutils.service_type_name("Tivo1._tivo-videostream._tcp.local.")
1717
nameutils.service_type_name("Tivo1._tivo-videostream._tcp.local.", strict=False)
18+
19+
20+
def test_service_type_name_overlong_full_name():
21+
"""Test overlong service_type_name full name."""
22+
with pytest.raises(BadTypeInNameException):
23+
nameutils.service_type_name(
24+
"Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1"
25+
"Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1"
26+
"Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1"
27+
"._tivo-videostream._tcp.local."
28+
)
29+
with pytest.raises(BadTypeInNameException):
30+
nameutils.service_type_name(
31+
"Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1"
32+
"Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1"
33+
"Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1Tivo1"
34+
"._tivo-videostream._tcp.local.",
35+
strict=False,
36+
)

zeroconf/_utils/name.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ def service_type_name(type_: str, *, strict: bool = True) -> str: # pylint: dis
7474
:param type_: Type, SubType or service name to validate
7575
:return: fully qualified service name (eg: _http._tcp.local.)
7676
"""
77+
if len(type_) > 256:
78+
# https://datatracker.ietf.org/doc/html/rfc6763#section-7.2
79+
raise BadTypeInNameException("Full name (%s) must be > 256 bytes" % type_)
7780

7881
if type_.endswith((_TCP_PROTOCOL_LOCAL_TRAILER, _NONTCP_PROTOCOL_LOCAL_TRAILER)):
7982
remaining = type_[: -len(_TCP_PROTOCOL_LOCAL_TRAILER)].split('.')

0 commit comments

Comments
 (0)