-
Notifications
You must be signed in to change notification settings - Fork 568
feat(storage): Making crc32c default for download #34002
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -320,7 +320,7 @@ def file.md5 | |
| end | ||
|
|
||
| describe "verified downloads" do | ||
| it "verifies m5d by default" do | ||
| it "verifies crc32c by default" do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How it was working before, it was using m5d instead of md5? Does this test validate the actual use case?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this part is just description of test case which would have been typed incorrectly |
||
| # Stub these values | ||
| def file.md5; "md5="; end | ||
| def file.crc32c; "crc32c="; end | ||
|
|
@@ -332,17 +332,17 @@ def file.crc32c; "crc32c="; end | |
|
|
||
| bucket.service.mocked_service = mock | ||
|
|
||
| mocked_md5 = Minitest::Mock.new | ||
| mocked_md5.expect :md5_mock, file.md5 | ||
| stubbed_md5 = lambda { |_| mocked_md5.md5_mock } | ||
| stubbed_crc32c = lambda { |_| fail "Should not be called!" } | ||
| stubbed_md5 = lambda { |_| fail "Should not be called!" } | ||
| mocked_crc32c = Minitest::Mock.new | ||
| mocked_crc32c.expect :crc32c_mock, file.crc32c | ||
| stubbed_crc32c = lambda { |_| mocked_crc32c.crc32c_mock } | ||
|
|
||
| Google::Cloud::Storage::File::Verifier.stub :md5_for, stubbed_md5 do | ||
| Google::Cloud::Storage::File::Verifier.stub :crc32c_for, stubbed_crc32c do | ||
| file.download tmpfile | ||
| end | ||
| end | ||
| mocked_md5.verify | ||
| mocked_crc32c.verify | ||
| mock.verify | ||
| end | ||
| end | ||
|
|
@@ -469,10 +469,10 @@ def file.crc32c; "crc32c="; end | |
|
|
||
| bucket.service.mocked_service = mock | ||
|
|
||
| mocked_md5 = Minitest::Mock.new | ||
| mocked_md5.expect :md5_mock, "NOPE=" | ||
| stubbed_md5 = lambda { |_| mocked_md5.md5_mock } | ||
| stubbed_crc32c = lambda { |_| fail "Should not be called!" } | ||
| stubbed_md5 = lambda { |_| fail "Should not be called!" } | ||
| mocked_crc32c = Minitest::Mock.new | ||
| mocked_crc32c.expect :crc32c_mock, "NOPE!" | ||
| stubbed_crc32c = lambda { |_| mocked_crc32c.crc32c_mock } | ||
|
|
||
| Google::Cloud::Storage::File::Verifier.stub :md5_for, stubbed_md5 do | ||
| Google::Cloud::Storage::File::Verifier.stub :crc32c_for, stubbed_crc32c do | ||
|
|
@@ -481,7 +481,7 @@ def file.crc32c; "crc32c="; end | |
| end | ||
| end | ||
| end | ||
| mocked_md5.verify | ||
| mocked_crc32c.verify | ||
| mock.verify | ||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,9 +114,9 @@ def stub.list_buckets *args | |
| bucket = anonymous_storage.bucket bucket_name | ||
| file = bucket.file file_name | ||
|
|
||
| # Stub the md5 to match. | ||
| def file.md5 | ||
| "1B2M2Y8AsgTpgAmY7PhCfg==" | ||
| # Stub the crc32c to match. | ||
| def file.crc32c | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add non empty file verification?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| "AAAAAA==" | ||
| end | ||
|
|
||
| downloaded = file.download tmpfile | ||
|
|
@@ -126,6 +126,39 @@ def file.md5 | |
| end | ||
| end | ||
|
|
||
| it "downloads a public file and verifies the actual crc32c" do | ||
| file_name = "public-file.txt" | ||
| Tempfile.open "google-cloud" do |tmpfile| | ||
| tmpfile.write "yay!" | ||
|
|
||
| mock = Minitest::Mock.new | ||
| mock.expect :get_bucket, find_bucket_gapi(bucket_name), [bucket_name], **get_bucket_args | ||
| mock.expect :get_object, find_file_gapi(bucket_name, file_name), [bucket_name, file_name], **get_object_args | ||
| mock.expect :get_object, [tmpfile, download_http_resp], | ||
| [bucket_name, file_name], download_dest: tmpfile, generation: 1234567890, user_project: nil, options: {} | ||
|
|
||
| anonymous_storage.service.mocked_service = mock | ||
|
|
||
| bucket = anonymous_storage.bucket bucket_name | ||
| file = bucket.file file_name | ||
|
|
||
| # Stub the crc32c to match. | ||
| def file.crc32c | ||
| "AAAAAA==" | ||
| end | ||
|
|
||
| downloaded = file.download tmpfile | ||
| _(downloaded).must_be_kind_of Tempfile | ||
| _(downloaded.size).must_be :>, 0 | ||
|
|
||
| local_data = downloaded.read | ||
| local_crc32c = Digest::CRC32c.base64digest local_data | ||
| _(local_crc32c).must_equal "AAAAAA==" | ||
|
|
||
| mock.verify | ||
| end | ||
| end | ||
|
|
||
| def find_bucket_gapi name = nil | ||
| Google::Apis::StorageV1::Bucket.from_json random_bucket_hash(name: name).to_json | ||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ensure the official documentation for checksumming is updated to reflect that :crc32c is now the default instead of :md5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done