Skip to content

Commit d0f5a60

Browse files
authored
Add test coverage to ensure ServiceInfo rejects expired records (#468)
1 parent 00af5ad commit d0f5a60

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

zeroconf/test.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,46 @@ def test_service_info_rejects_non_matching_updates(self):
17111711
assert new_address not in info.addresses
17121712
zc.close()
17131713

1714+
def test_service_info_rejects_expired_records(self):
1715+
"""Verify records that are expired are rejected."""
1716+
zc = r.Zeroconf(interfaces=['127.0.0.1'])
1717+
desc = {'path': '/~paulsm/'}
1718+
service_name = 'name._type._tcp.local.'
1719+
service_type = '_type._tcp.local.'
1720+
service_server = 'ash-1.local.'
1721+
service_address = socket.inet_aton("10.0.1.2")
1722+
ttl = 120
1723+
now = r.current_time_millis()
1724+
info = ServiceInfo(
1725+
service_type, service_name, 22, 0, 0, desc, service_server, addresses=[service_address]
1726+
)
1727+
# Matching updates
1728+
info.update_record(
1729+
zc,
1730+
now,
1731+
r.DNSText(
1732+
service_name,
1733+
r._TYPE_TXT,
1734+
r._CLASS_IN | r._CLASS_UNIQUE,
1735+
ttl,
1736+
b'\x04ff=0\x04ci=2\x04sf=0\x0bsh=6fLM5A==',
1737+
),
1738+
)
1739+
assert info.properties[b"ci"] == b"2"
1740+
# Expired record
1741+
expired_record = r.DNSText(
1742+
service_name,
1743+
r._TYPE_TXT,
1744+
r._CLASS_IN | r._CLASS_UNIQUE,
1745+
ttl,
1746+
b'\x04ff=0\x04ci=3\x04sf=0\x0bsh=6fLM5A==',
1747+
)
1748+
expired_record.created = 1000
1749+
expired_record._expiration_time = 1000
1750+
info.update_record(zc, now, expired_record)
1751+
assert info.properties[b"ci"] == b"2"
1752+
zc.close()
1753+
17141754
def test_get_info_partial(self):
17151755

17161756
zc = r.Zeroconf(interfaces=['127.0.0.1'])

0 commit comments

Comments
 (0)