Author: russellm
Date: 2010-12-03 22:47:59 -0600 (Fri, 03 Dec 2010)
New Revision: 14793

Modified:
   django/trunk/django/contrib/auth/__init__.py
   django/trunk/django/contrib/auth/tests/__init__.py
   django/trunk/django/contrib/auth/tests/auth_backends.py
Log:
Fixed #13190 -- Improved error handling for the case where no authentication 
backends are defined. Thanks to Joel3000 for the report, and ?\197?\129ukasz 
Rekucki for the final patch.

Modified: django/trunk/django/contrib/auth/__init__.py
===================================================================
--- django/trunk/django/contrib/auth/__init__.py        2010-12-04 04:34:04 UTC 
(rev 14792)
+++ django/trunk/django/contrib/auth/__init__.py        2010-12-04 04:47:59 UTC 
(rev 14793)
@@ -37,6 +37,8 @@
     backends = []
     for backend_path in settings.AUTHENTICATION_BACKENDS:
         backends.append(load_backend(backend_path))
+    if not backends:
+        raise ImproperlyConfigured('No authentication backends have been 
defined. Does AUTHENTICATION_BACKENDS contain anything?')
     return backends
 
 def authenticate(**credentials):

Modified: django/trunk/django/contrib/auth/tests/__init__.py
===================================================================
--- django/trunk/django/contrib/auth/tests/__init__.py  2010-12-04 04:34:04 UTC 
(rev 14792)
+++ django/trunk/django/contrib/auth/tests/__init__.py  2010-12-04 04:47:59 UTC 
(rev 14793)
@@ -1,4 +1,4 @@
-from django.contrib.auth.tests.auth_backends import BackendTest, 
RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest
+from django.contrib.auth.tests.auth_backends import BackendTest, 
RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest, 
NoBackendsTest
 from django.contrib.auth.tests.basic import BasicTestCase
 from django.contrib.auth.tests.decorators import LoginRequiredTestCase
 from django.contrib.auth.tests.forms import UserCreationFormTest, 
AuthenticationFormTest, SetPasswordFormTest, PasswordChangeFormTest, 
UserChangeFormTest, PasswordResetFormTest

Modified: django/trunk/django/contrib/auth/tests/auth_backends.py
===================================================================
--- django/trunk/django/contrib/auth/tests/auth_backends.py     2010-12-04 
04:34:04 UTC (rev 14792)
+++ django/trunk/django/contrib/auth/tests/auth_backends.py     2010-12-04 
04:47:59 UTC (rev 14793)
@@ -3,6 +3,7 @@
 from django.conf import settings
 from django.contrib.auth.models import User, Group, Permission, AnonymousUser
 from django.contrib.contenttypes.models import ContentType
+from django.core.exceptions import ImproperlyConfigured
 from django.test import TestCase
 
 
@@ -251,3 +252,18 @@
 
     def test_get_all_permissions(self):
         self.assertEqual(self.user1.get_all_permissions(TestObj()), set())
+
+class NoBackendsTest(TestCase):
+    """
+    Tests that an appropriate error is raised if no auth backends are provided.
+    """
+    def setUp(self):
+        self.old_AUTHENTICATION_BACKENDS = settings.AUTHENTICATION_BACKENDS
+        settings.AUTHENTICATION_BACKENDS = []
+        self.user = User.objects.create_user('test', '[email protected]', 
'test')
+
+    def tearDown(self):
+        settings.AUTHENTICATION_BACKENDS = self.old_AUTHENTICATION_BACKENDS
+
+    def test_raises_exception(self):
+        self.assertRaises(ImproperlyConfigured, self.user.has_perm, ('perm', 
TestObj(),))

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to