1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Merge pull request #1929 from ryanpetrello/fix-968

allow AUTH_LDAP_USER_FLAGS_BY_GROUP to specify an OR'd list for a flag
This commit is contained in:
Ryan Petrello 2018-05-23 14:58:27 -04:00 committed by GitHub
commit ec8d6e2f6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 1 deletions

View File

@ -101,6 +101,42 @@ def test_ldap_settings(get, put, patch, delete, admin):
patch(url, user=admin, data={'AUTH_LDAP_BIND_DN': u'cn=暴力膜,dc=大新闻,dc=真的粉丝'}, expect=200)
@pytest.mark.django_db
@pytest.mark.parametrize('value', [
None, '', 'INVALID', 1, [1], ['INVALID'],
])
def test_ldap_user_flags_by_group_invalid_dn(get, patch, admin, value):
url = reverse('api:setting_singleton_detail', kwargs={'category_slug': 'ldap'})
patch(url, user=admin,
data={'AUTH_LDAP_USER_FLAGS_BY_GROUP': {'is_superuser': value}},
expect=400)
@pytest.mark.django_db
def test_ldap_user_flags_by_group_string(get, patch, admin):
expected = 'CN=Admins,OU=Groups,DC=example,DC=com'
url = reverse('api:setting_singleton_detail', kwargs={'category_slug': 'ldap'})
patch(url, user=admin,
data={'AUTH_LDAP_USER_FLAGS_BY_GROUP': {'is_superuser': expected}},
expect=200)
resp = get(url, user=admin)
assert resp.data['AUTH_LDAP_USER_FLAGS_BY_GROUP']['is_superuser'] == [expected]
@pytest.mark.django_db
def test_ldap_user_flags_by_group_list(get, patch, admin):
expected = [
'CN=Admins,OU=Groups,DC=example,DC=com',
'CN=Superadmins,OU=Groups,DC=example,DC=com'
]
url = reverse('api:setting_singleton_detail', kwargs={'category_slug': 'ldap'})
patch(url, user=admin,
data={'AUTH_LDAP_USER_FLAGS_BY_GROUP': {'is_superuser': expected}},
expect=200)
resp = get(url, user=admin)
assert resp.data['AUTH_LDAP_USER_FLAGS_BY_GROUP']['is_superuser'] == expected
@pytest.mark.parametrize('setting', [
'AUTH_LDAP_USER_DN_TEMPLATE',
'AUTH_LDAP_REQUIRE_GROUP',

View File

@ -220,6 +220,18 @@ class LDAPDNField(fields.CharField):
return None if value == '' else value
class LDAPDNListField(fields.StringListField):
def __init__(self, **kwargs):
super(LDAPDNListField, self).__init__(**kwargs)
self.validators.append(lambda dn: map(validate_ldap_dn, dn))
def run_validation(self, data=empty):
if not isinstance(data, (list, tuple)):
data = [data]
return super(LDAPDNListField, self).run_validation(data)
class LDAPDNWithUserField(fields.CharField):
def __init__(self, **kwargs):
@ -431,7 +443,7 @@ class LDAPUserFlagsField(fields.DictField):
'invalid_flag': _('Invalid user flag: "{invalid_flag}".'),
}
valid_user_flags = {'is_superuser', 'is_system_auditor'}
child = LDAPDNField()
child = LDAPDNListField()
def to_internal_value(self, data):
data = super(LDAPUserFlagsField, self).to_internal_value(data)