Browse Source

Normalize IP addresses

pull/759/head
Ross McFarland 4 years ago
parent
commit
074de66988
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 20 additions and 5 deletions
  1. +7
    -2
      octodns/record/__init__.py
  2. +13
    -3
      tests/test_octodns_record.py

+ 7
- 2
octodns/record/__init__.py View File

@ -749,8 +749,13 @@ class _IpList(object):
@classmethod @classmethod
def process(cls, values): def process(cls, values):
# Translating None into '' so that the list will be sortable in python3
return [v if v is not None else '' for v in values]
# Translating None into '' so that the list will be sortable in
# python3, get everything to str first
values = [text_type(v) if v is not None else '' for v in values]
# Now round trip all non-'' through the address type and back to a str
# to normalize the address representation.
return [text_type(cls._address_type(v)) if v != '' else ''
for v in values]
class Ipv4List(_IpList): class Ipv4List(_IpList):


+ 13
- 3
tests/test_octodns_record.py View File

@ -259,11 +259,21 @@ class TestRecord(TestCase):
self.assertEquals(b_data, b.data) self.assertEquals(b_data, b.data)
def test_aaaa(self): def test_aaaa(self):
a_values = ['2001:0db8:3c4d:0015:0000:0000:1a2f:1a2b',
'2001:0db8:3c4d:0015:0000:0000:1a2f:1a3b']
b_value = '2001:0db8:3c4d:0015:0000:0000:1a2f:1a4b'
a_values = ['2001:db8:3c4d:15::1a2f:1a2b',
'2001:db8:3c4d:15::1a2f:1a3b']
b_value = '2001:db8:3c4d:15::1a2f:1a4b'
self.assertMultipleValues(AaaaRecord, a_values, b_value) self.assertMultipleValues(AaaaRecord, a_values, b_value)
# Specifically validate that we normalize IPv6 addresses
values = ['2001:db8:3c4d:15:0000:0000:1a2f:1a2b',
'2001:0db8:3c4d:0015::1a2f:1a3b']
data = {
'ttl': 30,
'values': values,
}
record = AaaaRecord(self.zone, 'aaaa', data)
self.assertEquals(a_values, record.values)
def assertSingleValue(self, _type, a_value, b_value): def assertSingleValue(self, _type, a_value, b_value):
a_data = {'ttl': 30, 'value': a_value} a_data = {'ttl': 30, 'value': a_value}
a = _type(self.zone, 'a', a_data) a = _type(self.zone, 'a', a_data)


Loading…
Cancel
Save