Merge ~mpontillo/maas:fix-srv-record-validation--bug-1782409 into maas:master

Proposed by Mike Pontillo on 2018-09-05
Status: Merged
Approved by: Mike Pontillo on 2018-09-06
Approved revision: 96677360a86c518136bf2366ef22c2403ad47195
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~mpontillo/maas:fix-srv-record-validation--bug-1782409
Merge into: maas:master
Diff against target: 30 lines (+5/-1)
2 files modified
src/maasserver/models/dnsdata.py (+1/-1)
src/maasserver/models/tests/test_dnsdata.py (+4/-0)
Reviewer Review Type Date Requested Status
Alberto Donato 2018-09-05 Approve on 2018-09-06
MAAS Lander Approve on 2018-09-05
Review via email: mp+354366@code.launchpad.net

Commit message

LP: #1782409 - Fix bad error message when adding a malformed SRV record.

To post a comment you must log in.
Mike Pontillo (mpontillo) wrote :

For some reason the code was pulling the srv_host out of the regular expression before validating that the regular expression matched at all - oops. ;-)

MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b fix-srv-record-validation--bug-1782409 lp:~mpontillo/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 96677360a86c518136bf2366ef22c2403ad47195

review: Approve
Alberto Donato (ack) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/models/dnsdata.py b/src/maasserver/models/dnsdata.py
2index 028b7ac..4907f67 100644
3--- a/src/maasserver/models/dnsdata.py
4+++ b/src/maasserver/models/dnsdata.py
5@@ -327,9 +327,9 @@ class DNSData(CleanSave, TimestampedModel):
6 r"^(?P<pri>[0-9]+)\s+(?P<weight>[0-9]+)\s+(?P<port>[0-9]+)\s+"
7 r"(?P<target>.*)")
8 res = spec.search(self.rrdata)
9- srv_host = res.groupdict()['target']
10 if res is None:
11 raise ValidationError(INVALID_SRV_MSG)
12+ srv_host = res.groupdict()['target']
13 pri = int(res.groupdict()['pri'])
14 weight = int(res.groupdict()['weight'])
15 port = int(res.groupdict()['port'])
16diff --git a/src/maasserver/models/tests/test_dnsdata.py b/src/maasserver/models/tests/test_dnsdata.py
17index 3b769be..2e3ba31 100644
18--- a/src/maasserver/models/tests/test_dnsdata.py
19+++ b/src/maasserver/models/tests/test_dnsdata.py
20@@ -132,6 +132,10 @@ class DNSDataTest(MAASServerTestCase):
21 "{'__all__': [\"%s\"]}" % INVALID_CNAME_MSG)):
22 dnsdata.save()
23
24+ def test_rejects_bad_srv(self):
25+ with ExpectedException(ValidationError):
26+ factory.make_DNSData(rrtype="SRV", rrdata="")
27+
28 def test_rejects_bad_sshfp_record(self):
29 dnsresource = factory.make_DNSResource(no_ip_addresses=True)
30 dnsdata = DNSData(

Subscribers

People subscribed via source and target branches