Mercurial > public > sg101
changeset 1174:ba3230aba90c
Fix unicode error with wiki cookie processing
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 07 Jun 2018 19:53:13 -0500 (2018-06-08) |
parents | a1a223ab0c8f |
children | 9caf10deb45c |
files | wiki/middleware.py wiki/tests/test_middleware.py |
diffstat | 2 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/wiki/middleware.py Sat Apr 14 14:03:04 2018 -0500 +++ b/wiki/middleware.py Thu Jun 07 19:53:13 2018 -0500 @@ -23,16 +23,18 @@ # The key part of the cookie is just a string that would make things # difficult for a spoofer; something that can't be easily made up: + username = user.username.encode('utf-8') + email = user.email.encode('utf-8') h = hashlib.sha256() - h.update(user.username.encode('utf-8')) - h.update(user.email.encode('utf-8')) + h.update(username) + h.update(email) h.update(now.isoformat()) h.update(''.join(random.sample(string.printable, 64))) h.update(settings.SECRET_KEY) key = h.hexdigest() - parts = (user.username, user.email, key) + parts = (username, email, key) return '#'.join(parts)
--- a/wiki/tests/test_middleware.py Sat Apr 14 14:03:04 2018 -0500 +++ b/wiki/tests/test_middleware.py Thu Jun 07 19:53:13 2018 -0500 @@ -1,3 +1,4 @@ +# coding=utf-8 """ Tests for the wiki integration application. @@ -20,8 +21,8 @@ def setUp(self): self.factory = RequestFactory() - self.user = User.objects.create_user('test_user', 'test@example.com', - 'password') + self.user = User.objects.create_user(u'Sérgio', u'test@example.com', + u'password') self.conn = get_redis_connection() self.mw = WikiMiddleware() @@ -52,7 +53,7 @@ cookie_val = cookie.value try: - user, email, key = cookie_val.split('#') + user, email, key = cookie_val.decode('utf-8').split('#') except ValueError: self.fail('invalid cookie value') else: