Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

DummySession: Correctly implement ISession by generating CSRF token i…

…f it's missing
  • Loading branch information...
commit 4d20038ead23d708bdcbbeacb3c2a09496c10930 1 parent 42ef9d7
Robert Buchholz authored
Showing with 10 additions and 1 deletion.
  1. +5 −1 pyramid/testing.py
  2. +5 −0 pyramid/tests/test_testing.py
6 pyramid/testing.py
View
@@ -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,
5 pyramid/tests/test_testing.py
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.