mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
NAPTR RFC2915 - validate flags (partial)
- punting on service, regex & replacement validation for now - clean up MX a smidge
This commit is contained in:
@@ -425,13 +425,12 @@ class MxValue(object):
|
||||
def _validate_value(cls, value):
|
||||
reasons = []
|
||||
try:
|
||||
# seperate lines to have preference set in the ValueError case
|
||||
preference = value.get('preference', None) or value['priority']
|
||||
int(preference)
|
||||
int(value.get('preference', None) or value['priority'])
|
||||
except KeyError:
|
||||
reasons.append('missing preference')
|
||||
except ValueError:
|
||||
reasons.append('invalid preference "{}"'.format(preference))
|
||||
reasons.append('invalid preference "{}"'
|
||||
.format(value['preference']))
|
||||
exchange = None
|
||||
try:
|
||||
exchange = value.get('exchange', None) or value['value']
|
||||
@@ -483,6 +482,7 @@ class MxRecord(_ValuesMixin, Record):
|
||||
|
||||
|
||||
class NaptrValue(object):
|
||||
LEGAL_FLAGS = ('S', 'A', 'U', 'P')
|
||||
|
||||
@classmethod
|
||||
def _validate_value(cls, data):
|
||||
@@ -500,8 +500,15 @@ class NaptrValue(object):
|
||||
except ValueError:
|
||||
reasons.append('invalid preference "{}"'
|
||||
.format(data['preference']))
|
||||
# TODO: validate field data
|
||||
for k in ('flags', 'service', 'regexp', 'replacement'):
|
||||
try:
|
||||
flags = data['flags']
|
||||
if flags not in cls.LEGAL_FLAGS:
|
||||
reasons.append('invalid flags "{}"'.format(flags))
|
||||
except KeyError:
|
||||
reasons.append('missing flags')
|
||||
|
||||
# TODO: validate these... they're non-trivial
|
||||
for k in ('service', 'regexp', 'replacement'):
|
||||
if k not in data:
|
||||
reasons.append('missing {}'.format(k))
|
||||
return reasons
|
||||
|
@@ -952,7 +952,7 @@ class TestRecordValidation(TestCase):
|
||||
'value': {
|
||||
'order': 10,
|
||||
'preference': 20,
|
||||
'flags': 'f',
|
||||
'flags': 'S',
|
||||
'service': 'srv',
|
||||
'regexp': '.*',
|
||||
'replacement': '.'
|
||||
@@ -963,7 +963,7 @@ class TestRecordValidation(TestCase):
|
||||
value = {
|
||||
'order': 10,
|
||||
'preference': 20,
|
||||
'flags': 'f',
|
||||
'flags': 'S',
|
||||
'service': 'srv',
|
||||
'regexp': '.*',
|
||||
'replacement': '.'
|
||||
@@ -1002,6 +1002,17 @@ class TestRecordValidation(TestCase):
|
||||
})
|
||||
self.assertEquals(['invalid preference "who"'], ctx.exception.reasons)
|
||||
|
||||
# unrecognized flags
|
||||
v = dict(value)
|
||||
v['flags'] = 'X'
|
||||
with self.assertRaises(ValidationError) as ctx:
|
||||
Record.new(self.zone, '', {
|
||||
'type': 'NAPTR',
|
||||
'ttl': 600,
|
||||
'value': v
|
||||
})
|
||||
self.assertEquals(['invalid flags "X"'], ctx.exception.reasons)
|
||||
|
||||
def test_NS(self):
|
||||
# doesn't blow up
|
||||
Record.new(self.zone, '', {
|
||||
|
Reference in New Issue
Block a user