mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
Validate that MX preference parses as int
This commit is contained in:
+7
-1
@@ -424,8 +424,14 @@ class MxValue(object):
|
||||
@classmethod
|
||||
def _validate_value(cls, value):
|
||||
reasons = []
|
||||
if 'preference' not in value and 'priority' not in value:
|
||||
try:
|
||||
# seperate lines to have preference set in the ValueError case
|
||||
preference = value.get('preference', None) or value['priority']
|
||||
int(preference)
|
||||
except KeyError:
|
||||
reasons.append('missing preference')
|
||||
except ValueError:
|
||||
reasons.append('invalid preference "{}"'.format(preference))
|
||||
exchange = None
|
||||
try:
|
||||
exchange = value.get('exchange', None) or value['value']
|
||||
|
||||
@@ -898,7 +898,7 @@ class TestRecordValidation(TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
# missing priority
|
||||
# missing preference
|
||||
with self.assertRaises(ValidationError) as ctx:
|
||||
Record.new(self.zone, '', {
|
||||
'type': 'MX',
|
||||
@@ -909,7 +909,19 @@ class TestRecordValidation(TestCase):
|
||||
})
|
||||
self.assertEquals(['missing preference'], ctx.exception.reasons)
|
||||
|
||||
# missing value
|
||||
# invalid preference
|
||||
with self.assertRaises(ValidationError) as ctx:
|
||||
Record.new(self.zone, '', {
|
||||
'type': 'MX',
|
||||
'ttl': 600,
|
||||
'value': {
|
||||
'preference': 'nope',
|
||||
'exchange': 'foo.bar.com.'
|
||||
}
|
||||
})
|
||||
self.assertEquals(['invalid preference "nope"'], ctx.exception.reasons)
|
||||
|
||||
# missing exchange
|
||||
with self.assertRaises(ValidationError) as ctx:
|
||||
Record.new(self.zone, '', {
|
||||
'type': 'MX',
|
||||
|
||||
Reference in New Issue
Block a user