summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWichert Akkerman <wichert@wiggy.net>2011-09-28 10:37:40 +0200
committerWichert Akkerman <wichert@wiggy.net>2011-09-28 10:37:40 +0200
commitdd5a91eb937369d06f3fc438c817e046fc81f891 (patch)
tree98ae57cf94166e698351ab4f16d0a83236765687
parent54979dd45918ffbb411c8983d4194855856ed2aa (diff)
downloadpyramid-dd5a91eb937369d06f3fc438c817e046fc81f891.tar.gz
pyramid-dd5a91eb937369d06f3fc438c817e046fc81f891.tar.bz2
pyramid-dd5a91eb937369d06f3fc438c817e046fc81f891.zip
Accept unicode token instances with ascii content
This is required when reissueing cookies which include a token: WebOb returns the tokens from a cookie as unicode instances, so remember() must be able to deal with them when refreshing.
-rw-r--r--pyramid/authentication.py2
-rw-r--r--pyramid/tests/test_authentication.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/pyramid/authentication.py b/pyramid/authentication.py
index e38c984b3..ed422b044 100644
--- a/pyramid/authentication.py
+++ b/pyramid/authentication.py
@@ -729,7 +729,7 @@ class AuthTktCookieHelper(object):
for token in tokens:
if isinstance(token, text_type):
try:
- token.encode('ascii')
+ token = token.encode('ascii')
except UnicodeEncodeError:
raise ValueError("Invalid token %r" % (token,))
if not (isinstance(token, str) and VALID_TOKEN.match(token)):
diff --git a/pyramid/tests/test_authentication.py b/pyramid/tests/test_authentication.py
index b612c5789..6b8393fc2 100644
--- a/pyramid/tests/test_authentication.py
+++ b/pyramid/tests/test_authentication.py
@@ -616,6 +616,7 @@ class TestAuthTktCookieHelper(unittest.TestCase):
now = time.time()
helper.auth_tkt.timestamp = now
helper.now = now + 1
+ helper.auth_tkt.tokens = (u'a', )
request = self._makeRequest('bogus')
result = helper.identify(request)
self.assertTrue(result)
@@ -907,6 +908,12 @@ class TestAuthTktCookieHelper(unittest.TestCase):
self.assertEqual(result[2][0], 'Set-Cookie')
self.assertTrue("'tokens': ('foo', 'bar')" in result[2][1])
+ 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,))
+
def test_remember_nonascii_token(self):
helper = self._makeOne('secret')
request = self._makeRequest()