Browse Source

Test YamlProvider handling of non-ascii record names

pull/922/head
Ross McFarland 3 years ago
parent
commit
27fc734c2a
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 29 additions and 9 deletions
  1. +3
    -1
      octodns/zone.py
  2. +26
    -8
      tests/test_octodns_provider_yaml.py

+ 3
- 1
octodns/zone.py View File

@ -41,7 +41,9 @@ class Zone(object):
self.decoded_name = idna_decode(self.name)
self.sub_zones = sub_zones
# We're grouping by node, it allows us to efficiently search for
# duplicates and detect when CNAMEs co-exist with other records
# duplicates and detect when CNAMEs co-exist with other records. Also
# node that we always store things with Record.name which will be idna
# encoded thus we don't have to deal with idna/utf8 collisions
self._records = defaultdict(set)
self._root_ns = None
# optional leading . to match empty hostname


+ 26
- 8
tests/test_octodns_provider_yaml.py View File

@ -174,7 +174,7 @@ class TestYamlProvider(TestCase):
# make sure nothing is left
self.assertEqual([], list(data.keys()))
def test_idna_filenames(self):
def test_idna(self):
with TemporaryDirectory() as td:
name = 'déjà.vu.'
filename = f'{name}yaml'
@ -184,23 +184,41 @@ class TestYamlProvider(TestCase):
# create a idna named file
with open(join(td.dirname, idna_encode(filename)), 'w') as fh:
pass
fh.write(
'''---
'':
type: A
value: 1.2.3.4
# something in idna notation
xn--dj-kia8a:
type: A
value: 2.3.4.5
# something with utf-8
:
type: A
value: 3.4.5.6
'''
)
# populates fine when there's just the idna version (as a fallback)
provider.populate(zone)
self.assertEqual(1, len(zone.records))
# create a utf8 named file
with open(join(td.dirname, filename), 'w') as fh:
pass
d = {r.name: r for r in zone.records}
self.assertEqual(3, len(d))
# verify that we loaded the expected records, including idna/utf-8
# named ones
self.assertEqual(['1.2.3.4'], d[''].values)
self.assertEqual(['2.3.4.5'], d['xn--dj-kia8a'].values)
self.assertEqual(['3.4.5.6'], d['xn--28jm5b5a8k5k8cra'].values)
# create a utf8 named file (provider always writes utf-8 filenames
plan = provider.plan(zone)
provider.apply(plan)
with open(join(td.dirname, filename), 'r') as fh:
content = fh.read()
# verify that the non-ascii records were written out in utf-8
self.assertTrue('déjà:' in content)
self.assertTrue('これはテストです:' in content)
# does not allow both idna and utf8 named files
with self.assertRaises(ProviderException) as ctx:


Loading…
Cancel
Save