-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a6a0b4
commit 9da4853
Showing
2 changed files
with
109 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
gems/aws-sdk-s3/spec/plugins/skip_whole_multipart_checksums_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../spec_helper' | ||
|
||
module Aws | ||
module S3 | ||
module Plugins | ||
describe SkipWholeMultipartGetChecksums do | ||
let(:creds) { Aws::Credentials.new('akid', 'secret') } | ||
let(:client) { S3::Client.new(stub_responses: true) } | ||
let(:bucket) { 'bucket' } | ||
let(:key) { 'key' } | ||
|
||
let(:body) { 'hello world' } | ||
let(:digest) { 'DUoRhQ==' } | ||
|
||
let(:body_part_1) { 'hello '} | ||
let(:digest_part_1) { '7YH59g==' } | ||
|
||
it 'validates the checksum on an Object GET' do | ||
client.stub_responses( | ||
:get_object, | ||
[{ | ||
body: body, | ||
headers: {'x-amz-checksum-crc32' => digest}, | ||
status_code: 200 | ||
}]) | ||
resp = client.get_object(bucket: bucket, key: key, checksum_mode: 'ENABLED') | ||
expect(resp.context[:http_checksum][:validated]).to eq 'CRC32' | ||
end | ||
|
||
it 'raises when the checksum does not match on an Object GET' do | ||
client.stub_responses( | ||
:get_object, | ||
[{ | ||
body: body, | ||
headers: {'x-amz-checksum-crc32' => 'invalid_value'}, | ||
status_code: 200 | ||
}]) | ||
expect do | ||
client.get_object(bucket: bucket, key: key, checksum_mode: 'ENABLED') | ||
end.to raise_error(Aws::Errors::ChecksumError) | ||
end | ||
|
||
it 'validates the checksum on a range GET matching the part boundary' do | ||
client.stub_responses( | ||
:get_object, | ||
[{ | ||
body: body_part_1, | ||
headers: {'x-amz-checksum-crc32' => digest_part_1}, | ||
status_code: 200 | ||
}]) | ||
resp = client.get_object(bucket: bucket, key: key, checksum_mode: 'ENABLED', range: "bytes=0-6") | ||
expect(resp.context[:http_checksum][:validated]).to eq 'CRC32' | ||
end | ||
|
||
it 'validates the checksum on a single part GET' do | ||
client.stub_responses( | ||
:get_object, | ||
[{ | ||
body: body_part_1, | ||
headers: {'x-amz-checksum-crc32' => digest_part_1}, | ||
status_code: 200 | ||
}]) | ||
resp = client.get_object(bucket: bucket, key: key, checksum_mode: 'ENABLED', part_number: 1) | ||
expect(resp.context[:http_checksum][:validated]).to eq 'CRC32' | ||
end | ||
|
||
it 'does not validate on a whole multipart GET' do | ||
client.stub_responses( | ||
:get_object, | ||
[{ | ||
body: body, | ||
headers: {'x-amz-checksum-crc32' => 'cpjwid==-12'}, | ||
status_code: 200 | ||
}]) | ||
resp = client.get_object(bucket: bucket, key: key, checksum_mode: 'ENABLED') | ||
expect(resp.context[:http_checksum][:validated]).to be_nil | ||
end | ||
end | ||
end | ||
end | ||
end |