Skip to content

Commit

Permalink
[master][1783][xs]: Avoid issue with foreign chars being passed into …
Browse files Browse the repository at this point in the history
…hash function as unicode.
  • Loading branch information
David Read committed Feb 7, 2012
1 parent d1886ae commit 8f059ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ckan/lib/hash.py
Expand Up @@ -12,7 +12,7 @@ def get_message_hash(value):
# avoid getting config value at module scope since config may
# not be read in yet
secret = config['beaker.session.secret']
return hmac.new(secret, value, hashlib.sha1).hexdigest()
return hmac.new(secret, value.encode('utf8'), hashlib.sha1).hexdigest()

def get_redirect():
'''Checks the return_to value against the hash, and if it
Expand Down
16 changes: 16 additions & 0 deletions ckan/tests/lib/test_hash.py
@@ -0,0 +1,16 @@
from nose.tools import assert_equals

from ckan.lib.hash import get_message_hash, get_redirect

class TestHash:
@classmethod
def setup_class(cls):
global secret
secret = '42' # so that these tests are repeatable

def test_get_message_hash(self):
assert_equals(get_message_hash(u'/tag/country-uk'), '6f58ff51b42e6b2d2e700abd1a14c9699e115c61')

def test_get_message_hash_unicode(self):
assert_equals(get_message_hash(u'/tag/biocombust\xedveis'), 'd748fa890eb6a964cd317e6ff62905fad645b43d')

0 comments on commit 8f059ed

Please sign in to comment.