diff --git a/ckan/lib/hash.py b/ckan/lib/hash.py index 8aae27ae3b8..7fa52331912 100644 --- a/ckan/lib/hash.py +++ b/ckan/lib/hash.py @@ -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 diff --git a/ckan/tests/lib/test_hash.py b/ckan/tests/lib/test_hash.py new file mode 100644 index 00000000000..45002bccfee --- /dev/null +++ b/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') +