MX RFC1035 - priority -> preference & value -> exchange

This commit is contained in:
Ross McFarland
2017-06-23 13:04:38 -07:00
parent 3ca64c4e08
commit 1340aee8a9
14 changed files with 118 additions and 88 deletions
+6 -6
View File
@@ -60,12 +60,12 @@ mx:
ttl: 300
type: MX
values:
- priority: 40
value: smtp-1.unit.tests.
- priority: 20
value: smtp-2.unit.tests.
- priority: 30
value: smtp-3.unit.tests.
- exchange: smtp-1.unit.tests.
preference: 40
- exchange: smtp-2.unit.tests.
preference: 20
- exchange: smtp-3.unit.tests.
preference: 30
- priority: 10
value: smtp-4.unit.tests.
naptr:
+4 -4
View File
@@ -46,11 +46,11 @@ class TestDynProvider(TestCase):
'type': 'MX',
'ttl': 302,
'values': [{
'priority': 10,
'value': 'smtp-1.unit.tests.'
'preference': 10,
'exchange': 'smtp-1.unit.tests.'
}, {
'priority': 20,
'value': 'smtp-2.unit.tests.'
'preference': 20,
'exchange': 'smtp-2.unit.tests.'
}]
}),
('naptr', {
+4 -4
View File
@@ -44,11 +44,11 @@ class TestNs1Provider(TestCase):
'ttl': 35,
'type': 'MX',
'values': [{
'priority': 10,
'value': 'mx1.unit.tests.',
'preference': 10,
'exchange': 'mx1.unit.tests.',
}, {
'priority': 20,
'value': 'mx2.unit.tests.',
'preference': 20,
'exchange': 'mx2.unit.tests.',
}]
}))
expected.add(Record.new(zone, 'naptr', {
+6 -6
View File
@@ -52,11 +52,11 @@ class TestRoute53Provider(TestCase):
'Goodbye World?']}),
('', {'ttl': 64, 'type': 'MX',
'values': [{
'priority': 10,
'value': 'smtp-1.unit.tests.',
'preference': 10,
'exchange': 'smtp-1.unit.tests.',
}, {
'priority': 20,
'value': 'smtp-2.unit.tests.',
'preference': 20,
'exchange': 'smtp-2.unit.tests.',
}]}),
('naptr', {'ttl': 65, 'type': 'NAPTR',
'value': {
@@ -1262,8 +1262,8 @@ class TestRoute53Records(TestCase):
d = _Route53Record(None, Record.new(existing, '',
{'ttl': 42, 'type': 'MX',
'value': {
'priority': 10,
'value': 'foo.bar.'}}),
'preference': 10,
'exchange': 'foo.bar.'}}),
False)
self.assertEquals(d, d)
+37 -21
View File
@@ -212,45 +212,49 @@ class TestRecord(TestCase):
def test_mx(self):
a_values = [{
'priority': 10,
'value': 'smtp1'
'preference': 10,
'exchange': 'smtp1.'
}, {
'priority': 20,
'value': 'smtp2'
'value': 'smtp2.'
}]
a_data = {'ttl': 30, 'values': a_values}
a = MxRecord(self.zone, 'a', a_data)
self.assertEquals('a', a.name)
self.assertEquals('a.unit.tests.', a.fqdn)
self.assertEquals(30, a.ttl)
self.assertEquals(a_values[0]['priority'], a.values[0].priority)
self.assertEquals(a_values[0]['value'], a.values[0].value)
self.assertEquals(a_values[1]['priority'], a.values[1].priority)
self.assertEquals(a_values[1]['value'], a.values[1].value)
self.assertEquals(a_values[0]['preference'], a.values[0].preference)
self.assertEquals(a_values[0]['exchange'], a.values[0].exchange)
self.assertEquals(a_values[1]['priority'], a.values[1].preference)
self.assertEquals(a_values[1]['value'], a.values[1].exchange)
a_data['values'][1] = {
'preference': 20,
'exchange': 'smtp2.',
}
self.assertEquals(a_data, a.data)
b_value = {
'priority': 12,
'value': 'smtp3',
'preference': 12,
'exchange': 'smtp3.',
}
b_data = {'ttl': 30, 'value': b_value}
b = MxRecord(self.zone, 'b', b_data)
self.assertEquals(b_value['priority'], b.values[0].priority)
self.assertEquals(b_value['value'], b.values[0].value)
self.assertEquals(b_value['preference'], b.values[0].preference)
self.assertEquals(b_value['exchange'], b.values[0].exchange)
self.assertEquals(b_data, b.data)
target = SimpleProvider()
# No changes with self
self.assertFalse(a.changes(a, target))
# Diff in priority causes change
# Diff in preference causes change
other = MxRecord(self.zone, 'a', {'ttl': 30, 'values': a_values})
other.values[0].priority = 22
other.values[0].preference = 22
change = a.changes(other, target)
self.assertEqual(change.existing, a)
self.assertEqual(change.new, other)
# Diff in value causes change
other.values[0].priority = a.values[0].priority
other.values[0].value = 'smtpX'
other.values[0].preference = a.values[0].preference
other.values[0].exchange = 'smtpX'
change = a.changes(other, target)
self.assertEqual(change.existing, a)
self.assertEqual(change.new, other)
@@ -889,8 +893,8 @@ class TestRecordValidation(TestCase):
'type': 'MX',
'ttl': 600,
'value': {
'priority': 10,
'value': 'foo.bar.com.'
'preference': 10,
'exchange': 'foo.bar.com.'
}
})
@@ -900,10 +904,10 @@ class TestRecordValidation(TestCase):
'type': 'MX',
'ttl': 600,
'value': {
'value': 'foo.bar.com.'
'exchange': 'foo.bar.com.'
}
})
self.assertEquals(['missing priority'], ctx.exception.reasons)
self.assertEquals(['missing preference'], ctx.exception.reasons)
# missing value
with self.assertRaises(ValidationError) as ctx:
@@ -911,10 +915,22 @@ class TestRecordValidation(TestCase):
'type': 'MX',
'ttl': 600,
'value': {
'priority': 10,
'preference': 10,
}
})
self.assertEquals(['missing value'], ctx.exception.reasons)
self.assertEquals(['missing exchange'], ctx.exception.reasons)
# missing trailing .
with self.assertRaises(ValidationError) as ctx:
Record.new(self.zone, '', {
'type': 'MX',
'ttl': 600,
'value': {
'preference': 10,
'exchange': 'foo.bar.com'
}
})
self.assertEquals(['missing trailing .'], ctx.exception.reasons)
def test_NXPTR(self):
# doesn't blow up
+8 -8
View File
@@ -68,22 +68,22 @@ class TestTinyDnsFileSource(TestCase):
'type': 'MX',
'ttl': 3600,
'values': [{
'priority': 10,
'value': 'smtp-1-host.example.com.',
'preference': 10,
'exchange': 'smtp-1-host.example.com.',
}, {
'priority': 20,
'value': 'smtp-2-host.example.com.',
'preference': 20,
'exchange': 'smtp-2-host.example.com.',
}]
}),
('smtp', {
'type': 'MX',
'ttl': 1800,
'values': [{
'priority': 30,
'value': 'smtp-1-host.example.com.',
'preference': 30,
'exchange': 'smtp-1-host.example.com.',
}, {
'priority': 40,
'value': 'smtp-2-host.example.com.',
'preference': 40,
'exchange': 'smtp-2-host.example.com.',
}]
}),
):