diff --git a/awx/conf/fields.py b/awx/conf/fields.py index e48ef805062c..ca731de579d4 100644 --- a/awx/conf/fields.py +++ b/awx/conf/fields.py @@ -121,11 +121,14 @@ class URLField(CharField): def __init__(self, **kwargs): schemes = kwargs.pop('schemes', None) + regex = kwargs.pop('regex', None) self.allow_plain_hostname = kwargs.pop('allow_plain_hostname', False) super(URLField, self).__init__(**kwargs) validator_kwargs = dict(message=_('Enter a valid URL')) if schemes is not None: validator_kwargs['schemes'] = schemes + if regex is not None: + validator_kwargs['regex'] = regex self.validators.append(URLValidator(**validator_kwargs)) def to_representation(self, value): diff --git a/awx/sso/fields.py b/awx/sso/fields.py index dddd1ee6a124..d3bf36164541 100644 --- a/awx/sso/fields.py +++ b/awx/sso/fields.py @@ -11,6 +11,7 @@ # Django from django.utils import six from django.utils.translation import ugettext_lazy as _ +from django.core.validators import URLValidator, _lazy_re_compile # Django Auth LDAP import django_auth_ldap.config @@ -233,12 +234,34 @@ def _default_from_required_settings(self): class LDAPServerURIField(fields.URLField): + tld_re = ( + r'\.' # dot + r'(?!-)' # can't start with a dash + r'(?:[a-z' + URLValidator.ul + r'0-9' + '-]{2,63}' # domain label, this line was changed from the original URLValidator + r'|xn--[a-z0-9]{1,59})' # or punycode label + r'(?