Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 2 changed files with 10 additions and 1 deletion. Show diff stats Hide diff stats

  1. +5 1 pyramid/testing.py
  2. +5 0 pyramid/tests/test_testing.py
6 pyramid/testing.py
@@ -620,7 +620,11 @@ def new_csrf_token(self):
620 620 return token
621 621
622 622 def get_csrf_token(self):
623   - return self.get('_csrft_', None)
  623 + token = self.get('_csrft_', None)
  624 + if token is None:
  625 + token = self.new_csrf_token()
  626 + return token
  627 +
624 628
625 629 @implementer(IRequest)
626 630 class DummyRequest(DeprecatedRequestMethodsMixin, URLMethodsMixin,
5 pyramid/tests/test_testing.py
@@ -894,6 +894,11 @@ def test_get_csrf_token(self):
894 894 self.assertEqual(token, 'token')
895 895 self.assertTrue('_csrft_' in session)
896 896
  897 + def test_get_csrf_token_generates_token(self):
  898 + session = self._makeOne()
  899 + token = session.get_csrf_token()
  900 + self.assertNotEqual(token, None)
  901 + self.assertTrue(len(token) >= 1)
897 902
898 903 from zope.interface import Interface
899 904 from zope.interface import implementer

0 comments on commit 4d20038

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