Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DummySession: Correctly implement ISession by generating CSRF token i…

…f it's missing
  • Loading branch information...
commit 1f8a007f51cda0f4ebfc74d1a178cbab136f5ea0 1 parent e61ab86
@rbu rbu authored mcdonc committed
Showing with 10 additions and 1 deletion.
  1. +5 −1 pyramid/testing.py
  2. +5 −0 pyramid/tests/test_testing.py
View
6 pyramid/testing.py
@@ -619,7 +619,11 @@ def new_csrf_token(self):
return token
def get_csrf_token(self):
- return self.get('_csrft_', None)
+ token = self.get('_csrft_', None)
+ if token is None:
+ token = self.new_csrf_token()
+ return token
+
class DummyRequest(DeprecatedRequestMethodsMixin, URLMethodsMixin,
CallbackMethodsMixin):
View
5 pyramid/tests/test_testing.py
@@ -886,6 +886,11 @@ def test_get_csrf_token(self):
self.assertEqual(token, 'token')
self.assertTrue('_csrft_' in session)
+ def test_get_csrf_token_generates_token(self):
+ session = self._makeOne()
+ token = session.get_csrf_token()
+ self.assertNotEqual(token, None)
+ self.assertTrue(len(token) >= 1)
from zope.interface import Interface
from zope.interface import implements

0 comments on commit 1f8a007

Please sign in to comment.
Something went wrong with that request. Please try again.