mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Normalize IP addresses
This commit is contained in:
@@ -749,8 +749,13 @@ class _IpList(object):
|
||||
|
||||
@classmethod
|
||||
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):
|
||||
|
||||
@@ -259,11 +259,21 @@ class TestRecord(TestCase):
|
||||
self.assertEquals(b_data, b.data)
|
||||
|
||||
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)
|
||||
|
||||
# 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):
|
||||
a_data = {'ttl': 30, 'value': a_value}
|
||||
a = _type(self.zone, 'a', a_data)
|
||||
|
||||
Reference in New Issue
Block a user