Testing of Zone and Record name/decoded_name handling

This commit is contained in:
Ross McFarland
2022-08-20 11:55:19 -07:00
parent 27fc734c2a
commit 16e0bd0675
3 changed files with 44 additions and 2 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ from collections import defaultdict
from logging import getLogger
import re
from .idna import idna_decode
from .idna import idna_decode, idna_encode
from .record import Create, Delete
@@ -36,7 +36,7 @@ class Zone(object):
if not name[-1] == '.':
raise Exception(f'Invalid zone name {name}, missing ending dot')
# internally everything is idna
self.name = str(name).lower() if name else name
self.name = idna_encode(str(name)) if name else name
# we'll keep a decoded version around for logs and errors
self.decoded_name = idna_decode(self.name)
self.sub_zones = sub_zones
+13
View File
@@ -11,6 +11,7 @@ from __future__ import (
from unittest import TestCase
from octodns.idna import idna_encode
from octodns.record import (
ARecord,
AaaaRecord,
@@ -83,6 +84,18 @@ class TestRecord(TestCase):
)
self.assertEqual('mixedcase', record.name)
def test_utf8(self):
zone = Zone('natación.mx.', [])
utf8 = 'niño'
encoded = idna_encode(utf8)
record = ARecord(
zone, utf8, {'ttl': 30, 'type': 'A', 'value': '1.2.3.4'}
)
self.assertEqual(encoded, record.name)
self.assertEqual(utf8, record.decoded_name)
self.assertTrue(f'{encoded}.{zone.name}', record.fqdn)
self.assertTrue(f'{utf8}.{zone.decoded_name}', record.decoded_fqdn)
def test_alias_lowering_value(self):
upper_record = AliasRecord(
self.zone,
+29
View File
@@ -11,6 +11,7 @@ from __future__ import (
from unittest import TestCase
from octodns.idna import idna_encode
from octodns.record import (
ARecord,
AaaaRecord,
@@ -35,6 +36,13 @@ class TestZone(TestCase):
zone = Zone('UniT.TEsTs.', [])
self.assertEqual('unit.tests.', zone.name)
def test_utf8(self):
utf8 = 'grüßen.de.'
encoded = idna_encode(utf8)
zone = Zone(utf8, [])
self.assertEqual(encoded, zone.name)
self.assertEqual(utf8, zone.decoded_name)
def test_hostname_from_fqdn(self):
zone = Zone('unit.tests.', [])
for hostname, fqdn in (
@@ -46,6 +54,27 @@ class TestZone(TestCase):
('foo.bar', 'foo.bar.unit.tests'),
('foo.unit.tests', 'foo.unit.tests.unit.tests.'),
('foo.unit.tests', 'foo.unit.tests.unit.tests'),
('déjà', 'déjà.unit.tests'),
('déjà.foo', 'déjà.foo.unit.tests'),
('bar.déjà', 'bar.déjà.unit.tests'),
('bar.déjà.foo', 'bar.déjà.foo.unit.tests'),
):
self.assertEqual(hostname, zone.hostname_from_fqdn(fqdn))
zone = Zone('grüßen.de.', [])
for hostname, fqdn in (
('', 'grüßen.de.'),
('', 'grüßen.de'),
('foo', 'foo.grüßen.de.'),
('foo', 'foo.grüßen.de'),
('foo.bar', 'foo.bar.grüßen.de.'),
('foo.bar', 'foo.bar.grüßen.de'),
('foo.grüßen.de', 'foo.grüßen.de.grüßen.de.'),
('foo.grüßen.de', 'foo.grüßen.de.grüßen.de'),
('déjà', 'déjà.grüßen.de'),
('déjà.foo', 'déjà.foo.grüßen.de'),
('bar.déjà', 'bar.déjà.grüßen.de'),
('bar.déjà.foo', 'bar.déjà.foo.grüßen.de'),
):
self.assertEqual(hostname, zone.hostname_from_fqdn(fqdn))