From 4a7df31445c4cb355cb3a2bcdd26dcba51bb6001 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Fri, 30 Jun 2023 14:59:09 -0700 Subject: [PATCH] handle a couple zone.owns edge cases --- octodns/zone.py | 8 ++++++-- tests/test_octodns_zone.py | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/octodns/zone.py b/octodns/zone.py index ba527a2..9cbc712 100644 --- a/octodns/zone.py +++ b/octodns/zone.py @@ -79,8 +79,12 @@ class Zone(object): if fqdn[-1] != '.': fqdn = f'{fqdn}.' - # if we don't end with the zone's name we aren't owned by it - if not fqdn.endswith(self.name): + # if we exactly match the zone name we own it + if fqdn == self.name: + return True + + # if we don't end with the zone's name on a boundary we aren't owned + if not fqdn.endswith(f'.{self.name}'): return False hostname = self.hostname_from_fqdn(fqdn) diff --git a/tests/test_octodns_zone.py b/tests/test_octodns_zone.py index b3f76e2..93d8a87 100644 --- a/tests/test_octodns_zone.py +++ b/tests/test_octodns_zone.py @@ -210,6 +210,12 @@ class TestZone(TestCase): # including subsequent delegatoin NS records self.assertFalse(zone.owns('NS', 'below.sub.unit.tests.')) + # edge cases + # we don't own something that ends with our name, but isn't a boundary + self.assertFalse(zone.owns('A', 'foo-unit.tests.')) + # we do something that ends with the sub-zone, but isn't at a boundary + self.assertTrue(zone.owns('A', 'foo-sub.unit.tests.')) + def test_sub_zones(self): # NS for exactly the sub is allowed zone = Zone('unit.tests.', set(['sub', 'barred']))