Skip to content
Permalink
Browse files
fix: extract hashes correctly during download (#238)
Co-authored-by: Tres Seaver <tseaver@palladion.com>
  • Loading branch information
HemangChothani and tseaver committed Aug 14, 2020
1 parent acea15b commit 23cfb65c3a3b10759c67846e162e4ed77a3f5307
Showing with 15 additions and 3 deletions.
  1. +1 −1 google/cloud/storage/blob.py
  2. +12 −0 tests/system/test_system.py
  3. +2 −2 tests/unit/test_blob.py
@@ -804,7 +804,7 @@ def _extract_headers_from_download(self, response):

digests = {}
for encoded_digest in x_goog_hash.split(","):
match = re.match(r"(crc32c|md5)=([\w\d]+)==", encoded_digest)
match = re.match(r"(crc32c|md5)=([\w\d/]+={0,3})", encoded_digest)
if match:
method, digest = match.groups()
digests[method] = digest
@@ -910,6 +910,18 @@ def test_upload_blob_owner(self):
owner = same_blob.owner
self.assertIn(user_email, owner["entity"])

def test_blob_crc32_md5_hash(self):
blob = self.bucket.blob("MyBuffer")
file_contents = b"Hello World"
blob.upload_from_string(file_contents)
self.case_blobs_to_delete.append(blob)

download_blob = self.bucket.blob("MyBuffer")

self.assertEqual(download_blob.download_as_string(), file_contents)
self.assertEqual(download_blob.crc32c, blob.crc32c)
self.assertEqual(download_blob.md5_hash, blob.md5_hash)


class TestUnicode(unittest.TestCase):
@vpcsc_config.skip_if_inside_vpcsc
@@ -1476,8 +1476,8 @@ def test_download_as_string_w_response_headers(self):
self.assertEqual(blob.content_encoding, "gzip")
self.assertEqual(blob.cache_control, "max-age=1337;public")
self.assertEqual(blob.storage_class, "STANDARD")
self.assertEqual(blob.md5_hash, "CS9tHYTtyFntzj7B9nkkJQ")
self.assertEqual(blob.crc32c, "4gcgLQ")
self.assertEqual(blob.md5_hash, "CS9tHYTtyFntzj7B9nkkJQ==")
self.assertEqual(blob.crc32c, "4gcgLQ==")

def test_download_as_string_w_hash_response_header_none(self):
blob_name = "blob-name"

0 comments on commit 23cfb65

Please sign in to comment.