mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-10-12 16:32:01 -05:00
Improve error message in zonemgr validator
This patch consolidates zonemgr function to move the most of the checks to common functions in order to provide consistent output. The error messages produced by the validator should now be more helpful when identifying the source of error. https://fedorahosted.org/freeipa/ticket/1966
This commit is contained in:
1 parent
1a26406db2
commit
caf36e1f24
1 file changed
+22
-18
+22
-18
@@ -223,12 +223,15 @@ def validate_dns_label(dns_label, allow_underscore=False):
|
|||||||
label_regex = r'^[%(chars)s]([%(chars)s-]?[%(chars)s])*$' % dict(chars=label_chars)
|
label_regex = r'^[%(chars)s]([%(chars)s-]?[%(chars)s])*$' % dict(chars=label_chars)
|
||||||
regex = re.compile(label_regex, re.IGNORECASE)
|
regex = re.compile(label_regex, re.IGNORECASE)
|
||||||
|
|
||||||
|
if not dns_label:
|
||||||
|
raise ValueError(_('empty DNS label'))
|
||||||
|
|
||||||
if len(dns_label) > 63:
|
if len(dns_label) > 63:
|
||||||
raise ValueError(_('DNS label cannot be longer that 63 characters'))
|
raise ValueError(_('DNS label cannot be longer that 63 characters'))
|
||||||
|
|
||||||
if not regex.match(dns_label):
|
if not regex.match(dns_label):
|
||||||
raise ValueError(_('only letters, numbers,%(underscore)s and - are allowed. ' \
|
raise ValueError(_('only letters, numbers,%(underscore)s and - are allowed. ' \
|
||||||
'- must not be the DNS label character') \
|
'DNS label may not start or end with -') \
|
||||||
% dict(underscore=underscore_err_msg))
|
% dict(underscore=underscore_err_msg))
|
||||||
|
|
||||||
def validate_domain_name(domain_name, allow_underscore=False):
|
def validate_domain_name(domain_name, allow_underscore=False):
|
||||||
@@ -246,11 +249,12 @@ def validate_domain_name(domain_name, allow_underscore=False):
|
|||||||
|
|
||||||
def validate_zonemgr(zonemgr):
|
def validate_zonemgr(zonemgr):
|
||||||
""" See RFC 1033, 1035 """
|
""" See RFC 1033, 1035 """
|
||||||
regex_domain = re.compile(r'^[a-z0-9]([a-z0-9-]?[a-z0-9])*$', re.IGNORECASE)
|
regex_local_part = re.compile(r'^[a-z0-9]([a-z0-9-_]?[a-z0-9])*$',
|
||||||
regex_local_part = re.compile(r'^[a-z0-9]([a-z0-9-_\.]?[a-z0-9])*$',
|
|
||||||
re.IGNORECASE)
|
re.IGNORECASE)
|
||||||
|
local_part_errmsg = _('mail account may only include letters, numbers, -, _ and a dot. There may not be consecutive -, _ and . characters. Its parts may not start or end with - or _')
|
||||||
local_part_errmsg = _('mail account may only include letters, numbers, -, _ and a dot. There may not be consecutive -, _ and . characters')
|
local_part_sep = '.'
|
||||||
|
local_part = None
|
||||||
|
domain = None
|
||||||
|
|
||||||
if len(zonemgr) > 255:
|
if len(zonemgr) > 255:
|
||||||
raise ValueError(_('cannot be longer that 255 characters'))
|
raise ValueError(_('cannot be longer that 255 characters'))
|
||||||
@@ -260,31 +264,31 @@ def validate_zonemgr(zonemgr):
|
|||||||
|
|
||||||
if zonemgr.count('@') == 1:
|
if zonemgr.count('@') == 1:
|
||||||
local_part, dot, domain = zonemgr.partition('@')
|
local_part, dot, domain = zonemgr.partition('@')
|
||||||
if not regex_local_part.match(local_part):
|
|
||||||
raise ValueError(local_part_errmsg)
|
|
||||||
if not domain:
|
|
||||||
raise ValueError(_('missing address domain'))
|
|
||||||
elif zonemgr.count('@') > 1:
|
elif zonemgr.count('@') > 1:
|
||||||
raise ValueError(_('too many \'@\' characters'))
|
raise ValueError(_('too many \'@\' characters'))
|
||||||
else:
|
else:
|
||||||
last_fake_sep = zonemgr.rfind('\\.')
|
last_fake_sep = zonemgr.rfind('\\.')
|
||||||
if last_fake_sep != -1: # there is a 'fake' local-part/domain separator
|
if last_fake_sep != -1: # there is a 'fake' local-part/domain separator
|
||||||
|
local_part_sep = '\\.'
|
||||||
sep = zonemgr.find('.', last_fake_sep+2)
|
sep = zonemgr.find('.', last_fake_sep+2)
|
||||||
if sep == -1:
|
if sep != -1:
|
||||||
raise ValueError(_('missing address domain'))
|
local_part = zonemgr[:sep]
|
||||||
local_part = zonemgr[:sep]
|
domain = zonemgr[sep+1:]
|
||||||
domain = zonemgr[sep+1:]
|
|
||||||
|
|
||||||
if not all(regex_local_part.match(part) for part in local_part.split('\\.')):
|
|
||||||
raise ValueError(local_part_errmsg)
|
|
||||||
else:
|
else:
|
||||||
local_part, dot, domain = zonemgr.partition('.')
|
local_part, dot, domain = zonemgr.partition('.')
|
||||||
|
|
||||||
if not regex_local_part.match(local_part):
|
if not domain:
|
||||||
raise ValueError(local_part_errmsg)
|
raise ValueError(_('missing address domain'))
|
||||||
|
|
||||||
validate_domain_name(domain)
|
validate_domain_name(domain)
|
||||||
|
|
||||||
|
if not local_part:
|
||||||
|
raise ValueError(_('missing mail account'))
|
||||||
|
|
||||||
|
if not all(regex_local_part.match(part) for part in \
|
||||||
|
local_part.split(local_part_sep)):
|
||||||
|
raise ValueError(local_part_errmsg)
|
||||||
|
|
||||||
def validate_hostname(hostname, check_fqdn=True, allow_underscore=False):
|
def validate_hostname(hostname, check_fqdn=True, allow_underscore=False):
|
||||||
""" See RFC 952, 1123
|
""" See RFC 952, 1123
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user