Merge ~lloydwaltersj/maas:interface-name into maas:master

Proposed by Jack Lloyd-Walters
Status: Merged
Approved by: Anton Troyanov
Approved revision: 119be4037c471e7c6a494c0107a33864e0a793c4
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~lloydwaltersj/maas:interface-name
Merge into: maas:master
Diff against target: 32 lines (+12/-5)
1 file modified
src/maasserver/models/domain.py (+12/-5)
Reviewer Review Type Date Requested Status
Alexsander de Souza Approve
MAAS Lander Approve
Review via email: mp+426390@code.launchpad.net

Commit message

sanitise domain names

Description of the change

modify regex to better sanitise domain names
introduce slightly more verbose error message for domain names.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b interface-name lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/13170/console
COMMIT: e55e431f76cc7140af14d40f82a9de1a781d94e9

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b interface-name lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/13171/console
COMMIT: f89fd2bc4e8085762f7be3e0cf8ee072e4cd3a5f

review: Needs Fixing
~lloydwaltersj/maas:interface-name updated
119be40... by Jack Lloyd-Walters

actually fix merge conflict this time

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b interface-name lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 119be4037c471e7c6a494c0107a33864e0a793c4

review: Approve
Revision history for this message
Alexsander de Souza (alexsander-souza) 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/domain.py b/src/maasserver/models/domain.py
2index f3c1d71..a793e01 100644
3--- a/src/maasserver/models/domain.py
4+++ b/src/maasserver/models/domain.py
5@@ -30,17 +30,24 @@ from maasserver.utils.orm import MAASQueriesMixin
6
7 # Labels are at most 63 octets long, and a name can be many of them.
8 LABEL = r"[a-zA-Z0-9]([-a-zA-Z0-9]{0,62}[a-zA-Z0-9]){0,1}"
9-NAMESPEC = rf"({LABEL}.)*{LABEL}.?"
10+NAMESPEC = rf"({LABEL}[.])*{LABEL}[.]?"
11
12
13 def validate_domain_name(value):
14 """Django validator: `value` must be a valid DNS Zone name."""
15- namespec = re.compile("^%s$" % NAMESPEC)
16- if not namespec.search(value) or len(value) > 255:
17- raise ValidationError("Invalid domain name: %s." % value)
18+ namespec = re.compile(f"^{NAMESPEC}$")
19+ if len(value) > 255:
20+ raise ValidationError(
21+ "Domain name length cannot exceed 255 characters."
22+ )
23+ if not namespec.match(value):
24+ disallowed_chars = re.sub("[a-zA-Z0-9-.]*", "", value)
25+ if disallowed_chars:
26+ raise ValidationError("Domain name contains invalid characters.")
27+ raise ValidationError(f"Invalid domain name: {value}.")
28 if value == Config.objects.get_config("maas_internal_domain"):
29 raise ValidationError(
30- "Domain name cannot duplicate maas internal domain name"
31+ "Domain name cannot duplicate maas internal domain name."
32 )
33
34

Subscribers

People subscribed via source and target branches