|
@@ -20,25 +20,26 @@ import json
|
|
|
import ldap
|
|
import ldap
|
|
|
import re
|
|
import re
|
|
|
import sys
|
|
import sys
|
|
|
|
|
+import time
|
|
|
import urllib
|
|
import urllib
|
|
|
|
|
|
|
|
-from nose.plugins.attrib import attr
|
|
|
|
|
from nose.plugins.skip import SkipTest
|
|
from nose.plugins.skip import SkipTest
|
|
|
from nose.tools import assert_true, assert_equal, assert_false, assert_not_equal
|
|
from nose.tools import assert_true, assert_equal, assert_false, assert_not_equal
|
|
|
|
|
|
|
|
-import desktop.conf
|
|
|
|
|
-from desktop.lib.django_test_util import make_logged_in_client
|
|
|
|
|
from django.contrib.auth.models import User, Group
|
|
from django.contrib.auth.models import User, Group
|
|
|
from django.utils.encoding import smart_unicode
|
|
from django.utils.encoding import smart_unicode
|
|
|
from django.core.urlresolvers import reverse
|
|
from django.core.urlresolvers import reverse
|
|
|
from django.test.client import Client
|
|
from django.test.client import Client
|
|
|
|
|
|
|
|
-from useradmin.models import HuePermission, GroupPermission, UserProfile
|
|
|
|
|
-from useradmin.models import get_profile, get_default_user_group
|
|
|
|
|
|
|
+import desktop.conf
|
|
|
|
|
+from desktop.lib.django_test_util import make_logged_in_client
|
|
|
|
|
+from desktop.views import home
|
|
|
|
|
+from hadoop import pseudo_hdfs4
|
|
|
|
|
|
|
|
import useradmin.conf
|
|
import useradmin.conf
|
|
|
import useradmin.ldap_access
|
|
import useradmin.ldap_access
|
|
|
-from hadoop import pseudo_hdfs4
|
|
|
|
|
|
|
+from useradmin.models import HuePermission, GroupPermission, UserProfile
|
|
|
|
|
+from useradmin.models import get_profile, get_default_user_group
|
|
|
from useradmin.password_policy import reset_password_policy
|
|
from useradmin.password_policy import reset_password_policy
|
|
|
|
|
|
|
|
|
|
|
|
@@ -47,6 +48,7 @@ def reset_all_users():
|
|
|
for user in User.objects.all():
|
|
for user in User.objects.all():
|
|
|
user.delete()
|
|
user.delete()
|
|
|
|
|
|
|
|
|
|
+
|
|
|
def reset_all_groups():
|
|
def reset_all_groups():
|
|
|
"""Reset to a clean state by deleting all groups"""
|
|
"""Reset to a clean state by deleting all groups"""
|
|
|
|
|
|
|
@@ -222,6 +224,7 @@ def test_invalid_username():
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseUserAdminTests(object):
|
|
class BaseUserAdminTests(object):
|
|
|
|
|
+
|
|
|
@classmethod
|
|
@classmethod
|
|
|
def setUpClass(cls):
|
|
def setUpClass(cls):
|
|
|
cls._class_resets = [
|
|
cls._class_resets = [
|
|
@@ -242,6 +245,7 @@ class BaseUserAdminTests(object):
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestUserAdmin(BaseUserAdminTests):
|
|
class TestUserAdmin(BaseUserAdminTests):
|
|
|
|
|
+
|
|
|
def test_group_permissions(self):
|
|
def test_group_permissions(self):
|
|
|
# Get ourselves set up with a user and a group
|
|
# Get ourselves set up with a user and a group
|
|
|
c = make_logged_in_client(username="test", is_superuser=True)
|
|
c = make_logged_in_client(username="test", is_superuser=True)
|
|
@@ -294,6 +298,7 @@ class TestUserAdmin(BaseUserAdminTests):
|
|
|
response = c1.get('/useradmin/users')
|
|
response = c1.get('/useradmin/users')
|
|
|
assert_true('You do not have permission to access the Useradmin application.' in response.content)
|
|
assert_true('You do not have permission to access the Useradmin application.' in response.content)
|
|
|
|
|
|
|
|
|
|
+
|
|
|
def test_default_group(self):
|
|
def test_default_group(self):
|
|
|
resets = [
|
|
resets = [
|
|
|
useradmin.conf.DEFAULT_USER_GROUP.set_for_testing('test_default')
|
|
useradmin.conf.DEFAULT_USER_GROUP.set_for_testing('test_default')
|
|
@@ -390,6 +395,7 @@ class TestUserAdmin(BaseUserAdminTests):
|
|
|
response = c.post('/useradmin/groups/new', dict(name="with space"))
|
|
response = c.post('/useradmin/groups/new', dict(name="with space"))
|
|
|
assert_equal(len(Group.objects.all()), group_count + 1)
|
|
assert_equal(len(Group.objects.all()), group_count + 1)
|
|
|
|
|
|
|
|
|
|
+
|
|
|
def test_user_admin_password_policy(self):
|
|
def test_user_admin_password_policy(self):
|
|
|
# Set up password policy
|
|
# Set up password policy
|
|
|
password_hint = password_error_msg = ("The password must be at least 8 characters long, "
|
|
password_hint = password_error_msg = ("The password must be at least 8 characters long, "
|
|
@@ -684,7 +690,6 @@ class TestUserAdmin(BaseUserAdminTests):
|
|
|
reset()
|
|
reset()
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
def test_list_for_autocomplete(self):
|
|
def test_list_for_autocomplete(self):
|
|
|
# Now the autocomplete has access to all the users and groups
|
|
# Now the autocomplete has access to all the users and groups
|
|
|
c1 = make_logged_in_client('test_list_for_autocomplete', is_superuser=False, groupname='test_list_for_autocomplete')
|
|
c1 = make_logged_in_client('test_list_for_autocomplete', is_superuser=False, groupname='test_list_for_autocomplete')
|
|
@@ -726,6 +731,7 @@ class TestUserAdmin(BaseUserAdminTests):
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestUserAdminWithHadoop(BaseUserAdminTests):
|
|
class TestUserAdminWithHadoop(BaseUserAdminTests):
|
|
|
|
|
+
|
|
|
requires_hadoop = True
|
|
requires_hadoop = True
|
|
|
|
|
|
|
|
def test_ensure_home_directory(self):
|
|
def test_ensure_home_directory(self):
|
|
@@ -766,6 +772,7 @@ class TestUserAdminWithHadoop(BaseUserAdminTests):
|
|
|
for reset in resets:
|
|
for reset in resets:
|
|
|
reset()
|
|
reset()
|
|
|
|
|
|
|
|
|
|
+
|
|
|
class MockLdapConnection(object):
|
|
class MockLdapConnection(object):
|
|
|
def __init__(self, ldap_config, ldap_url, username, password, ldap_cert):
|
|
def __init__(self, ldap_config, ldap_url, username, password, ldap_cert):
|
|
|
self.ldap_config = ldap_config
|
|
self.ldap_config = ldap_config
|
|
@@ -774,6 +781,7 @@ class MockLdapConnection(object):
|
|
|
self.password = password
|
|
self.password = password
|
|
|
self.ldap_cert = ldap_cert
|
|
self.ldap_cert = ldap_cert
|
|
|
|
|
|
|
|
|
|
+
|
|
|
def test_get_connection_bind_password():
|
|
def test_get_connection_bind_password():
|
|
|
# Unfortunately our tests leak a cached test ldap connection across functions, so we need to clear it out.
|
|
# Unfortunately our tests leak a cached test ldap connection across functions, so we need to clear it out.
|
|
|
useradmin.ldap_access.CACHED_LDAP_CONN = None
|
|
useradmin.ldap_access.CACHED_LDAP_CONN = None
|
|
@@ -803,6 +811,7 @@ def test_get_connection_bind_password():
|
|
|
for f in reset:
|
|
for f in reset:
|
|
|
f()
|
|
f()
|
|
|
|
|
|
|
|
|
|
+
|
|
|
def test_get_connection_bind_password_script():
|
|
def test_get_connection_bind_password_script():
|
|
|
# Unfortunately our tests leak a cached test ldap connection across functions, so we need to clear it out.
|
|
# Unfortunately our tests leak a cached test ldap connection across functions, so we need to clear it out.
|
|
|
useradmin.ldap_access.CACHED_LDAP_CONN = None
|
|
useradmin.ldap_access.CACHED_LDAP_CONN = None
|
|
@@ -837,7 +846,50 @@ def test_get_connection_bind_password_script():
|
|
|
for f in reset:
|
|
for f in reset:
|
|
|
f()
|
|
f()
|
|
|
|
|
|
|
|
-def test_last_activity():
|
|
|
|
|
- c = make_logged_in_client(username="test", is_superuser=True)
|
|
|
|
|
- profile = UserProfile.objects.get(user__username='test')
|
|
|
|
|
- assert_not_equal(profile.last_activity, 0)
|
|
|
|
|
|
|
+
|
|
|
|
|
+class BaseUserAdminTests(object):
|
|
|
|
|
+
|
|
|
|
|
+ def test_last_activity(self):
|
|
|
|
|
+ c = make_logged_in_client(username="test", is_superuser=True)
|
|
|
|
|
+ profile = UserProfile.objects.get(user__username='test')
|
|
|
|
|
+ assert_not_equal(profile.last_activity, 0)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ def test_idle_timeout(self):
|
|
|
|
|
+ timeout = 5
|
|
|
|
|
+ reset = [
|
|
|
|
|
+ desktop.conf.AUTH.IDLE_SESSION_TIMEOUT.set_for_testing(timeout)
|
|
|
|
|
+ ]
|
|
|
|
|
+ try:
|
|
|
|
|
+ c = make_logged_in_client(username="test", is_superuser=True)
|
|
|
|
|
+ response = c.get(reverse(home))
|
|
|
|
|
+ assert_equal(200, response.status_code)
|
|
|
|
|
+
|
|
|
|
|
+ # Assert after timeout that user is redirected to login
|
|
|
|
|
+ time.sleep(timeout)
|
|
|
|
|
+ response = c.get(reverse(home))
|
|
|
|
|
+ assert_equal(302, response.status_code)
|
|
|
|
|
+ finally:
|
|
|
|
|
+ for f in reset:
|
|
|
|
|
+ f()
|
|
|
|
|
+
|
|
|
|
|
+ def test_ignore_jobbrowser_polling(self):
|
|
|
|
|
+ timeout = 5
|
|
|
|
|
+ reset = [
|
|
|
|
|
+ desktop.conf.AUTH.IDLE_SESSION_TIMEOUT.set_for_testing(timeout)
|
|
|
|
|
+ ]
|
|
|
|
|
+ try:
|
|
|
|
|
+ c = make_logged_in_client(username="test", is_superuser=True)
|
|
|
|
|
+ response = c.get(reverse(home))
|
|
|
|
|
+ assert_equal(200, response.status_code)
|
|
|
|
|
+
|
|
|
|
|
+ # Assert that jobbrowser polling does not reset idle time
|
|
|
|
|
+ time.sleep(2)
|
|
|
|
|
+ c.get('jobbrowser/?format=json&state=running&user=%s' % "test")
|
|
|
|
|
+ time.sleep(3)
|
|
|
|
|
+
|
|
|
|
|
+ response = c.get(reverse(home))
|
|
|
|
|
+ assert_equal(302, response.status_code)
|
|
|
|
|
+ finally:
|
|
|
|
|
+ for f in reset:
|
|
|
|
|
+ f()
|