Ticket #13190: 13190_empty_auth_backends.diff

File 13190_empty_auth_backends.diff, 2.6 KB (added by gabrielhurley, 4 years ago)
  • django/contrib/auth/__init__.py

     
    3939    backends = []
    4040    for backend_path in settings.AUTHENTICATION_BACKENDS:
    4141        backends.append(load_backend(backend_path))
     42    if len(backends) == 0:
     43        raise ImproperlyConfigured, 'settings.AUTHENTICATION_BACKENDS is empty.'
    4244    return backends
    4345
    4446def authenticate(**credentials):
  • django/contrib/auth/tests/__init__.py

     
    1 from django.contrib.auth.tests.auth_backends import BackendTest, RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest
     1from django.contrib.auth.tests.auth_backends import BackendTest, RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest, NoBackendTest
    22from django.contrib.auth.tests.basic import BASIC_TESTS
    33from django.contrib.auth.tests.decorators import LoginRequiredTestCase
    44from django.contrib.auth.tests.forms import UserCreationFormTest, AuthenticationFormTest, SetPasswordFormTest, PasswordChangeFormTest, UserChangeFormTest, PasswordResetFormTest
  • django/contrib/auth/tests/auth_backends.py

     
    11from django.conf import settings
    22from django.contrib.auth.models import User, Group, Permission, AnonymousUser
    33from django.contrib.contenttypes.models import ContentType
     4from django.core.exceptions import ImproperlyConfigured
    45from django.test import TestCase
    56
    67
     
    245246
    246247    def test_get_all_permissions(self):
    247248        self.assertEqual(self.user1.get_all_permissions(TestObj()), set())
     249
     250class NoBackendTest(TestCase):
     251    """
     252    Tests that an appropriate error is raised if no auth backends are provided.
     253    """
     254    backend = ()
     255
     256    def setUp(self):
     257        self.curr_auth = settings.AUTHENTICATION_BACKENDS
     258        settings.AUTHENTICATION_BACKENDS = self.backend
     259        self.user = User.objects.create_user('test', 'test@example.com', 'test')
     260
     261    def tearDown(self):
     262        settings.AUTHENTICATION_BACKENDS = self.curr_auth
     263
     264    def test_raises_exception(self):
     265        self.assertRaises(ImproperlyConfigured, self.user.has_perm, ('perm', TestObj(),))
Back to Top