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):
|
def _validate_value(cls, value):
|
||||||
reasons = []
|
reasons = []
|
||||||
try:
|
try:
|
||||||
# seperate lines to have preference set in the ValueError case
|
int(value.get('preference', None) or value['priority'])
|
||||||
preference = value.get('preference', None) or value['priority']
|
|
||||||
int(preference)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
reasons.append('missing preference')
|
reasons.append('missing preference')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
reasons.append('invalid preference "{}"'.format(preference))
|
reasons.append('invalid preference "{}"'
|
||||||
|
.format(value['preference']))
|
||||||
exchange = None
|
exchange = None
|
||||||
try:
|
try:
|
||||||
exchange = value.get('exchange', None) or value['value']
|
exchange = value.get('exchange', None) or value['value']
|
||||||
@@ -483,6 +482,7 @@ class MxRecord(_ValuesMixin, Record):
|
|||||||
|
|
||||||
|
|
||||||
class NaptrValue(object):
|
class NaptrValue(object):
|
||||||
|
LEGAL_FLAGS = ('S', 'A', 'U', 'P')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _validate_value(cls, data):
|
def _validate_value(cls, data):
|
||||||
@@ -500,8 +500,15 @@ class NaptrValue(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
reasons.append('invalid preference "{}"'
|
reasons.append('invalid preference "{}"'
|
||||||
.format(data['preference']))
|
.format(data['preference']))
|
||||||
# TODO: validate field data
|
try:
|
||||||
for k in ('flags', 'service', 'regexp', 'replacement'):
|
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:
|
if k not in data:
|
||||||
reasons.append('missing {}'.format(k))
|
reasons.append('missing {}'.format(k))
|
||||||
return reasons
|
return reasons
|
||||||
|
@@ -952,7 +952,7 @@ class TestRecordValidation(TestCase):
|
|||||||
'value': {
|
'value': {
|
||||||
'order': 10,
|
'order': 10,
|
||||||
'preference': 20,
|
'preference': 20,
|
||||||
'flags': 'f',
|
'flags': 'S',
|
||||||
'service': 'srv',
|
'service': 'srv',
|
||||||
'regexp': '.*',
|
'regexp': '.*',
|
||||||
'replacement': '.'
|
'replacement': '.'
|
||||||
@@ -963,7 +963,7 @@ class TestRecordValidation(TestCase):
|
|||||||
value = {
|
value = {
|
||||||
'order': 10,
|
'order': 10,
|
||||||
'preference': 20,
|
'preference': 20,
|
||||||
'flags': 'f',
|
'flags': 'S',
|
||||||
'service': 'srv',
|
'service': 'srv',
|
||||||
'regexp': '.*',
|
'regexp': '.*',
|
||||||
'replacement': '.'
|
'replacement': '.'
|
||||||
@@ -1002,6 +1002,17 @@ class TestRecordValidation(TestCase):
|
|||||||
})
|
})
|
||||||
self.assertEquals(['invalid preference "who"'], ctx.exception.reasons)
|
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):
|
def test_NS(self):
|
||||||
# doesn't blow up
|
# doesn't blow up
|
||||||
Record.new(self.zone, '', {
|
Record.new(self.zone, '', {
|
||||||
|
Reference in New Issue
Block a user