diff options
| author | Chris McDonough <chrism@plope.com> | 2011-09-28 04:55:36 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-09-28 04:55:36 -0400 |
| commit | bdfb877ab4c7c2ea9f1e9fe6aacd1865612c86cc (patch) | |
| tree | a04d9fa22d2f221d9129ac551c8d547de5d9b9e7 | |
| parent | 9871015cb19de379a34c60d7f2854257f2782181 (diff) | |
| parent | 9f2d38c1cf8b88658c3600afab195cb3686300b8 (diff) | |
| download | pyramid-bdfb877ab4c7c2ea9f1e9fe6aacd1865612c86cc.tar.gz pyramid-bdfb877ab4c7c2ea9f1e9fe6aacd1865612c86cc.tar.bz2 pyramid-bdfb877ab4c7c2ea9f1e9fe6aacd1865612c86cc.zip | |
Merge branch 'wichert-token-reissue'
| -rw-r--r-- | pyramid/authentication.py | 3 | ||||
| -rw-r--r-- | pyramid/tests/test_authentication.py | 7 |
2 files changed, 9 insertions, 1 deletions
diff --git a/pyramid/authentication.py b/pyramid/authentication.py index e38c984b3..245a9692f 100644 --- a/pyramid/authentication.py +++ b/pyramid/authentication.py @@ -14,6 +14,7 @@ from pyramid.compat import binary_type from pyramid.compat import url_unquote from pyramid.compat import url_quote from pyramid.compat import bytes_ +from pyramid.compat import ascii_native_ from pyramid.interfaces import IAuthenticationPolicy from pyramid.interfaces import IDebugLogger @@ -729,7 +730,7 @@ class AuthTktCookieHelper(object): for token in tokens: if isinstance(token, text_type): try: - token.encode('ascii') + token = ascii_native_(token) 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..6bf14e76c 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 = (text_('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() |
