From 88f41a570e8c4c53374cdbd5e5de40286b35a6af Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 13 Oct 2018 03:38:50 -0400 Subject: [PATCH] Make sure all key used as input for the cache key hash are bytes and not unicode. GitLab issue #520. Thanks to TheOneValen @TheOneValen for the report. Signed-off-by: Roberto Rosario --- HISTORY.rst | 3 + docs/releases/3.1.7.rst | 85 +++++++++++++++++++++++ docs/releases/index.rst | 1 + mayan/apps/mirroring/caches.py | 3 +- mayan/apps/mirroring/tests/literals.py | 3 + mayan/apps/mirroring/tests/test_caches.py | 9 ++- 6 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 docs/releases/3.1.7.rst diff --git a/HISTORY.rst b/HISTORY.rst index d15056dffa..f90822d6cb 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,9 @@ images. Ref: http://api.jquery.com/load-event/ * Remove duplicate YAML loading of environment variables. * Don't load development apps if they are already loaded. +* Make sure all key used as input for the cache key hash are + bytes and not unicode. GitLab issue #520. Thanks to TheOneValen + @TheOneValen for the report. 3.1.6 (2018-10-09) ================== diff --git a/docs/releases/3.1.7.rst b/docs/releases/3.1.7.rst new file mode 100644 index 0000000000..7c6db16575 --- /dev/null +++ b/docs/releases/3.1.7.rst @@ -0,0 +1,85 @@ +=============================== +Mayan EDMS v3.1.7 release notes +=============================== + +Released: October XX, 2018 + +Changes +~~~~~~~ +* Fix an issue with some browsers not firing the .load event on cached + images. Ref: http://api.jquery.com/load-event/ +* Remove duplicate YAML loading of environment variables. +* Don't load development apps if they are already loaded. +* Make sure all key used as input for the cache key hash are + bytes and not unicode. GitLab issue #520. Thanks to TheOneValen + @TheOneValen for the report. + + +Removals +-------- + +* None + +Upgrading from a previous version +--------------------------------- + + +If installed via Python's PIP +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Remove deprecated requirements:: + + $ curl https://gitlab.com/mayan-edms/mayan-edms/raw/master/removals.txt | pip uninstall -r /dev/stdin + +Type in the console:: + + $ pip install mayan-edms==3.1.5 + +the requirements will also be updated automatically. + + +Using Git +~~~~~~~~~ + +If you installed Mayan EDMS by cloning the Git repository issue the commands:: + + $ git reset --hard HEAD + $ git pull + +otherwise download the compressed archived and uncompress it overriding the +existing installation. + +Remove deprecated requirements:: + + $ pip uninstall -y -r removals.txt + +Next upgrade/add the new requirements:: + + $ pip install --upgrade -r requirements.txt + + +Common steps +~~~~~~~~~~~~ +Perform these steps after updating the code from either step above. + +Migrate existing database schema with:: + + $ mayan-edms.py performupgrade + +Add new static media:: + + $ mayan-edms.py collectstatic --noinput + +The upgrade procedure is now complete. + + +Backward incompatible changes +----------------------------- + +* None + +Bugs fixed or issues closed +=========================== + +* None +.. _PyPI: https://pypi.python.org/pypi/mayan-edms/ diff --git a/docs/releases/index.rst b/docs/releases/index.rst index a7c372b50a..f9fbfb698a 100644 --- a/docs/releases/index.rst +++ b/docs/releases/index.rst @@ -22,6 +22,7 @@ versions of the documentation contain the release notes for any later releases. .. toctree:: :maxdepth: 1 + 3.1.7 3.1.6 3.1.5 3.1.4 diff --git a/mayan/apps/mirroring/caches.py b/mayan/apps/mirroring/caches.py index affeaa003e..3116fec696 100644 --- a/mayan/apps/mirroring/caches.py +++ b/mayan/apps/mirroring/caches.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import hashlib from django.core.cache import caches +from django.utils.encoding import force_bytes from .settings import ( setting_document_lookup_cache_timeout, setting_node_lookup_cache_timeout @@ -12,7 +13,7 @@ from .settings import ( class IndexFilesystemCache(object): @staticmethod def get_key_hash(key): - return hashlib.sha256(key).hexdigest() + return hashlib.sha256(force_bytes(key)).hexdigest() @staticmethod def get_document_key(document): diff --git a/mayan/apps/mirroring/tests/literals.py b/mayan/apps/mirroring/tests/literals.py index 08724ec148..b6ebabfe75 100644 --- a/mayan/apps/mirroring/tests/literals.py +++ b/mayan/apps/mirroring/tests/literals.py @@ -1,7 +1,10 @@ +# -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals TEST_CACHE_KEY_BAD_CHARACTERS = ' \r\n!@#$%^&*()+_{}|:"<>?-=[];\',./' TEST_DOCUMENT_PK = 99 +TEST_KEY_UNICODE = 'áéíóúüäåéë¹²³¤' +TEST_KEY_UNICODE_HASH = 'ba418878794230c3f4308e66c70db31dd83f1def4d9381f379c50f42eb88989c' TEST_NODE_EXPRESSION = 'level_1' TEST_NODE_EXPRESSION_MULTILINE = 'first\r\nsecond\r\nthird' TEST_NODE_EXPRESSION_MULTILINE_EXPECTED = 'first second third' diff --git a/mayan/apps/mirroring/tests/test_caches.py b/mayan/apps/mirroring/tests/test_caches.py index 0e15b3df9b..7d36d04fb4 100644 --- a/mayan/apps/mirroring/tests/test_caches.py +++ b/mayan/apps/mirroring/tests/test_caches.py @@ -7,7 +7,8 @@ from common.tests import BaseTestCase from ..caches import IndexFilesystemCache from .literals import ( - TEST_CACHE_KEY_BAD_CHARACTERS, TEST_DOCUMENT_PK, TEST_NODE_PK, TEST_PATH + TEST_CACHE_KEY_BAD_CHARACTERS, TEST_DOCUMENT_PK, TEST_KEY_UNICODE, + TEST_KEY_UNICODE_HASH, TEST_NODE_PK, TEST_PATH, ) @@ -62,3 +63,9 @@ class IndexFilesystemCacheTestCase(BaseTestCase): self.cache.get_key_hash(key=TEST_CACHE_KEY_BAD_CHARACTERS) ) self.assertTrue(len(warning_list) == 0) + + def test_hash_non_ascii_key(self): + self.assertEqual( + self.cache.get_key_hash(key=TEST_KEY_UNICODE), + TEST_KEY_UNICODE_HASH + )