add NetworkValueRejectlistFilter and NetworkValueAllowlistFilter processors

This commit is contained in:
Solvik Blum
2023-11-09 15:24:03 +01:00
parent f5fcb1ae8a
commit f5fd68bb7e
2 changed files with 119 additions and 0 deletions
+34
View File
@@ -9,6 +9,8 @@ from octodns.processor.filter import (
IgnoreRootNsFilter,
NameAllowlistFilter,
NameRejectlistFilter,
NetworkValueAllowlistFilter,
NetworkValueRejectlistFilter,
TypeAllowlistFilter,
TypeRejectlistFilter,
ZoneNameFilter,
@@ -161,6 +163,38 @@ class TestNameRejectListFilter(TestCase):
)
class TestNetworkValueFilter(TestCase):
zone = Zone('unit.tests.', [])
matches = Record.new(
zone, 'private-ipv4', {'type': 'A', 'ttl': 42, 'value': '10.42.42.42'}
)
zone.add_record(matches)
doesnt = Record.new(
zone, 'public-ipv4', {'type': 'A', 'ttl': 42, 'value': '42.42.42.42'}
)
zone.add_record(doesnt)
matchable1 = Record.new(
zone, 'private-ipv6', {'type': 'AAAA', 'ttl': 42, 'value': 'fd12:3456:789a:1::1'}
)
zone.add_record(matchable1)
matchable2 = Record.new(
zone, 'public-ipv6', {'type': 'AAAA', 'ttl': 42, 'value': 'dead:beef:cafe::1'}
)
zone.add_record(matchable2)
def test_reject(self):
filter_private = NetworkValueRejectlistFilter('rejectlist', set(('10.0.0.0/8', 'fd00::/8')))
got = filter_private.process_source_zone(self.zone.copy())
self.assertEqual(['public-ipv4', 'public-ipv6'], sorted([r.name for r in got.records]))
def test_allow(self):
filter_private = NetworkValueAllowlistFilter('allowlist', set(('10.0.0.0/8', 'fd00::/8')))
got = filter_private.process_source_zone(self.zone.copy())
self.assertEqual(['private-ipv4', 'private-ipv6'], sorted([r.name for r in got.records]))
class TestIgnoreRootNsFilter(TestCase):
zone = Zone('unit.tests.', [])
root = Record.new(