Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jinty/pyramid into jinty-…
Browse files Browse the repository at this point in the history
…master
  • Loading branch information
mcdonc committed Oct 11, 2011
2 parents c5724cb + c3c0bea commit aeb144c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pyramid/authentication.py
Expand Up @@ -726,7 +726,8 @@ def remember(self, request, userid, max_age=None, tokens=()):
encoding, encoder = encoding_data
userid = encoder(userid)
user_data = 'userid_type:%s' % encoding


new_tokens = []
for token in tokens:
if isinstance(token, text_type):
try:
Expand All @@ -735,6 +736,8 @@ def remember(self, request, userid, max_age=None, tokens=()):
raise ValueError("Invalid token %r" % (token,))
if not (isinstance(token, str) and VALID_TOKEN.match(token)):
raise ValueError("Invalid token %r" % (token,))
new_tokens.append(token)
tokens = tuple(new_tokens)

if hasattr(request, '_authtkt_reissued'):
request._authtkt_reissue_revoked = True
Expand Down
6 changes: 4 additions & 2 deletions pyramid/tests/test_authentication.py
Expand Up @@ -703,7 +703,7 @@ def test_identify_cookie_reissue_with_tokens_default(self):
request.callbacks[0](None, response)
self.assertEqual(len(response.headerlist), 3)
self.assertEqual(response.headerlist[0][0], 'Set-Cookie')
self.assertTrue("'tokens': []" in response.headerlist[0][1])
self.assertTrue("'tokens': ()" in response.headerlist[0][1])

def test_remember(self):
helper = self._makeOne('secret')
Expand Down Expand Up @@ -912,7 +912,9 @@ def test_remember_unicode_but_ascii_token(self):
helper = self._makeOne('secret')
request = self._makeRequest()
la = text_(b'foo', 'utf-8')
helper.remember(request, 'other', tokens=(la,))
result = helper.remember(request, 'other', tokens=(la,))
# tokens must be str type on both Python 2 and 3
self.assertTrue("'tokens': ('foo',)" in result[0][1])

def test_remember_nonascii_token(self):
helper = self._makeOne('secret')
Expand Down

0 comments on commit aeb144c

Please sign in to comment.