|
@@ -474,21 +474,32 @@ class TestUserAdminLdap(BaseUserAdminTests):
|
|
|
assert_false(User.objects.filter(username='Rock').exists())
|
|
assert_false(User.objects.filter(username='Rock').exists())
|
|
|
assert_true(User.objects.filter(username='rock').exists())
|
|
assert_true(User.objects.filter(username='rock').exists())
|
|
|
|
|
|
|
|
- # Test upper case
|
|
|
|
|
- User.objects.filter(username__iexact='rock').delete()
|
|
|
|
|
- import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'rock', sync_groups=False, import_by_dn=False)
|
|
|
|
|
- assert_false(User.objects.filter(username='Rock').exists())
|
|
|
|
|
- assert_true(User.objects.filter(username='ROCK').exists())
|
|
|
|
|
|
|
+ finally:
|
|
|
|
|
+ for finish in done:
|
|
|
|
|
+ finish()
|
|
|
|
|
|
|
|
- done.append(desktop.conf.LDAP.FORCE_USERNAME_UPPERCASE.set_for_testing(True))
|
|
|
|
|
|
|
|
|
|
- import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'Rock', sync_groups=False, import_by_dn=False)
|
|
|
|
|
- assert_false(User.objects.filter(username='Rock').exists())
|
|
|
|
|
- assert_true(User.objects.filter(username='ROCK').exists())
|
|
|
|
|
|
|
+ def test_useradmin_ldap_force_uppercase(self):
|
|
|
|
|
+ if is_live_cluster():
|
|
|
|
|
+ raise SkipTest('HUE-2897: Skipping because the DB may not be case sensitive')
|
|
|
|
|
+
|
|
|
|
|
+ done = []
|
|
|
|
|
+
|
|
|
|
|
+ # Set to nonsensical value just to force new config usage.
|
|
|
|
|
+ # Should continue to use cached connection.
|
|
|
|
|
+ done.append(desktop.conf.LDAP.LDAP_SERVERS.set_for_testing(get_nonsense_config()))
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
|
|
|
|
|
+ ldap_access.CACHED_LDAP_CONN = LdapTestConnection()
|
|
|
|
|
+
|
|
|
|
|
+ # Test upper case
|
|
|
|
|
+ User.objects.filter(username__iexact='Rock').delete()
|
|
|
|
|
+ done.append(desktop.conf.LDAP.IGNORE_USERNAME_CASE.set_for_testing(False))
|
|
|
|
|
+ done.append(desktop.conf.LDAP.FORCE_USERNAME_LOWERCASE.set_for_testing(False))
|
|
|
|
|
+ done.append(desktop.conf.LDAP.FORCE_USERNAME_UPPERCASE.set_for_testing(True))
|
|
|
|
|
|
|
|
- User.objects.filter(username='Rock').delete()
|
|
|
|
|
import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'Rock', sync_groups=False, import_by_dn=False)
|
|
import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'Rock', sync_groups=False, import_by_dn=False)
|
|
|
- assert_false(User.objects.filter(username='Rock').exists())
|
|
|
|
|
assert_true(User.objects.filter(username='ROCK').exists())
|
|
assert_true(User.objects.filter(username='ROCK').exists())
|
|
|
finally:
|
|
finally:
|
|
|
for finish in done:
|
|
for finish in done:
|
|
@@ -548,17 +559,6 @@ class TestUserAdminLdap(BaseUserAdminTests):
|
|
|
assert_false(User.objects.filter(username='Rock').exists())
|
|
assert_false(User.objects.filter(username='Rock').exists())
|
|
|
assert_true(User.objects.filter(username='rock').exists())
|
|
assert_true(User.objects.filter(username='rock').exists())
|
|
|
|
|
|
|
|
- # Test upper case
|
|
|
|
|
- done.append(desktop.conf.LDAP.FORCE_USERNAME_UPPERCASE.set_for_testing(True))
|
|
|
|
|
- User.objects.filter(username__iexact='Rock').delete()
|
|
|
|
|
- assert_false(User.objects.filter(username='Rock').exists())
|
|
|
|
|
- assert_false(User.objects.filter(username='ROCK').exists())
|
|
|
|
|
- response = c.post(URL, dict(server='nonsense', username_pattern='ROCK', password1='test', password2='test'))
|
|
|
|
|
- assert_true('Location' in response, response)
|
|
|
|
|
- assert_true('/useradmin/users' in response['Location'], response)
|
|
|
|
|
- assert_false(User.objects.filter(username='Rock').exists())
|
|
|
|
|
- assert_true(User.objects.filter(username='ROCK').exists())
|
|
|
|
|
-
|
|
|
|
|
# Test regular with spaces (should fail)
|
|
# Test regular with spaces (should fail)
|
|
|
response = c.post(URL, dict(server='nonsense', username_pattern='user with space', password1='test', password2='test'))
|
|
response = c.post(URL, dict(server='nonsense', username_pattern='user with space', password1='test', password2='test'))
|
|
|
assert_true("Username must not contain whitespaces and ':'" in response.context['form'].errors['username_pattern'][0], response)
|
|
assert_true("Username must not contain whitespaces and ':'" in response.context['form'].errors['username_pattern'][0], response)
|
|
@@ -578,6 +578,44 @@ class TestUserAdminLdap(BaseUserAdminTests):
|
|
|
finish()
|
|
finish()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ def test_add_ldap_users_force_uppercase(self):
|
|
|
|
|
+ if is_live_cluster():
|
|
|
|
|
+ raise SkipTest('HUE-2897: Skipping because the DB may not be case sensitive')
|
|
|
|
|
+
|
|
|
|
|
+ done = []
|
|
|
|
|
+
|
|
|
|
|
+ # Set to nonsensical value just to force new config usage.
|
|
|
|
|
+ # Should continue to use cached connection.
|
|
|
|
|
+ done.append(desktop.conf.LDAP.LDAP_SERVERS.set_for_testing(get_nonsense_config()))
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ URL = reverse(add_ldap_users)
|
|
|
|
|
+
|
|
|
|
|
+ # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
|
|
|
|
|
+ ldap_access.CACHED_LDAP_CONN = LdapTestConnection()
|
|
|
|
|
+
|
|
|
|
|
+ c = make_logged_in_client('test', is_superuser=True)
|
|
|
|
|
+
|
|
|
|
|
+ assert_true(c.get(URL))
|
|
|
|
|
+
|
|
|
|
|
+ # Test upper case
|
|
|
|
|
+ done.append(desktop.conf.LDAP.IGNORE_USERNAME_CASE.set_for_testing(False))
|
|
|
|
|
+ done.append(desktop.conf.LDAP.FORCE_USERNAME_LOWERCASE.set_for_testing(False))
|
|
|
|
|
+ done.append(desktop.conf.LDAP.FORCE_USERNAME_UPPERCASE.set_for_testing(True))
|
|
|
|
|
+
|
|
|
|
|
+ User.objects.filter(username='rock').delete()
|
|
|
|
|
+ assert_false(User.objects.filter(username='Rock').exists())
|
|
|
|
|
+ assert_false(User.objects.filter(username='ROCK').exists())
|
|
|
|
|
+
|
|
|
|
|
+ response = c.post(URL, dict(server='nonsense', username_pattern='Rock', password1='test', password2='test'))
|
|
|
|
|
+ assert_true('Location' in response, response)
|
|
|
|
|
+ assert_true('/useradmin/users' in response['Location'], response)
|
|
|
|
|
+ assert_true(User.objects.filter(username='ROCK').exists())
|
|
|
|
|
+ finally:
|
|
|
|
|
+ for finish in done:
|
|
|
|
|
+ finish()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def test_add_ldap_groups(self):
|
|
def test_add_ldap_groups(self):
|
|
|
URL = reverse(add_ldap_groups)
|
|
URL = reverse(add_ldap_groups)
|
|
|
|
|
|