base64-decode GCS checksums (#5891)

This commit is contained in:
Kartik Kumar 2023-04-11 21:55:42 +05:30 committed by GitHub
parent 283e1eb302
commit d47c732ae9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -3,6 +3,7 @@ Files Pipeline
See documentation in topics/media-pipeline.rst
"""
import base64
import functools
import hashlib
import logging
@ -228,7 +229,7 @@ class GCSFilesStore:
def stat_file(self, path, info):
def _onsuccess(blob):
if blob:
checksum = blob.md5_hash
checksum = base64.b64decode(blob.md5_hash).hex()
last_modified = time.mktime(blob.updated.timetuple())
return {"checksum": checksum, "last_modified": last_modified}
return {}

View File

@ -601,7 +601,7 @@ class TestGCSFilesStore(unittest.TestCase):
s = yield store.stat_file(path, info=None)
self.assertIn("last_modified", s)
self.assertIn("checksum", s)
self.assertEqual(s["checksum"], "zc2oVgXkbQr2EQdSdw3OPA==")
self.assertEqual(s["checksum"], "cdcda85605e46d0af6110752770dce3c")
u = urlparse(uri)
content, acl, blob = get_gcs_content_and_delete(u.hostname, u.path[1:] + path)
self.assertEqual(content, data)