Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update hashing algorithm in StaticFileHandler #2778

Merged
merged 2 commits into from
Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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