diff options
author | kpdev <kinpaa@gmail.com> | 2021-05-06 06:56:11 +0200 |
---|---|---|
committer | Kiran Pawar <kinpaa@gmail.com> | 2022-08-15 07:41:34 +0000 |
commit | 536315e38ccc06193d9f8b83770aab8f671f6fa8 (patch) | |
tree | 50b14c7cd450dc9bbb58046f47daf75acb9df438 | |
parent | 63563a50983c85df852654e908963eeb7331e3c8 (diff) | |
download | designate-536315e38ccc06193d9f8b83770aab8f671f6fa8.tar.gz |
Validate MX records during recordset create or update
If invalid MX record is provided during recordset create command or
valid record is updated to invalid record using recordset set command,
causes recordset creation/updation failure. This leads to zone enter
in ERROR state and all further recordset creation calls fail. Validate
the records within recordset during create or update call.
Closes-Bug: #1927304
Change-Id: I0ace4d6c4ad6a6ee236e3af23805b01345d60a42
-rw-r--r-- | designate/objects/rrdata_mx.py | 3 | ||||
-rw-r--r-- | designate/tests/unit/objects/test_rrdata_mx.py | 13 |
2 files changed, 15 insertions, 1 deletions
diff --git a/designate/objects/rrdata_mx.py b/designate/objects/rrdata_mx.py index 7d924358..99387d1e 100644 --- a/designate/objects/rrdata_mx.py +++ b/designate/objects/rrdata_mx.py @@ -35,6 +35,9 @@ class MX(Record): if repr(int(priority)) != priority: raise ValueError('Value is not an integer') + if not exchange.endswith('.'): + raise ValueError('Domain %s does not end with a dot' % exchange) + self.priority = int(priority) self.exchange = exchange diff --git a/designate/tests/unit/objects/test_rrdata_mx.py b/designate/tests/unit/objects/test_rrdata_mx.py index 1344bf26..9c9e4469 100644 --- a/designate/tests/unit/objects/test_rrdata_mx.py +++ b/designate/tests/unit/objects/test_rrdata_mx.py @@ -34,7 +34,18 @@ class RRDataMXTest(oslotest.base.BaseTestCase): record_set = objects.RecordSet( name='www.example.org.', type='MX', records=objects.RecordList(objects=[ - objects.Record(data='-0 mail.example.org.', + objects.Record(data='-0 mail.example.test.', + status='ACTIVE'), + ]) + ) + + self.assertRaises(InvalidObject, record_set.validate) + + def test_validate_mx_not_fqdn(self): + record_set = objects.RecordSet( + name='www.example.org.', type='MX', + records=objects.RecordList(objects=[ + objects.Record(data='10 mail.example.test', status='ACTIVE'), ]) ) |