Update dns hostname validation for host-records
The validation of hostname in service parameter dns host-record is updated to use a new utility function. This function checks hostname to match the definitions as per RFCs (1035/3.1, 2181/11) Closes-bug: 2046246 Test Plan: PASS: Verify build and install PASS: Verify service-parameter-add with valid & invalid hostname Change-Id: I6f13811764c0b793d15a5f94a1d6721fa5a1dc9b Signed-off-by: Joseph Vazhappilly <joseph.vazhappillypaily@windriver.com>
This commit is contained in:
parent
f2ebb1114e
commit
907c461db0
|
@ -580,7 +580,7 @@ def _validate_auth_id_reclaim_enabled(name, value):
|
|||
|
||||
def _validate_dns_hostname(name, value):
|
||||
hostname = value if '.' in value else value + '.dummy'
|
||||
if not cutils.is_valid_domain_name(hostname):
|
||||
if not cutils.is_valid_dns_hostname(hostname):
|
||||
raise wsme.exc.ClientSideError(_(
|
||||
"Parameter '%s' includes an invalid domain name '%s'." %
|
||||
(name, value)))
|
||||
|
|
|
@ -2194,6 +2194,35 @@ def is_valid_domain_name(value):
|
|||
return False
|
||||
|
||||
|
||||
def is_valid_dns_hostname(value):
|
||||
""" Validate dns hostname with TLD based on RFC specs """
|
||||
p = re.compile(
|
||||
# Doesn't contain underscore
|
||||
r'^(?!.*?_.*?)'
|
||||
# Doesn't contain dash at the beginning of a label
|
||||
r'(?!(?:[\d\w]+?\.)?\-[\w\d\.\-]*?)'
|
||||
# Doesn't contain dash at the end of a label
|
||||
r'(?![\w\d]+?\-\.(?:[\d\w\.\-]+?))'
|
||||
# Starts with a non-limit char
|
||||
r'(?=[\w\d])'
|
||||
# Contains at least 1 dot
|
||||
r'(?=[\w\d\.\-]*?\.+[\w\d\.\-]*?)'
|
||||
# Not longer than 253 chars
|
||||
r'(?![\w\d\.\-]{254})'
|
||||
# Doesn't contain a label longer than 63 char
|
||||
r'(?!(?:\.?[\w\d\-\.]*?[\w\d\-]{64,}\.)+?)'
|
||||
# Allowed chars
|
||||
r'[\w\d\.\-]+?'
|
||||
# TLD is at most 24 characters
|
||||
r'(?<![\w\d\-]{25})$'
|
||||
)
|
||||
m = p.match(value)
|
||||
if m:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def verify_checksum(path):
|
||||
""" Find and validate the checksum file in a given directory. """
|
||||
rc = True
|
||||
|
|
|
@ -809,7 +809,7 @@ class ApiServiceParameterPostTestSuiteMixin(ApiServiceParameterTestCaseMixin):
|
|||
post_object = self.service_parameter_data[param]
|
||||
self.post(post_object, expect_errors=True, error_message="Parameter '" +
|
||||
self.service_parameter_data[param]['name'] +
|
||||
"' includes an invalid domain name \'1.1.1.1.1\'.")
|
||||
"' must contain valid ip address and host name.")
|
||||
|
||||
# Test invalid domain name in host-record value
|
||||
for param in range(dns_index + 4, dns_index + 6):
|
||||
|
@ -852,6 +852,12 @@ class ApiServiceParameterPostTestSuiteMixin(ApiServiceParameterTestCaseMixin):
|
|||
self.service_parameter_data[dns_index + 10]['name'] +
|
||||
"' includes an invalid domain name \'" + msg + "\'.")
|
||||
|
||||
# Test valid dns host record with label length 63 & total length 253
|
||||
for param in range(dns_index + 11, dns_index + 12):
|
||||
post_object = self.service_parameter_data[param]
|
||||
response = self.post(post_object)
|
||||
self.validate_data(post_object, response)
|
||||
|
||||
|
||||
class ApiServiceParameterDeleteTestSuiteMixin(ApiServiceParameterTestCaseMixin):
|
||||
""" Tests deletion.
|
||||
|
|
Loading…
Reference in New Issue