mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Check that an alias zone source is not an alias zone
This commit is contained in:
@@ -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
|
||||
|
||||
21
tests/config/alias-zone-loop.yaml
Normal file
21
tests/config/alias-zone-loop.yaml
Normal file
@@ -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.
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user