Skip to content

Commit

Permalink
Add support for disabling checksum validation
Browse files Browse the repository at this point in the history
  • Loading branch information
alextwoods committed Aug 9, 2023
1 parent 1b79077 commit c504e96
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions gems/aws-sdk-s3/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Issue - Add support for disabling checksum validation in `Object#download_file` (#2893).

1.132.0 (2023-07-24)
------------------

Expand Down
5 changes: 3 additions & 2 deletions gems/aws-sdk-s3/lib/aws-sdk-s3/customizations/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,9 @@ def upload_file(source, options = {})
# the object has a stored checksum, it will be used to validate the
# download and will raise an `Aws::Errors::ChecksumError` if
# checksum validation fails. You may provide a `on_checksum_validated`
# callback if you need to verify that validation occured and which
# algorithm was used.
# callback if you need to verify that validation occurred and which
# algorithm was used. To disable checksum validation, set
# `checksum_mode` to either `false` or `nil`.
#
# @option options [Callable] on_checksum_validated Called each time a
# request's checksum is validated with the checksum algorithm and the
Expand Down
8 changes: 7 additions & 1 deletion gems/aws-sdk-s3/lib/aws-sdk-s3/file_downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ def download(destination, options = {})
key: options[:key],
}
@params[:version_id] = options[:version_id] if options[:version_id]
@params[:checksum_mode] = options[:checksum_mode] || 'ENABLED'

# checksum_mode only supports the value "ENABLED"
# falsey values (false/nil) should be considered disabled and
# the api parameter should be unset.
if options.fetch(:checksum_mode, 'ENABLED')
@params[:checksum_mode] = options.fetch(:checksum_mode, 'ENABLED')
end
@on_checksum_validated = options[:on_checksum_validated]

validate!
Expand Down
22 changes: 22 additions & 0 deletions gems/aws-sdk-s3/spec/object/download_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,28 @@ module S3
expect(callback_data[:called]).to eq(4)
end

it 'supports disabling checksum_mode' do
expect(client).to receive(:head_object).with({
bucket: 'bucket',
key: 'small',
part_number: 1
}).and_return(
client.stub_data(
:head_object,
content_length: one_meg,
parts_count: nil
)
)

expect(client).to receive(:get_object).with({
bucket: 'bucket',
key: 'small',
response_target: path
}).exactly(1).times

small_obj.download_file(path, checksum_mode: nil)
end

it 'raises an error if an invalid mode is specified' do
expect { large_obj.download_file(path, mode: 'invalid_mode') }
.to raise_error(
Expand Down

0 comments on commit c504e96

Please sign in to comment.