Skip to content

Commit 38b1517

Browse files
committed
test: pin DNSNsec flood is bounded by _MAX_CACHE_RECORDS
The ``new = is_new and not isinstance(record, DNSNsec)`` line in ``_async_add`` only gates the listener-notify return value — the counter increment, the cache store, and the cap check are all type-agnostic. A peer can't flood NSec records past the cap today. But the existing ``new`` flag is exactly the shape a future refactor might extend to ``_total_records`` ("DNSNsec isn't real data, don't count it"), which would silently open a bypass. Pin ``_total_records == _MAX_CACHE_RECORDS`` after pushing ``_MAX_CACHE_RECORDS + 100`` unique-name DNSNsec records so any such regression fails this test loudly.
1 parent a2a2d34 commit 38b1517

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎tests/test_cache.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,26 @@ def test_cache_eviction_victim_shares_key_with_new_record() -> None:
583583
assert total == cache._total_records
584584

585585

586+
def test_cache_dnsnsec_flood_is_bounded() -> None:
587+
"""DNSNsec records honour ``_MAX_CACHE_RECORDS`` (no bypass via the ``new`` flag)."""
588+
cache = r.DNSCache()
589+
overflow = 100
590+
cache.async_add_records(
591+
r.DNSNsec(
592+
f"nsec-{i}.local.",
593+
const._TYPE_NSEC,
594+
const._CLASS_IN,
595+
120,
596+
f"nsec-{i}.local.",
597+
[const._TYPE_A],
598+
)
599+
for i in range(const._MAX_CACHE_RECORDS + overflow)
600+
)
601+
assert cache._total_records == const._MAX_CACHE_RECORDS
602+
total = sum(len(store) for store in cache.cache.values())
603+
assert total == const._MAX_CACHE_RECORDS
604+
605+
586606
def test_cache_re_add_flood_does_not_grow_heap_unbounded() -> None:
587607
"""Replaying cached records with shifting TTLs cannot grow ``_expire_heap`` unbounded."""
588608
cache = r.DNSCache()

0 commit comments

Comments
 (0)