|
4 | 4 |
|
5 | 5 | module Aws |
6 | 6 | module S3 |
7 | | - module Plugins |
8 | | - describe ChecksumAlgorithm do |
9 | | - let(:creds) { Aws::Credentials.new('akid', 'secret') } |
10 | | - let(:client) { S3::Client.new(stub_responses: true) } |
11 | | - let(:bucket) { 'bucket' } |
12 | | - let(:key) { 'key' } |
| 7 | + describe Client do |
| 8 | + let(:creds) { Aws::Credentials.new('akid', 'secret') } |
| 9 | + let(:client) { S3::Client.new(stub_responses: true) } |
| 10 | + let(:bucket) { 'bucket' } |
| 11 | + let(:key) { 'key' } |
13 | 12 |
|
14 | | - let(:body) { 'hello world' } |
15 | | - let(:digest) { 'DUoRhQ==' } |
| 13 | + let(:body) { 'hello world' } |
| 14 | + let(:digest) { 'DUoRhQ==' } |
16 | 15 |
|
17 | | - let(:body_part_1) { 'hello '} |
18 | | - let(:digest_part_1) { '7YH59g==' } |
| 16 | + let(:body_part_1) { 'hello '} |
| 17 | + let(:digest_part_1) { '7YH59g==' } |
19 | 18 |
|
20 | | - it 'validates the checksum on an Object GET' do |
21 | | - client.stub_responses( |
22 | | - :get_object, |
23 | | - [{ |
24 | | - body: body, |
25 | | - headers: {'x-amz-checksum-crc32' => digest}, |
26 | | - status_code: 200 |
27 | | - }]) |
28 | | - resp = client.get_object(bucket: bucket, key: key, checksum_mode: 'ENABLED') |
29 | | - expect(resp.context[:http_checksum][:validated]).to eq 'CRC32' |
30 | | - end |
| 19 | + it 'validates the checksum on an Object GET' do |
| 20 | + client.stub_responses( |
| 21 | + :get_object, |
| 22 | + [{ |
| 23 | + body: body, |
| 24 | + headers: {'x-amz-checksum-crc32' => digest}, |
| 25 | + status_code: 200 |
| 26 | + }] |
| 27 | + ) |
| 28 | + resp = client.get_object(bucket: bucket, key: key) |
| 29 | + expect(resp.context[:http_checksum][:validated]).to eq 'CRC32' |
| 30 | + end |
31 | 31 |
|
32 | | - it 'raises when the checksum does not match on an Object GET' do |
33 | | - client.stub_responses( |
34 | | - :get_object, |
35 | | - [{ |
36 | | - body: body, |
37 | | - headers: {'x-amz-checksum-crc32' => 'invalid_value'}, |
38 | | - status_code: 200 |
39 | | - }]) |
40 | | - expect do |
41 | | - client.get_object(bucket: bucket, key: key, checksum_mode: 'ENABLED') |
42 | | - end.to raise_error(Aws::Errors::ChecksumError) |
43 | | - end |
| 32 | + it 'raises when the checksum does not match on an Object GET' do |
| 33 | + client.stub_responses( |
| 34 | + :get_object, |
| 35 | + [{ |
| 36 | + body: body, |
| 37 | + headers: {'x-amz-checksum-crc32' => 'invalid_value'}, |
| 38 | + status_code: 200 |
| 39 | + }] |
| 40 | + ) |
| 41 | + expect do |
| 42 | + client.get_object(bucket: bucket, key: key) |
| 43 | + end.to raise_error(Aws::Errors::ChecksumError) |
| 44 | + end |
44 | 45 |
|
45 | | - it 'validates the checksum on a range GET matching the part boundary' do |
46 | | - client.stub_responses( |
47 | | - :get_object, |
48 | | - [{ |
49 | | - body: body_part_1, |
50 | | - headers: {'x-amz-checksum-crc32' => digest_part_1}, |
51 | | - status_code: 200 |
52 | | - }]) |
53 | | - resp = client.get_object(bucket: bucket, key: key, checksum_mode: 'ENABLED', range: "bytes=0-6") |
54 | | - expect(resp.context[:http_checksum][:validated]).to eq 'CRC32' |
55 | | - end |
| 46 | + it 'validates the checksum on a range GET matching the part boundary' do |
| 47 | + client.stub_responses( |
| 48 | + :get_object, |
| 49 | + [{ |
| 50 | + body: body_part_1, |
| 51 | + headers: {'x-amz-checksum-crc32' => digest_part_1}, |
| 52 | + status_code: 200 |
| 53 | + }] |
| 54 | + ) |
| 55 | + resp = client.get_object(bucket: bucket, key: key, range: "bytes=0-6") |
| 56 | + expect(resp.context[:http_checksum][:validated]).to eq 'CRC32' |
| 57 | + end |
56 | 58 |
|
57 | | - it 'validates the checksum on a single part GET' do |
58 | | - client.stub_responses( |
59 | | - :get_object, |
60 | | - [{ |
61 | | - body: body_part_1, |
62 | | - headers: {'x-amz-checksum-crc32' => digest_part_1}, |
63 | | - status_code: 200 |
64 | | - }]) |
65 | | - resp = client.get_object(bucket: bucket, key: key, checksum_mode: 'ENABLED', part_number: 1) |
66 | | - expect(resp.context[:http_checksum][:validated]).to eq 'CRC32' |
| 59 | + it 'validates the checksum on a single part GET' do |
| 60 | + client.stub_responses( |
| 61 | + :get_object, |
| 62 | + [{ |
| 63 | + body: body_part_1, |
| 64 | + headers: {'x-amz-checksum-crc32' => digest_part_1}, |
| 65 | + status_code: 200 |
| 66 | + }] |
| 67 | + ) |
| 68 | + resp = client.get_object(bucket: bucket, key: key, part_number: 1) |
| 69 | + expect(resp.context[:http_checksum][:validated]).to eq 'CRC32' |
| 70 | + end |
| 71 | + |
| 72 | + it 'validates before any mutation of response target' do |
| 73 | + client.stub_responses( |
| 74 | + :get_object, |
| 75 | + [{ |
| 76 | + body: body, |
| 77 | + headers: {'x-amz-checksum-crc32' => digest}, |
| 78 | + status_code: 200 |
| 79 | + }] |
| 80 | + ) |
| 81 | + resp = client.get_object(bucket: bucket, key: key) do |chunk| |
| 82 | + chunk.upcase! |
67 | 83 | end |
| 84 | + expect(resp.context[:http_checksum][:validated]).to eq 'CRC32' |
| 85 | + end |
68 | 86 |
|
69 | | - context 'checksum response composite validation' do |
70 | | - file = File.expand_path('checksum_response_composite.json', __dir__) |
71 | | - test_cases = JSON.load_file(file) |
| 87 | + context 'checksum response composite validation' do |
| 88 | + file = File.expand_path('checksum_response_composite.json', __dir__) |
| 89 | + test_cases = JSON.load_file(file) |
72 | 90 |
|
73 | | - test_cases.each do |test_case| |
74 | | - it "passes test: #{test_case['documentation']}" do |
75 | | - if (algorithm = test_case['checksumAlgorithm']) |
76 | | - algorithm.upcase! |
77 | | - unless Aws::Plugins::ChecksumAlgorithm::CLIENT_ALGORITHMS.include?(algorithm) |
78 | | - skip "Algorithm #{algorithm} not supported" |
79 | | - end |
| 91 | + test_cases.each do |test_case| |
| 92 | + it "passes test: #{test_case['documentation']}" do |
| 93 | + if (algorithm = test_case['checksumAlgorithm']) |
| 94 | + algorithm.upcase! |
| 95 | + unless Aws::Plugins::ChecksumAlgorithm::CLIENT_ALGORITHMS.include?(algorithm) |
| 96 | + skip "Algorithm #{algorithm} not supported" |
80 | 97 | end |
81 | | - |
82 | | - client.stub_responses( |
83 | | - :get_object, |
84 | | - [{ |
85 | | - body: test_case['responsePayload'], |
86 | | - headers: test_case['responseHeaders'], |
87 | | - status_code: 200 |
88 | | - }] |
89 | | - ) |
90 | | - resp = client.get_object(bucket: bucket, key: key, checksum_mode: 'ENABLED') |
91 | | - expect(resp.context[:http_checksum][:validated]).to be_nil |
92 | 98 | end |
| 99 | + |
| 100 | + client.stub_responses( |
| 101 | + :get_object, |
| 102 | + [{ |
| 103 | + body: test_case['responsePayload'], |
| 104 | + headers: test_case['responseHeaders'], |
| 105 | + status_code: 200 |
| 106 | + }] |
| 107 | + ) |
| 108 | + resp = client.get_object(bucket: bucket, key: key, checksum_mode: 'ENABLED') |
| 109 | + expect(resp.context[:http_checksum][:validated]).to be_nil |
93 | 110 | end |
94 | 111 | end |
95 | 112 | end |
|
0 commit comments