Ticket #2550: patch.diff
File patch.diff, 3.3 KB (added by , 14 years ago) |
---|
-
django/contrib/auth/__init__.py
1 1 import datetime 2 2 from warnings import warn 3 from django.core.exceptions import ImproperlyConfigured 3 from django.core.exceptions import ImproperlyConfigured,PermissionDenied 4 4 from django.utils.importlib import import_module 5 5 from django.contrib.auth.signals import user_logged_in, user_logged_out 6 6 … … 56 56 except TypeError: 57 57 # This backend doesn't accept these credentials as arguments. Try the next one. 58 58 continue 59 except PermissionDenied: 60 # This backend says to stop in our tracks - this user should not be allowed in at all. 61 return None 59 62 if user is None: 60 63 continue 61 64 # Annotate the user object with the path of the backend. -
django/contrib/auth/tests/auth_backends.py
354 354 self.assertEqual(self.user1.has_module_perms("app1"), False) 355 355 self.assertEqual(self.user1.has_module_perms("app2"), False) 356 356 357 class PermissionDeniedBackend(object): 358 """ 359 always raises PermissionDenied 360 """ 361 supports_object_permissions = False 362 supports_anonymous_user = False 363 364 def authenticate(self,username=None,password=None): 365 raise PermissionDenied 366 367 class PermissionDeniedBackendTest(TestCase): 368 """ 369 Tests that other backends are not checked once a backend raises PermissionDenied 370 """ 371 backend = 'django.contrib.auth.tests.auth_backends.PermissionDeniedBackend' 372 373 def setUp(self): 374 self.curr_auth = settings.AUTHENTICATION_BACKENDS 375 self.user1 = User.objects.create_user('test', 'test@example.com', 'test') 376 self.user1.save() 377 378 def tearDown(self): 379 settings.AUTHENTICATION_BACKENDS = self.curr_auth 380 381 def test_permission_denied(self): 382 "user is not authenticated after a backend raises permission denied #2550" 383 settings.AUTHENTICATION_BACKENDS = (self.backend,)+tuple(self.curr_auth) 384 self.assertEqual(authenticate(username='test',password='test'), None) 385 386 def test_authenticates(self): 387 settings.AUTHENTICATION_BACKENDS = tuple(self.curr_auth) + (self.backend,) 388 self.assertEqual(authenticate(username='test',password='test'),self.user1) 389 -
django/contrib/auth/tests/__init__.py
1 1 from django.contrib.auth.tests.auth_backends import (BackendTest, 2 2 RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest, 3 NoBackendsTest, InActiveUserBackendTest, NoInActiveUserBackendTest )3 NoBackendsTest, InActiveUserBackendTest, NoInActiveUserBackendTest,PermissionDeniedBackendTest) 4 4 from django.contrib.auth.tests.basic import BasicTestCase 5 5 from django.contrib.auth.tests.decorators import LoginRequiredTestCase 6 6 from django.contrib.auth.tests.forms import (UserCreationFormTest,