Skip to content

Commit

Permalink
web: Update hashing algorithm in StaticFileHandler (#2778)
Browse files Browse the repository at this point in the history
Addresses #2776.
  • Loading branch information
mivade authored and bdarnell committed Nov 23, 2019
1 parent 1418880 commit 2054f47
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions tornado/test/web_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,12 @@ def test_failed_write_error(self):


class StaticFileTest(WebTestCase):
# The expected MD5 hash of robots.txt, used in tests that call
# The expected SHA-512 hash of robots.txt, used in tests that call
# StaticFileHandler.get_version
robots_txt_hash = b"f71d20196d4caf35b6a670db8c70b03d"
robots_txt_hash = (
b"63a36e950e134b5217e33c763e88840c10a07d80e6057d92b9ac97508de7fb1f"
b"a6f0e9b7531e169657165ea764e8963399cb6d921ffe6078425aaafe54c04563"
)
static_dir = os.path.join(os.path.dirname(__file__), "static")

def get_handlers(self):
Expand Down
4 changes: 2 additions & 2 deletions tornado/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2822,12 +2822,12 @@ def get_content_version(cls, abspath: str) -> str:
"""Returns a version string for the resource at the given path.
This class method may be overridden by subclasses. The
default implementation is a hash of the file's contents.
default implementation is a SHA-512 hash of the file's contents.
.. versionadded:: 3.1
"""
data = cls.get_content(abspath)
hasher = hashlib.md5()
hasher = hashlib.sha512()
if isinstance(data, bytes):
hasher.update(data)
else:
Expand Down

0 comments on commit 2054f47

Please sign in to comment.