aliyun-sdk 0.4.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +25 -0
- data/README.md +174 -172
- data/examples/aliyun/oss/bucket.rb +0 -0
- data/examples/aliyun/oss/callback.rb +0 -0
- data/examples/aliyun/oss/object.rb +0 -0
- data/examples/aliyun/oss/resumable_download.rb +0 -0
- data/examples/aliyun/oss/resumable_upload.rb +0 -0
- data/examples/aliyun/oss/streaming.rb +0 -0
- data/examples/aliyun/oss/using_sts.rb +0 -0
- data/examples/aliyun/sts/assume_role.rb +0 -0
- data/ext/crcx/crc64_ecma.c +270 -0
- data/ext/crcx/crcx.c +45 -0
- data/ext/crcx/crcx.h +8 -0
- data/ext/crcx/extconf.rb +3 -0
- data/lib/aliyun/common.rb +0 -0
- data/lib/aliyun/common/exception.rb +0 -0
- data/lib/aliyun/common/logging.rb +6 -1
- data/lib/aliyun/common/struct.rb +0 -0
- data/lib/aliyun/oss.rb +1 -0
- data/lib/aliyun/oss/bucket.rb +41 -33
- data/lib/aliyun/oss/client.rb +10 -2
- data/lib/aliyun/oss/config.rb +4 -1
- data/lib/aliyun/oss/download.rb +2 -2
- data/lib/aliyun/oss/exception.rb +6 -0
- data/lib/aliyun/oss/http.rb +32 -48
- data/lib/aliyun/oss/iterator.rb +0 -0
- data/lib/aliyun/oss/multipart.rb +1 -1
- data/lib/aliyun/oss/object.rb +0 -0
- data/lib/aliyun/oss/protocol.rb +68 -8
- data/lib/aliyun/oss/struct.rb +2 -2
- data/lib/aliyun/oss/upload.rb +0 -0
- data/lib/aliyun/oss/util.rb +25 -1
- data/lib/aliyun/sts.rb +0 -0
- data/lib/aliyun/sts/client.rb +1 -1
- data/lib/aliyun/sts/config.rb +0 -0
- data/lib/aliyun/sts/exception.rb +0 -0
- data/lib/aliyun/sts/protocol.rb +3 -3
- data/lib/aliyun/sts/struct.rb +0 -0
- data/lib/aliyun/sts/util.rb +0 -0
- data/lib/aliyun/version.rb +1 -1
- data/spec/aliyun/oss/bucket_spec.rb +194 -18
- data/spec/aliyun/oss/client/bucket_spec.rb +342 -30
- data/spec/aliyun/oss/client/client_spec.rb +26 -1
- data/spec/aliyun/oss/client/resumable_download_spec.rb +0 -0
- data/spec/aliyun/oss/client/resumable_upload_spec.rb +0 -0
- data/spec/aliyun/oss/http_spec.rb +26 -0
- data/spec/aliyun/oss/multipart_spec.rb +53 -8
- data/spec/aliyun/oss/object_spec.rb +256 -10
- data/spec/aliyun/oss/service_spec.rb +0 -0
- data/spec/aliyun/oss/util_spec.rb +101 -0
- data/spec/aliyun/sts/client_spec.rb +0 -0
- data/spec/aliyun/sts/util_spec.rb +0 -0
- data/tests/config.rb +2 -0
- data/tests/helper.rb +15 -0
- data/tests/test_content_encoding.rb +0 -0
- data/tests/test_content_type.rb +0 -0
- data/tests/test_crc_check.rb +184 -0
- data/tests/test_custom_headers.rb +14 -6
- data/tests/test_encoding.rb +0 -0
- data/tests/test_large_file.rb +0 -0
- data/tests/test_multipart.rb +0 -0
- data/tests/test_object_acl.rb +0 -0
- data/tests/test_object_key.rb +18 -0
- data/tests/test_object_url.rb +20 -0
- data/tests/test_resumable.rb +0 -0
- metadata +33 -12
@@ -127,6 +127,31 @@ module Aliyun
|
|
127
127
|
expect(WebMock).to have_requested(:get, "#{bucket}.#{ep1}/#{object}")
|
128
128
|
expect(WebMock).to have_requested(:put, "#{bucket}.#{ep2}/#{object}")
|
129
129
|
end
|
130
|
+
|
131
|
+
it "should fail with invalid bucket name" do
|
132
|
+
bucket = 'INVALID'
|
133
|
+
ep1 = 'oss-cn-hangzhou.aliyuncs.com'
|
134
|
+
client = Client.new(
|
135
|
+
:endpoint => ep1,
|
136
|
+
:access_key_id => 'xxx', :access_key_secret => 'yyy')
|
137
|
+
|
138
|
+
expect {
|
139
|
+
client.create_bucket(bucket)
|
140
|
+
}.to raise_error(ClientError, "The bucket name is invalid.")
|
141
|
+
|
142
|
+
expect {
|
143
|
+
client.delete_bucket(bucket)
|
144
|
+
}.to raise_error(ClientError, "The bucket name is invalid.")
|
145
|
+
|
146
|
+
expect {
|
147
|
+
client.bucket_exists?(bucket)
|
148
|
+
}.to raise_error(ClientError, "The bucket name is invalid.")
|
149
|
+
|
150
|
+
expect {
|
151
|
+
client.get_bucket(bucket)
|
152
|
+
}.to raise_error(ClientError, "The bucket name is invalid.")
|
153
|
+
end
|
154
|
+
|
130
155
|
end # construct
|
131
156
|
|
132
157
|
def mock_buckets(buckets, more = {})
|
@@ -247,7 +272,7 @@ module Aliyun
|
|
247
272
|
end
|
248
273
|
|
249
274
|
it "should test bucket existence" do
|
250
|
-
query = {'acl' =>
|
275
|
+
query = {'acl' => nil}
|
251
276
|
return_acl = ACL::PUBLIC_READ
|
252
277
|
stub_request(:get, bucket_url)
|
253
278
|
.with(:query => query)
|
File without changes
|
File without changes
|
@@ -76,6 +76,32 @@ module Aliyun
|
|
76
76
|
r = s.read(1000)
|
77
77
|
expect(r.size).to eq(64)
|
78
78
|
end
|
79
|
+
|
80
|
+
it "should read with a correct crc" do
|
81
|
+
content = "hello world"
|
82
|
+
content_crc = Aliyun::OSS::Util.crc(content)
|
83
|
+
s = HTTP::StreamWriter.new(true) do |sr|
|
84
|
+
sr << content
|
85
|
+
end
|
86
|
+
|
87
|
+
r = s.read(content.size + 1)
|
88
|
+
expect(r.size).to eq(content.size)
|
89
|
+
expect(s.data_crc).to eq(content_crc)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should read with a correct crc when setting init_crc" do
|
93
|
+
content = "hello world"
|
94
|
+
init_crc = 100
|
95
|
+
content_crc = Aliyun::OSS::Util.crc(content, init_crc)
|
96
|
+
|
97
|
+
s = HTTP::StreamWriter.new(true, init_crc) do |sr|
|
98
|
+
sr << content
|
99
|
+
end
|
100
|
+
|
101
|
+
r = s.read(content.size + 1)
|
102
|
+
expect(r.size).to eq(content.size)
|
103
|
+
expect(s.data_crc).to eq(content_crc)
|
104
|
+
end
|
79
105
|
end # StreamWriter
|
80
106
|
|
81
107
|
end # HTTP
|
@@ -23,6 +23,15 @@ module Aliyun
|
|
23
23
|
"#{@bucket}.#{@endpoint}/#{@object}"
|
24
24
|
end
|
25
25
|
|
26
|
+
def crc_protocol
|
27
|
+
Protocol.new(
|
28
|
+
Config.new(:endpoint => @endpoint,
|
29
|
+
:access_key_id => 'xxx',
|
30
|
+
:access_key_secret => 'yyy',
|
31
|
+
:upload_crc_enable => true,
|
32
|
+
:download_crc_enable => true))
|
33
|
+
end
|
34
|
+
|
26
35
|
def mock_txn_id(txn_id)
|
27
36
|
Nokogiri::XML::Builder.new do |xml|
|
28
37
|
xml.InitiateMultipartUploadResult {
|
@@ -102,7 +111,7 @@ module Aliyun
|
|
102
111
|
context "Initiate multipart upload" do
|
103
112
|
|
104
113
|
it "should POST to create transaction" do
|
105
|
-
query = {'uploads' =>
|
114
|
+
query = {'uploads' => nil}
|
106
115
|
stub_request(:post, request_path).with(:query => query)
|
107
116
|
|
108
117
|
@protocol.initiate_multipart_upload(
|
@@ -120,7 +129,7 @@ module Aliyun
|
|
120
129
|
end
|
121
130
|
|
122
131
|
it "should return transaction id" do
|
123
|
-
query = {'uploads' =>
|
132
|
+
query = {'uploads' => nil}
|
124
133
|
return_txn_id = 'zyx'
|
125
134
|
stub_request(:post, request_path).
|
126
135
|
with(:query => query).
|
@@ -134,7 +143,7 @@ module Aliyun
|
|
134
143
|
end
|
135
144
|
|
136
145
|
it "should raise Exception on error" do
|
137
|
-
query = {'uploads' =>
|
146
|
+
query = {'uploads' => nil}
|
138
147
|
|
139
148
|
code = 'InvalidArgument'
|
140
149
|
message = 'Invalid argument.'
|
@@ -207,6 +216,42 @@ module Aliyun
|
|
207
216
|
.with(:body => nil, :query => query)
|
208
217
|
end
|
209
218
|
|
219
|
+
it "should raise crc exception on error" do
|
220
|
+
txn_id = 'xxxyyyzzz'
|
221
|
+
part_no = 1
|
222
|
+
query = {'partNumber' => part_no, 'uploadId' => txn_id}
|
223
|
+
|
224
|
+
content = "hello world"
|
225
|
+
content_crc = Aliyun::OSS::Util.crc(content)
|
226
|
+
|
227
|
+
stub_request(:put, request_path).with(:query => query).to_return(
|
228
|
+
:status => 200, :headers => {:x_oss_hash_crc64ecma => content_crc + 1})
|
229
|
+
|
230
|
+
expect {
|
231
|
+
crc_protocol.upload_part(@bucket, @object, txn_id, part_no) do |body|
|
232
|
+
body << content
|
233
|
+
end
|
234
|
+
}.to raise_error(CrcInconsistentError, "The crc of put between client and oss is not inconsistent.")
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should not raise crc exception on error" do
|
238
|
+
txn_id = 'xxxyyyzzz'
|
239
|
+
part_no = 1
|
240
|
+
query = {'partNumber' => part_no, 'uploadId' => txn_id}
|
241
|
+
|
242
|
+
content = "hello world"
|
243
|
+
content_crc = Aliyun::OSS::Util.crc(content)
|
244
|
+
|
245
|
+
stub_request(:put, request_path).with(:query => query).to_return(
|
246
|
+
:status => 200, :headers => {:x_oss_hash_crc64ecma => content_crc})
|
247
|
+
|
248
|
+
expect {
|
249
|
+
crc_protocol.upload_part(@bucket, @object, txn_id, part_no) do |body|
|
250
|
+
body << content
|
251
|
+
end
|
252
|
+
}.not_to raise_error
|
253
|
+
end
|
254
|
+
|
210
255
|
end # upload part
|
211
256
|
|
212
257
|
context "Upload part by copy object" do
|
@@ -417,7 +462,7 @@ module Aliyun
|
|
417
462
|
|
418
463
|
it "should GET to list multiparts" do
|
419
464
|
request_path = "#{@bucket}.#{@endpoint}/"
|
420
|
-
query = {'uploads' =>
|
465
|
+
query = {'uploads' => nil}
|
421
466
|
|
422
467
|
stub_request(:get, request_path).with(:query => query)
|
423
468
|
|
@@ -430,7 +475,7 @@ module Aliyun
|
|
430
475
|
it "should send extra params when list multiparts" do
|
431
476
|
request_path = "#{@bucket}.#{@endpoint}/"
|
432
477
|
query = {
|
433
|
-
'uploads' =>
|
478
|
+
'uploads' => nil,
|
434
479
|
'prefix' => 'foo-',
|
435
480
|
'upload-id-marker' => 'id-marker',
|
436
481
|
'key-marker' => 'key-marker',
|
@@ -456,7 +501,7 @@ module Aliyun
|
|
456
501
|
it "should get multipart transactions" do
|
457
502
|
request_path = "#{@bucket}.#{@endpoint}/"
|
458
503
|
query = {
|
459
|
-
'uploads' =>
|
504
|
+
'uploads' => nil,
|
460
505
|
'prefix' => 'foo-',
|
461
506
|
'upload-id-marker' => 'id-marker',
|
462
507
|
'key-marker' => 'key-marker',
|
@@ -503,7 +548,7 @@ module Aliyun
|
|
503
548
|
it "should decode object key" do
|
504
549
|
request_path = "#{@bucket}.#{@endpoint}/"
|
505
550
|
query = {
|
506
|
-
'uploads' =>
|
551
|
+
'uploads' => nil,
|
507
552
|
'prefix' => 'foo-',
|
508
553
|
'upload-id-marker' => 'id-marker',
|
509
554
|
'key-marker' => 'key-marker',
|
@@ -569,7 +614,7 @@ module Aliyun
|
|
569
614
|
|
570
615
|
it "should raise Exception on error" do
|
571
616
|
request_path = "#{@bucket}.#{@endpoint}/"
|
572
|
-
query = {'uploads' =>
|
617
|
+
query = {'uploads' => nil}
|
573
618
|
|
574
619
|
code = 'InvalidArgument'
|
575
620
|
message = 'Invalid argument.'
|
@@ -17,6 +17,15 @@ module Aliyun
|
|
17
17
|
@bucket = 'rubysdk-bucket'
|
18
18
|
end
|
19
19
|
|
20
|
+
def crc_protocol
|
21
|
+
Protocol.new(
|
22
|
+
Config.new(:endpoint => @endpoint,
|
23
|
+
:access_key_id => 'xxx',
|
24
|
+
:access_key_secret => 'yyy',
|
25
|
+
:upload_crc_enable => true,
|
26
|
+
:download_crc_enable => true))
|
27
|
+
end
|
28
|
+
|
20
29
|
def get_request_path(object = nil)
|
21
30
|
p = "#{@bucket}.#{@endpoint}/"
|
22
31
|
p += CGI.escape(object) if object
|
@@ -190,6 +199,35 @@ module Aliyun
|
|
190
199
|
'x-oss-meta-people' => 'mary'})
|
191
200
|
end
|
192
201
|
|
202
|
+
it "should raise crc exception on error" do
|
203
|
+
object_name = 'ruby'
|
204
|
+
url = get_request_path(object_name)
|
205
|
+
content = "hello world"
|
206
|
+
content_crc = Aliyun::OSS::Util.crc(content)
|
207
|
+
stub_request(:put, url).to_return(
|
208
|
+
:status => 200, :headers => {:x_oss_hash_crc64ecma => content_crc.to_i + 1})
|
209
|
+
expect(crc_protocol.upload_crc_enable).to eq(true)
|
210
|
+
expect {
|
211
|
+
crc_protocol.put_object(@bucket, object_name) do |c|
|
212
|
+
c << content
|
213
|
+
end
|
214
|
+
}.to raise_error(CrcInconsistentError, "The crc of put between client and oss is not inconsistent.")
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should not raise crc exception on error" do
|
218
|
+
object_name = 'ruby'
|
219
|
+
url = get_request_path(object_name)
|
220
|
+
content = "hello world"
|
221
|
+
content_crc = Aliyun::OSS::Util.crc(content)
|
222
|
+
stub_request(:put, url).to_return(
|
223
|
+
:status => 200, :headers => {:x_oss_hash_crc64ecma => content_crc})
|
224
|
+
expect(crc_protocol.upload_crc_enable).to eq(true)
|
225
|
+
expect {
|
226
|
+
crc_protocol.put_object(@bucket, object_name) do |c|
|
227
|
+
c << content
|
228
|
+
end
|
229
|
+
}.not_to raise_error
|
230
|
+
end
|
193
231
|
end # put object
|
194
232
|
|
195
233
|
context "Append object" do
|
@@ -198,7 +236,7 @@ module Aliyun
|
|
198
236
|
object_name = 'ruby'
|
199
237
|
url = get_request_path(object_name)
|
200
238
|
|
201
|
-
query = {'append' =>
|
239
|
+
query = {'append' => nil, 'position' => 11}
|
202
240
|
return_headers = {'x-oss-next-append-position' => '101'}
|
203
241
|
stub_request(:post, url).with(:query => query)
|
204
242
|
.to_return(:headers => return_headers)
|
@@ -217,7 +255,7 @@ module Aliyun
|
|
217
255
|
object_name = 'ruby'
|
218
256
|
url = get_request_path(object_name)
|
219
257
|
|
220
|
-
query = {'append' =>
|
258
|
+
query = {'append' => nil, 'position' => 11}
|
221
259
|
code = 'ObjectNotAppendable'
|
222
260
|
message = 'Normal object cannot be appended.'
|
223
261
|
stub_request(:post, url).with(:query => query).
|
@@ -237,7 +275,7 @@ module Aliyun
|
|
237
275
|
it "should use default content-type" do
|
238
276
|
object_name = 'ruby'
|
239
277
|
url = get_request_path(object_name)
|
240
|
-
query = {'append' =>
|
278
|
+
query = {'append' => nil, 'position' => 0}
|
241
279
|
|
242
280
|
stub_request(:post, url).with(:query => query)
|
243
281
|
|
@@ -254,7 +292,7 @@ module Aliyun
|
|
254
292
|
it "should use customized content-type" do
|
255
293
|
object_name = 'ruby'
|
256
294
|
url = get_request_path(object_name)
|
257
|
-
query = {'append' =>
|
295
|
+
query = {'append' => nil, 'position' => 0}
|
258
296
|
|
259
297
|
stub_request(:post, url).with(:query => query)
|
260
298
|
|
@@ -273,7 +311,7 @@ module Aliyun
|
|
273
311
|
it "should set user defined metas" do
|
274
312
|
object_name = 'ruby'
|
275
313
|
url = get_request_path(object_name)
|
276
|
-
query = {'append' =>
|
314
|
+
query = {'append' => nil, 'position' => 0}
|
277
315
|
|
278
316
|
stub_request(:post, url).with(:query => query)
|
279
317
|
|
@@ -290,6 +328,72 @@ module Aliyun
|
|
290
328
|
'x-oss-meta-year' => '2015',
|
291
329
|
'x-oss-meta-people' => 'mary'})
|
292
330
|
end
|
331
|
+
|
332
|
+
it "should raise crc exception on error" do
|
333
|
+
object_name = 'ruby'
|
334
|
+
url = get_request_path(object_name)
|
335
|
+
content = "hello world"
|
336
|
+
content_crc = Aliyun::OSS::Util.crc(content)
|
337
|
+
|
338
|
+
query = {'append' => nil, 'position' => 11}
|
339
|
+
return_headers = {'x-oss-next-append-position' => '101', :x_oss_hash_crc64ecma => content_crc.to_i + 1}
|
340
|
+
stub_request(:post, url).with(:query => query)
|
341
|
+
.to_return(:headers => return_headers)
|
342
|
+
expect(crc_protocol.upload_crc_enable).to eq(true)
|
343
|
+
expect {
|
344
|
+
crc_protocol.append_object(@bucket, object_name, 11, :init_crc => 0) do |c|
|
345
|
+
c << content
|
346
|
+
end
|
347
|
+
}.to raise_error(CrcInconsistentError, "The crc of append between client and oss is not inconsistent.")
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should not raise crc exception with init_crc" do
|
351
|
+
object_name = 'ruby'
|
352
|
+
url = get_request_path(object_name)
|
353
|
+
content = "hello world"
|
354
|
+
content_crc = Aliyun::OSS::Util.crc(content)
|
355
|
+
|
356
|
+
query = {'append' => nil, 'position' => 11}
|
357
|
+
return_headers = {'x-oss-next-append-position' => '101', :x_oss_hash_crc64ecma => content_crc}
|
358
|
+
stub_request(:post, url).with(:query => query)
|
359
|
+
.to_return(:headers => return_headers)
|
360
|
+
|
361
|
+
expect(crc_protocol.upload_crc_enable).to eq(true)
|
362
|
+
next_pos = 0
|
363
|
+
expect {
|
364
|
+
next_pos = crc_protocol.append_object(@bucket, object_name, 11, :init_crc => 0) do |c|
|
365
|
+
c << content
|
366
|
+
end
|
367
|
+
}.not_to raise_error
|
368
|
+
|
369
|
+
expect(WebMock).to have_requested(:post, url)
|
370
|
+
.with(:body => content, :query => query)
|
371
|
+
expect(next_pos).to eq(101)
|
372
|
+
end
|
373
|
+
|
374
|
+
it "should not raise crc exception without init_crc" do
|
375
|
+
object_name = 'ruby'
|
376
|
+
url = get_request_path(object_name)
|
377
|
+
content = "hello world"
|
378
|
+
content_crc = Aliyun::OSS::Util.crc(content)
|
379
|
+
|
380
|
+
query = {'append' => nil, 'position' => 11}
|
381
|
+
return_headers = {'x-oss-next-append-position' => '101', :x_oss_hash_crc64ecma => content_crc + 1}
|
382
|
+
stub_request(:post, url).with(:query => query)
|
383
|
+
.to_return(:headers => return_headers)
|
384
|
+
|
385
|
+
expect(crc_protocol.upload_crc_enable).to eq(true)
|
386
|
+
next_pos = 0
|
387
|
+
expect {
|
388
|
+
next_pos = crc_protocol.append_object(@bucket, object_name, 11) do |c|
|
389
|
+
c << content
|
390
|
+
end
|
391
|
+
}.not_to raise_error
|
392
|
+
|
393
|
+
expect(WebMock).to have_requested(:post, url)
|
394
|
+
.with(:body => content, :query => query)
|
395
|
+
expect(next_pos).to eq(101)
|
396
|
+
end
|
293
397
|
end # append object
|
294
398
|
|
295
399
|
context "Copy object" do
|
@@ -507,6 +611,15 @@ module Aliyun
|
|
507
611
|
})
|
508
612
|
end
|
509
613
|
|
614
|
+
it "should raise Exception on error when setting invalid range" do
|
615
|
+
object_name = 'ruby'
|
616
|
+
url = get_request_path(object_name)
|
617
|
+
stub_request(:get, url)
|
618
|
+
expect {
|
619
|
+
@protocol.get_object(@bucket, object_name, {:range => [0, 10, 5]}) {}
|
620
|
+
}.to raise_error(ClientError)
|
621
|
+
end
|
622
|
+
|
510
623
|
it "should match modify time and etag" do
|
511
624
|
object_name = 'ruby'
|
512
625
|
url = get_request_path(object_name)
|
@@ -557,6 +670,88 @@ module Aliyun
|
|
557
670
|
expect(WebMock).to have_requested(:get, url)
|
558
671
|
.with(:body => nil, :query => query)
|
559
672
|
end
|
673
|
+
|
674
|
+
it "should get object with headers" do
|
675
|
+
object_name = 'ruby'
|
676
|
+
url = get_request_path(object_name)
|
677
|
+
headers = {
|
678
|
+
'Range' => 'bytes=0-9'
|
679
|
+
}
|
680
|
+
stub_request(:get, url)
|
681
|
+
|
682
|
+
@protocol.get_object(@bucket, object_name, {:headers => headers}) {}
|
683
|
+
|
684
|
+
expect(WebMock).to have_requested(:get, url)
|
685
|
+
.with(:body => nil, :query => {},
|
686
|
+
:headers => {
|
687
|
+
'Range' => 'bytes=0-9'
|
688
|
+
})
|
689
|
+
end
|
690
|
+
|
691
|
+
it "should raise crc exception on error" do
|
692
|
+
object_name = 'ruby'
|
693
|
+
url = get_request_path(object_name)
|
694
|
+
content = "hello world"
|
695
|
+
content_crc = Aliyun::OSS::Util.crc(content)
|
696
|
+
stub_request(:get, url).to_return(
|
697
|
+
:status => 200, :body => content, :headers => {:x_oss_hash_crc64ecma => content_crc.to_i + 1})
|
698
|
+
response_content = ""
|
699
|
+
expect(crc_protocol.download_crc_enable).to eq(true)
|
700
|
+
expect {
|
701
|
+
crc_protocol.get_object(@bucket, object_name) {|c| response_content << c}
|
702
|
+
}.to raise_error(CrcInconsistentError, "The crc of get between client and oss is not inconsistent.")
|
703
|
+
end
|
704
|
+
|
705
|
+
it "should not raise crc exception on error" do
|
706
|
+
object_name = 'ruby'
|
707
|
+
url = get_request_path(object_name)
|
708
|
+
content = "hello world"
|
709
|
+
content_crc = Aliyun::OSS::Util.crc(content)
|
710
|
+
stub_request(:get, url).to_return(
|
711
|
+
:status => 200, :body => content, :headers => {:x_oss_hash_crc64ecma => content_crc})
|
712
|
+
response_content = ""
|
713
|
+
expect(crc_protocol.download_crc_enable).to eq(true)
|
714
|
+
expect {
|
715
|
+
crc_protocol.get_object(@bucket, object_name) {|c| response_content << c}
|
716
|
+
}.not_to raise_error
|
717
|
+
expect(response_content).to eq(content)
|
718
|
+
end
|
719
|
+
|
720
|
+
it "should not raise crc exception on error when setting range" do
|
721
|
+
object_name = 'ruby'
|
722
|
+
url = get_request_path(object_name)
|
723
|
+
content = "hello world 0123456789"
|
724
|
+
content_crc = Aliyun::OSS::Util.crc(content)
|
725
|
+
stub_request(:get, url).to_return(
|
726
|
+
:status => 200, :body => content, :headers => {:x_oss_hash_crc64ecma => content_crc.to_i + 1})
|
727
|
+
response_content = ""
|
728
|
+
expect(crc_protocol.download_crc_enable).to eq(true)
|
729
|
+
expect {
|
730
|
+
crc_protocol.get_object(@bucket, object_name, {range: [0, 10]}) {|c| response_content << c}
|
731
|
+
}.not_to raise_error
|
732
|
+
expect(WebMock).to have_requested(:get, url)
|
733
|
+
.with(:body => nil, :query => {},
|
734
|
+
:headers => {
|
735
|
+
'Range' => 'bytes=0-9'
|
736
|
+
})
|
737
|
+
end
|
738
|
+
|
739
|
+
it "should get to get object with special chars" do
|
740
|
+
object_name = 'ruby///adfadfa//!@#%^*//?key=value&aabc#abc=ad'
|
741
|
+
url = get_request_path(object_name)
|
742
|
+
|
743
|
+
return_content = "hello world"
|
744
|
+
stub_request(:get, url).to_return(:body => return_content)
|
745
|
+
|
746
|
+
content = ""
|
747
|
+
@protocol.get_object(@bucket, object_name) {|c| content << c}
|
748
|
+
|
749
|
+
expect(WebMock).to have_requested(:get, url)
|
750
|
+
.with(:body => nil, :query => {})
|
751
|
+
|
752
|
+
expect(content).to eq(return_content)
|
753
|
+
end
|
754
|
+
|
560
755
|
end # Get object
|
561
756
|
|
562
757
|
context "Get object meta" do
|
@@ -651,7 +846,7 @@ module Aliyun
|
|
651
846
|
|
652
847
|
it "should batch delete objects" do
|
653
848
|
url = get_request_path
|
654
|
-
query = {'delete' =>
|
849
|
+
query = {'delete' => nil}
|
655
850
|
|
656
851
|
object_names = (1..5).map do |i|
|
657
852
|
"object-#{i}"
|
@@ -661,7 +856,7 @@ module Aliyun
|
|
661
856
|
.with(:query => query)
|
662
857
|
.to_return(:body => mock_delete_result(object_names))
|
663
858
|
|
664
|
-
opts = {:quiet => false
|
859
|
+
opts = {:quiet => false}
|
665
860
|
deleted = @protocol.batch_delete_objects(@bucket, object_names, opts)
|
666
861
|
|
667
862
|
expect(WebMock).to have_requested(:post, url)
|
@@ -671,7 +866,7 @@ module Aliyun
|
|
671
866
|
|
672
867
|
it "should decode object key in batch delete response" do
|
673
868
|
url = get_request_path
|
674
|
-
query = {'delete' =>
|
869
|
+
query = {'delete' => nil, 'encoding-type' => KeyEncoding::URL}
|
675
870
|
|
676
871
|
object_names = (1..5).map do |i|
|
677
872
|
"对象-#{i}"
|
@@ -691,6 +886,57 @@ module Aliyun
|
|
691
886
|
.with(:query => query, :body => mock_delete(object_names, opts))
|
692
887
|
expect(deleted).to match_array(object_names)
|
693
888
|
end
|
889
|
+
|
890
|
+
it "should batch delete objects in quiet mode" do
|
891
|
+
url = get_request_path
|
892
|
+
query = {'delete' => nil}
|
893
|
+
|
894
|
+
object_names = (1..5).map do |i|
|
895
|
+
"object-#{i}"
|
896
|
+
end
|
897
|
+
|
898
|
+
stub_request(:post, url)
|
899
|
+
.with(:query => query)
|
900
|
+
.to_return(:body => "")
|
901
|
+
|
902
|
+
opts = {:quiet => true}
|
903
|
+
deleted = @protocol.batch_delete_objects(@bucket, object_names, opts)
|
904
|
+
|
905
|
+
expect(WebMock).to have_requested(:post, url)
|
906
|
+
.with(:query => query, :body => mock_delete(object_names, opts))
|
907
|
+
expect(deleted).to match_array([])
|
908
|
+
end
|
909
|
+
|
910
|
+
it "should rasie Exception wiht invalid responsed body" do
|
911
|
+
url = get_request_path
|
912
|
+
query = {'delete' => nil}
|
913
|
+
body = '<DeleteResult>
|
914
|
+
<EncodingType>invaid<EncodingType>
|
915
|
+
<Deleted>
|
916
|
+
<Key>multipart.data</Key>
|
917
|
+
</Deleted>
|
918
|
+
<Deleted>
|
919
|
+
<Key>test.jpg</Key>
|
920
|
+
</Deleted>
|
921
|
+
<Deleted>
|
922
|
+
<Key>demo.jpg</Key>
|
923
|
+
</Deleted>
|
924
|
+
</DeleteResult>'
|
925
|
+
|
926
|
+
object_names = (1..5).map do |i|
|
927
|
+
"object-#{i}"
|
928
|
+
end
|
929
|
+
|
930
|
+
stub_request(:post, url)
|
931
|
+
.with(:query => query)
|
932
|
+
.to_return(:body => body)
|
933
|
+
|
934
|
+
opts = {:quiet => false}
|
935
|
+
expect {
|
936
|
+
deleted = @protocol.batch_delete_objects(@bucket, object_names, opts)
|
937
|
+
}.to raise_error(ClientError)
|
938
|
+
|
939
|
+
end
|
694
940
|
end # delete object
|
695
941
|
|
696
942
|
context "acl" do
|
@@ -698,7 +944,7 @@ module Aliyun
|
|
698
944
|
object_name = 'ruby'
|
699
945
|
url = get_request_path(object_name)
|
700
946
|
|
701
|
-
query = {'acl' =>
|
947
|
+
query = {'acl' => nil}
|
702
948
|
stub_request(:put, url).with(:query => query)
|
703
949
|
|
704
950
|
@protocol.put_object_acl(@bucket, object_name, ACL::PUBLIC_READ)
|
@@ -713,7 +959,7 @@ module Aliyun
|
|
713
959
|
object_name = 'ruby'
|
714
960
|
url = get_request_path(object_name)
|
715
961
|
|
716
|
-
query = {'acl' =>
|
962
|
+
query = {'acl' => nil}
|
717
963
|
return_acl = ACL::PUBLIC_READ
|
718
964
|
|
719
965
|
stub_request(:get, url)
|