summaryrefslogtreecommitdiff
path: root/lib/python2.7/site-packages/django/contrib/auth/tests/test_handlers.py
diff options
context:
space:
mode:
authorttt2017-05-13 00:29:47 +0530
committerttt2017-05-13 00:29:47 +0530
commitabf599be33b383a6a5baf9493093b2126a622ac8 (patch)
tree4c5ab6e0d935d5e65fabcf0258e4a00dd20a5afa /lib/python2.7/site-packages/django/contrib/auth/tests/test_handlers.py
downloadSBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.gz
SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.bz2
SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.zip
added all server files
Diffstat (limited to 'lib/python2.7/site-packages/django/contrib/auth/tests/test_handlers.py')
-rw-r--r--lib/python2.7/site-packages/django/contrib/auth/tests/test_handlers.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/lib/python2.7/site-packages/django/contrib/auth/tests/test_handlers.py b/lib/python2.7/site-packages/django/contrib/auth/tests/test_handlers.py
new file mode 100644
index 0000000..b86775f
--- /dev/null
+++ b/lib/python2.7/site-packages/django/contrib/auth/tests/test_handlers.py
@@ -0,0 +1,79 @@
+from __future__ import unicode_literals
+
+from django.contrib.auth.handlers.modwsgi import check_password, groups_for_user
+from django.contrib.auth.models import User, Group
+from django.contrib.auth.tests.custom_user import CustomUser
+from django.contrib.auth.tests.utils import skipIfCustomUser
+from django.test import TransactionTestCase
+from django.test.utils import override_settings
+
+
+# This must be a TransactionTestCase because the WSGI auth handler performs
+# its own transaction management.
+class ModWsgiHandlerTestCase(TransactionTestCase):
+ """
+ Tests for the mod_wsgi authentication handler
+ """
+
+ available_apps = [
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ ]
+
+ @skipIfCustomUser
+ def test_check_password(self):
+ """
+ Verify that check_password returns the correct values as per
+ http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms#Apache_Authentication_Provider
+ """
+ User.objects.create_user('test', 'test@example.com', 'test')
+
+ # User not in database
+ self.assertTrue(check_password({}, 'unknown', '') is None)
+
+ # Valid user with correct password
+ self.assertTrue(check_password({}, 'test', 'test'))
+
+ # correct password, but user is inactive
+ User.objects.filter(username='test').update(is_active=False)
+ self.assertFalse(check_password({}, 'test', 'test'))
+
+ # Valid user with incorrect password
+ self.assertFalse(check_password({}, 'test', 'incorrect'))
+
+ @override_settings(AUTH_USER_MODEL='auth.CustomUser')
+ def test_check_password_custom_user(self):
+ """
+ Verify that check_password returns the correct values as per
+ http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms#Apache_Authentication_Provider
+
+ with custom user installed
+ """
+
+ CustomUser._default_manager.create_user('test@example.com', '1990-01-01', 'test')
+
+ # User not in database
+ self.assertTrue(check_password({}, 'unknown', '') is None)
+
+ # Valid user with correct password'
+ self.assertTrue(check_password({}, 'test@example.com', 'test'))
+
+ # Valid user with incorrect password
+ self.assertFalse(check_password({}, 'test@example.com', 'incorrect'))
+
+ @skipIfCustomUser
+ def test_groups_for_user(self):
+ """
+ Check that groups_for_user returns correct values as per
+ http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms#Apache_Group_Authorisation
+ """
+ user1 = User.objects.create_user('test', 'test@example.com', 'test')
+ User.objects.create_user('test1', 'test1@example.com', 'test1')
+ group = Group.objects.create(name='test_group')
+ user1.groups.add(group)
+
+ # User not in database
+ self.assertEqual(groups_for_user({}, 'unknown'), [])
+
+ self.assertEqual(groups_for_user({}, 'test'), [b'test_group'])
+ self.assertEqual(groups_for_user({}, 'test1'), [])