mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-14 15:58:38 -05:00
Fix LDAPServerURIField number in domain
- Bug: API error if LDAPServerURIField contains a number in the top level domain - Add custom regex in LDAPServerURIField class that is passed to django URLValidator - The custom regex allows for numbers to be present in the top level domain - Unit tests check that valid URIs pass through URLValidator, and that invalid URIs raise the correct exception - Related to issue #3646
This commit is contained in:
@@ -8,6 +8,7 @@ from awx.sso.fields import (
|
||||
SAMLOrgAttrField,
|
||||
SAMLTeamAttrField,
|
||||
LDAPGroupTypeParamsField,
|
||||
LDAPServerURIField
|
||||
)
|
||||
|
||||
|
||||
@@ -114,3 +115,20 @@ class TestLDAPGroupTypeParamsField():
|
||||
with pytest.raises(ValidationError) as e:
|
||||
field.to_internal_value(data)
|
||||
assert e.value.detail == expected
|
||||
|
||||
|
||||
class TestLDAPServerURIField():
|
||||
|
||||
@pytest.mark.parametrize("ldap_uri, exception, expected", [
|
||||
(r'ldap://servername.com:444', None, r'ldap://servername.com:444'),
|
||||
(r'ldap://servername.so3:444', None, r'ldap://servername.so3:444'),
|
||||
(r'ldaps://servername3.s300:344', None, r'ldaps://servername3.s300:344'),
|
||||
(r'ldap://servername.-so3:444', ValidationError, None),
|
||||
])
|
||||
def test_run_validators_valid(self, ldap_uri, exception, expected):
|
||||
field = LDAPServerURIField()
|
||||
if exception is None:
|
||||
assert field.run_validators(ldap_uri) == expected
|
||||
else:
|
||||
with pytest.raises(exception):
|
||||
field.run_validators(ldap_uri)
|
||||
|
||||
Reference in New Issue
Block a user