mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Test YamlProvider handling of non-ascii record names
This commit is contained in:
+3
-1
@@ -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
|
||||
|
||||
@@ -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))
|
||||
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
|
||||
with open(join(td.dirname, filename), 'w') as fh:
|
||||
pass
|
||||
# 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:
|
||||
|
||||
Reference in New Issue
Block a user