Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert unicode tokens to 'str' #314

Merged
merged 1 commit into from
Oct 11, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyramid/authentication.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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