from django.core.cache import cache from django.core.handlers.wsgi import WSGIRequest from django.db import close_connection from django.template import context import mock import session_csrf from session_csrf import (anonymous_csrf, anonymous_csrf_exempt, CsrfMiddleware, PREFIX) urlpatterns = patterns('', ('^$', lambda r: http.HttpResponse()), ('^anon$', anonymous_csrf(lambda r: http.HttpResponse())), ('^no-anon-csrf$', anonymous_csrf_exempt(lambda r: http.HttpResponse())), ('^logout$', anonymous_csrf(lambda r: logout(r) or http.HttpResponse())), ) class TestCsrfToken(django.test.TestCase): def setUp(self): self.client.handler = ClientHandler() User.objects.create_user('jbalogh', '*****@*****.**', 'password') self.save_ANON_ALWAYS = session_csrf.ANON_ALWAYS session_csrf.ANON_ALWAYS = False def tearDown(self): session_csrf.ANON_ALWAYS = self.save_ANON_ALWAYS
from django.core.cache import cache from django.core.handlers.wsgi import WSGIRequest from django.db import close_connection from django.template import context import mock import session_csrf from session_csrf import (anonymous_csrf, anonymous_csrf_exempt, CsrfMiddleware, prep_key) urlpatterns = patterns( '', ('^$', lambda r: http.HttpResponse()), ('^anon$', anonymous_csrf(lambda r: http.HttpResponse())), ('^no-anon-csrf$', anonymous_csrf_exempt(lambda r: http.HttpResponse())), ('^logout$', anonymous_csrf(lambda r: logout(r) or http.HttpResponse())), ) class TestCsrfToken(django.test.TestCase): def setUp(self): self.client.handler = ClientHandler() User.objects.create_user('jbalogh', '*****@*****.**', 'password') self.save_ANON_ALWAYS = session_csrf.ANON_ALWAYS session_csrf.ANON_ALWAYS = False def tearDown(self): session_csrf.ANON_ALWAYS = self.save_ANON_ALWAYS def login(self):
(r'', include('examples.urls')), (r'^badges/', include('badger_multiplayer.urls')), (r'^badges/', include('badger.urls')), (r'^comments/', include('django.contrib.comments.urls')), (r'^profiles/', include('profiles.urls')), (r'^accounts/', include('django.contrib.auth.urls')), (r'^accounts/', include('registration.backends.default.urls')), (r'^admin/', include(admin.site.urls)), #(r'^browserid/', include('django_browserid.urls')), # HACK: CSRF troubles wth browserid auth url(r'^browserid/verify/', anonymous_csrf_exempt(django_browserid.views.verify), name="browserid_verify"), ) ## In DEBUG mode, serve media files through Django. if settings.DEBUG: # Remove leading and trailing slashes so the regex matches. media_url = settings.MEDIA_URL.lstrip('/').rstrip('/') urlpatterns += patterns('', (r'^%s/(?P<path>.*)$' % media_url, 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), )
from django.core.exceptions import ImproperlyConfigured import session_csrf from session_csrf import (anonymous_csrf, anonymous_csrf_exempt, CsrfMiddleware, prep_key) try: from unittest import mock except ImportError: # Python 2.7 doesn't have unittest.mock, but it is available on PyPi import mock urlpatterns = [ url('^$', lambda r: http.HttpResponse()), url('^anon$', anonymous_csrf(lambda r: http.HttpResponse())), url('^no-anon-csrf$', anonymous_csrf_exempt(lambda r: http.HttpResponse())), url('^logout$', anonymous_csrf(lambda r: logout(r) or http.HttpResponse())), ] class TestCsrfToken(django.test.TestCase): def setUp(self): self.client.handler = ClientHandler() User.objects.create_user('jbalogh', '*****@*****.**', 'password') self.save_ANON_ALWAYS = session_csrf.ANON_ALWAYS session_csrf.ANON_ALWAYS = False def tearDown(self): session_csrf.ANON_ALWAYS = self.save_ANON_ALWAYS