From 2d4855508c89ea70933f776a2e5b967bb17f8249 Mon Sep 17 00:00:00 2001 From: Jonathan Leroy Date: Sun, 1 Nov 2020 23:58:40 +0100 Subject: [PATCH] Check that an alias zone source is not an alias zone --- octodns/manager.py | 16 ++++++++++++++++ tests/config/alias-zone-loop.yaml | 21 +++++++++++++++++++++ tests/test_octodns_manager.py | 17 ++++++++++++++++- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/config/alias-zone-loop.yaml diff --git a/octodns/manager.py b/octodns/manager.py index cfc9735..5f4af55 100644 --- a/octodns/manager.py +++ b/octodns/manager.py @@ -280,6 +280,7 @@ class Manager(object): self.log.info('sync: zone=%s', zone_name) if 'alias' in config: source_zone = config['alias'] + # Check that the source zone is defined. if source_zone not in self.config['zones']: self.log.error('Invalid alias zone {}, target {} does ' @@ -288,6 +289,14 @@ class Manager(object): 'source zone {} does not exist' .format(zone_name, source_zone)) + # Check that the source zone is not an alias zone itself. + if 'alias' in self.config['zones'][source_zone]: + self.log.error('Invalid alias zone {}, target {} is an ' + 'alias zone'.format(zone_name, source_zone)) + raise ManagerException('Invalid alias zone {}: source ' + 'zone {} is an alias zone' + .format(zone_name, source_zone)) + aliased_zones[zone_name] = source_zone continue @@ -473,6 +482,13 @@ class Manager(object): raise ManagerException('Invalid alias zone {}: ' 'source zone {} does not exist' .format(zone_name, source_zone)) + + if 'alias' in self.config['zones'][source_zone]: + self.log.exception('Invalid alias zone') + raise ManagerException('Invalid alias zone {}: ' + 'source zone {} is an alias zone' + .format(zone_name, source_zone)) + # this is just here to satisfy coverage, see # https://github.com/nedbat/coveragepy/issues/198 source_zone = source_zone diff --git a/tests/config/alias-zone-loop.yaml b/tests/config/alias-zone-loop.yaml new file mode 100644 index 0000000..df8b53f --- /dev/null +++ b/tests/config/alias-zone-loop.yaml @@ -0,0 +1,21 @@ +manager: + max_workers: 2 +providers: + in: + class: octodns.provider.yaml.YamlProvider + directory: tests/config + dump: + class: octodns.provider.yaml.YamlProvider + directory: env/YAML_TMP_DIR +zones: + unit.tests.: + sources: + - in + targets: + - dump + + alias.tests.: + alias: unit.tests. + + alias-loop.tests.: + alias: alias.tests. diff --git a/tests/test_octodns_manager.py b/tests/test_octodns_manager.py index 6affa17..dc047e8 100644 --- a/tests/test_octodns_manager.py +++ b/tests/test_octodns_manager.py @@ -183,6 +183,14 @@ class TestManager(TestCase): 'does-not-exists.tests. does not exist', text_type(ctx.exception)) + # Alias zone that points to another alias zone. + with self.assertRaises(ManagerException) as ctx: + tc = Manager(get_config_filename('alias-zone-loop.yaml')) \ + .sync() + self.assertEquals('Invalid alias zone alias-loop.tests.: source ' + 'zone alias.tests. is an alias zone', + text_type(ctx.exception)) + def test_compare(self): with TemporaryDirectory() as tmpdir: environ['YAML_TMP_DIR'] = tmpdir.dirname @@ -306,7 +314,14 @@ class TestManager(TestCase): with self.assertRaises(ManagerException) as ctx: Manager(get_config_filename('unknown-source-zone.yaml')) \ .validate_configs() - self.assertTrue('Invalid alias zone' in + self.assertTrue('does not exist' in + text_type(ctx.exception)) + + # Alias zone that points to another alias zone. + with self.assertRaises(ManagerException) as ctx: + Manager(get_config_filename('alias-zone-loop.yaml')) \ + .validate_configs() + self.assertTrue('is an alias zone' in text_type(ctx.exception)) # Valid config file using an alias zone.