Permalink
Browse files

DummySession: Correctly implement ISession by generating CSRF token i…

…f it's missing
  • Loading branch information...
1 parent 42ef9d7 commit 4d20038ead23d708bdcbbeacb3c2a09496c10930 @rbu committed Nov 2, 2011
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
@@ -620,7 +620,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
+
@implementer(IRequest)
class DummyRequest(DeprecatedRequestMethodsMixin, URLMethodsMixin,
View
5 pyramid/tests/test_testing.py
@@ -894,6 +894,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 implementer

0 comments on commit 4d20038

Please sign in to comment.