1. Mikhail Korobov
  2. django-webtest

Commits

Mikhail Korobov  committed ca7ca08

REMOTE_USER authorization can now be disabled

  • Participants
  • Parent commits 587cc8e
  • Branches default

Comments (0)

Files changed (2)

File CHANGES.txt

View file
  • Ignore whitespace
 CHANGES
 =======
 
+1.2.1 (2010-08-24)
+------------------
+
+- REMOTE_USER authorization can be disabled
+
 1.2 (2010-08-21)
 ----------------
 

File django_webtest/__init__.py

View file
  • Ignore whitespace
 
     extra_environ = {}
     csrf_checks = True
+    setup_auth = True
 
     def _patch_settings(self):
         ''' Patch settings to add support for REMOTE_USER authorization
         self._AUTHENTICATION_BACKENDS = settings.AUTHENTICATION_BACKENDS[:]
 
         if not self.csrf_checks:
-            disable_csrf_middleware = 'django_webtest.middleware.DisableCSRFCheckMiddleware'
-            if not disable_csrf_middleware in settings.MIDDLEWARE_CLASSES:
-                settings.MIDDLEWARE_CLASSES = (disable_csrf_middleware,) + settings.MIDDLEWARE_CLASSES
+            self._disable_csrf_checks()
 
+        if self.setup_auth:
+            self._setup_auth()
+
+    def _unpatch_settings(self):
+        ''' Restore settings to before-patching state '''
+        settings.MIDDLEWARE_CLASSES = self._MIDDLEWARE_CLASSES
+        settings.AUTHENTICATION_BACKENDS = self._AUTHENTICATION_BACKENDS
+
+    def _disable_csrf_checks(self):
+        disable_csrf_middleware = 'django_webtest.middleware.DisableCSRFCheckMiddleware'
+        if not disable_csrf_middleware in settings.MIDDLEWARE_CLASSES:
+            settings.MIDDLEWARE_CLASSES = (disable_csrf_middleware,) + settings.MIDDLEWARE_CLASSES
+
+    def _setup_auth(self):
         remote_user_middleware = 'django.contrib.auth.middleware.RemoteUserMiddleware'
         if not remote_user_middleware in settings.MIDDLEWARE_CLASSES:
             settings.MIDDLEWARE_CLASSES += (remote_user_middleware,)
             auth_backends.append('django.contrib.auth.backends.RemoteUserBackend')
         settings.AUTHENTICATION_BACKENDS = auth_backends
 
-    def _unpatch_settings(self):
-        ''' Restore settings to before-patching state '''
-        settings.MIDDLEWARE_CLASSES = self._MIDDLEWARE_CLASSES
-        settings.AUTHENTICATION_BACKENDS = self._AUTHENTICATION_BACKENDS
-
     def __call__(self, result=None):
         self._patch_settings()
         self.app = DjangoTestApp(extra_environ=self.extra_environ)