aliyun-sdk 0.4.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +174 -172
  4. data/examples/aliyun/oss/bucket.rb +0 -0
  5. data/examples/aliyun/oss/callback.rb +0 -0
  6. data/examples/aliyun/oss/object.rb +0 -0
  7. data/examples/aliyun/oss/resumable_download.rb +0 -0
  8. data/examples/aliyun/oss/resumable_upload.rb +0 -0
  9. data/examples/aliyun/oss/streaming.rb +0 -0
  10. data/examples/aliyun/oss/using_sts.rb +0 -0
  11. data/examples/aliyun/sts/assume_role.rb +0 -0
  12. data/ext/crcx/crc64_ecma.c +270 -0
  13. data/ext/crcx/crcx.c +45 -0
  14. data/ext/crcx/crcx.h +8 -0
  15. data/ext/crcx/extconf.rb +3 -0
  16. data/lib/aliyun/common.rb +0 -0
  17. data/lib/aliyun/common/exception.rb +0 -0
  18. data/lib/aliyun/common/logging.rb +6 -1
  19. data/lib/aliyun/common/struct.rb +0 -0
  20. data/lib/aliyun/oss.rb +1 -0
  21. data/lib/aliyun/oss/bucket.rb +41 -33
  22. data/lib/aliyun/oss/client.rb +10 -2
  23. data/lib/aliyun/oss/config.rb +4 -1
  24. data/lib/aliyun/oss/download.rb +2 -2
  25. data/lib/aliyun/oss/exception.rb +6 -0
  26. data/lib/aliyun/oss/http.rb +32 -48
  27. data/lib/aliyun/oss/iterator.rb +0 -0
  28. data/lib/aliyun/oss/multipart.rb +1 -1
  29. data/lib/aliyun/oss/object.rb +0 -0
  30. data/lib/aliyun/oss/protocol.rb +68 -8
  31. data/lib/aliyun/oss/struct.rb +2 -2
  32. data/lib/aliyun/oss/upload.rb +0 -0
  33. data/lib/aliyun/oss/util.rb +25 -1
  34. data/lib/aliyun/sts.rb +0 -0
  35. data/lib/aliyun/sts/client.rb +1 -1
  36. data/lib/aliyun/sts/config.rb +0 -0
  37. data/lib/aliyun/sts/exception.rb +0 -0
  38. data/lib/aliyun/sts/protocol.rb +3 -3
  39. data/lib/aliyun/sts/struct.rb +0 -0
  40. data/lib/aliyun/sts/util.rb +0 -0
  41. data/lib/aliyun/version.rb +1 -1
  42. data/spec/aliyun/oss/bucket_spec.rb +194 -18
  43. data/spec/aliyun/oss/client/bucket_spec.rb +342 -30
  44. data/spec/aliyun/oss/client/client_spec.rb +26 -1
  45. data/spec/aliyun/oss/client/resumable_download_spec.rb +0 -0
  46. data/spec/aliyun/oss/client/resumable_upload_spec.rb +0 -0
  47. data/spec/aliyun/oss/http_spec.rb +26 -0
  48. data/spec/aliyun/oss/multipart_spec.rb +53 -8
  49. data/spec/aliyun/oss/object_spec.rb +256 -10
  50. data/spec/aliyun/oss/service_spec.rb +0 -0
  51. data/spec/aliyun/oss/util_spec.rb +101 -0
  52. data/spec/aliyun/sts/client_spec.rb +0 -0
  53. data/spec/aliyun/sts/util_spec.rb +0 -0
  54. data/tests/config.rb +2 -0
  55. data/tests/helper.rb +15 -0
  56. data/tests/test_content_encoding.rb +0 -0
  57. data/tests/test_content_type.rb +0 -0
  58. data/tests/test_crc_check.rb +184 -0
  59. data/tests/test_custom_headers.rb +14 -6
  60. data/tests/test_encoding.rb +0 -0
  61. data/tests/test_large_file.rb +0 -0
  62. data/tests/test_multipart.rb +0 -0
  63. data/tests/test_object_acl.rb +0 -0
  64. data/tests/test_object_key.rb +18 -0
  65. data/tests/test_object_url.rb +20 -0
  66. data/tests/test_resumable.rb +0 -0
  67. metadata +33 -12
File without changes
@@ -25,7 +25,7 @@ module Aliyun
25
25
  # @param role [String] the role arn
26
26
  # @param session [String] the session name
27
27
  # @param policy [STS::Policy] the policy
28
- # @param duration [Fixnum] the duration seconds for the
28
+ # @param duration [Integer] the duration seconds for the
29
29
  # requested token
30
30
  # @return [STS::Token] the sts token
31
31
  def assume_role(role, session, policy = nil, duration = 3600)
File without changes
File without changes
@@ -27,7 +27,7 @@ module Aliyun
27
27
  # @param role [String] the role arn
28
28
  # @param session [String] the session name
29
29
  # @param policy [STS::Policy] the policy
30
- # @param duration [Fixnum] the duration seconds for the
30
+ # @param duration [Integer] the duration seconds for the
31
31
  # requested token
32
32
  # @return [STS::Token] the sts token
33
33
  def assume_role(role, session, policy = nil, duration = 3600)
@@ -88,14 +88,14 @@ module Aliyun
88
88
  :method => 'POST',
89
89
  :url => @config.endpoint || ENDPOINT,
90
90
  :payload => query
91
- ) do |response, request, result, &blk|
91
+ ) do |response, &blk|
92
92
 
93
93
  if response.code >= 300
94
94
  e = ServerError.new(response)
95
95
  logger.error(e.to_s)
96
96
  raise e
97
97
  else
98
- response.return!(request, result, &blk)
98
+ response.return!(&blk)
99
99
  end
100
100
  end
101
101
 
File without changes
File without changes
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Aliyun
4
4
 
5
- VERSION = "0.4.1"
5
+ VERSION = "0.7.2"
6
6
 
7
7
  end # Aliyun
@@ -89,7 +89,7 @@ module Aliyun
89
89
  if opts.enabled?
90
90
  xml.LoggingEnabled {
91
91
  xml.TargetBucket opts.target_bucket
92
- xml.TargetPrefix opts.target_prefix
92
+ xml.TargetPrefix opts.target_prefix if opts.target_prefix
93
93
  }
94
94
  end
95
95
  }
@@ -356,7 +356,7 @@ module Aliyun
356
356
 
357
357
  context "acl, logging, website, referer, lifecycle" do
358
358
  it "should update acl" do
359
- query = {'acl' => ''}
359
+ query = {'acl' => nil}
360
360
  stub_request(:put, request_path).with(:query => query)
361
361
 
362
362
  @protocol.put_bucket_acl(@bucket, ACL::PUBLIC_READ)
@@ -366,7 +366,7 @@ module Aliyun
366
366
  end
367
367
 
368
368
  it "should get acl" do
369
- query = {'acl' => ''}
369
+ query = {'acl' => nil}
370
370
  return_acl = ACL::PUBLIC_READ
371
371
  stub_request(:get, request_path)
372
372
  .with(:query => query)
@@ -380,7 +380,7 @@ module Aliyun
380
380
  end
381
381
 
382
382
  it "should enable logging" do
383
- query = {'logging' => ''}
383
+ query = {'logging' => nil}
384
384
  stub_request(:put, request_path).with(:query => query)
385
385
 
386
386
  logging_opts = BucketLogging.new(
@@ -392,8 +392,21 @@ module Aliyun
392
392
  .with(:query => query, :body => mock_logging(logging_opts))
393
393
  end
394
394
 
395
+ it "should enable logging without target prefix" do
396
+ query = {'logging' => nil}
397
+ stub_request(:put, request_path).with(:query => query)
398
+
399
+ logging_opts = BucketLogging.new(
400
+ :enable => true,
401
+ :target_bucket => 'target-bucket')
402
+ @protocol.put_bucket_logging(@bucket, logging_opts)
403
+
404
+ expect(WebMock).to have_requested(:put, request_path)
405
+ .with(:query => query, :body => mock_logging(logging_opts))
406
+ end
407
+
395
408
  it "should disable logging" do
396
- query = {'logging' => ''}
409
+ query = {'logging' => nil}
397
410
  stub_request(:put, request_path).with(:query => query)
398
411
 
399
412
  logging_opts = BucketLogging.new(:enable => false)
@@ -404,7 +417,7 @@ module Aliyun
404
417
  end
405
418
 
406
419
  it "should get logging" do
407
- query = {'logging' => ''}
420
+ query = {'logging' => nil}
408
421
  logging_opts = BucketLogging.new(
409
422
  :enable => true,
410
423
  :target_bucket => 'target-bucket', :target_prefix => 'foo')
@@ -420,8 +433,25 @@ module Aliyun
420
433
  expect(logging.to_s).to eq(logging_opts.to_s)
421
434
  end
422
435
 
436
+ it "should get logging without target-bucket" do
437
+ query = {'logging' => nil}
438
+ logging_opts = BucketLogging.new(
439
+ :enable => false,
440
+ :target_bucket => nil, :target_prefix => nil)
441
+
442
+ stub_request(:get, request_path)
443
+ .with(:query => query)
444
+ .to_return(:body => mock_logging(logging_opts))
445
+
446
+ logging = @protocol.get_bucket_logging(@bucket)
447
+
448
+ expect(WebMock).to have_requested(:get, request_path)
449
+ .with(:query => query, :body => nil)
450
+ expect(logging.to_s).to eq(logging_opts.to_s)
451
+ end
452
+
423
453
  it "should delete logging" do
424
- query = {'logging' => ''}
454
+ query = {'logging' => nil}
425
455
  stub_request(:delete, request_path).with(:query => query)
426
456
 
427
457
  @protocol.delete_bucket_logging(@bucket)
@@ -430,8 +460,20 @@ module Aliyun
430
460
  .with(:query => query, :body => nil)
431
461
  end
432
462
 
463
+ it "should raise Exception when enable logging" do
464
+ query = {'logging' => nil}
465
+ stub_request(:put, request_path).with(:query => query)
466
+
467
+ logging_opts = BucketLogging.new(
468
+ :enable => true,
469
+ :target_bucket => nil, :target_prefix => nil)
470
+ expect {
471
+ @protocol.put_bucket_logging(@bucket, logging_opts)
472
+ }.to raise_error(ClientError)
473
+ end
474
+
433
475
  it "should update website" do
434
- query = {'website' => ''}
476
+ query = {'website' => nil}
435
477
  stub_request(:put, request_path).with(:query => query)
436
478
 
437
479
  website_opts = BucketWebsite.new(
@@ -442,8 +484,20 @@ module Aliyun
442
484
  .with(:query => query, :body => mock_website(website_opts))
443
485
  end
444
486
 
487
+ it "should update website with index only" do
488
+ query = {'website' => nil}
489
+ stub_request(:put, request_path).with(:query => query)
490
+
491
+ website_opts = BucketWebsite.new(
492
+ :enable => true, :index => 'index.html', :error => nil)
493
+ @protocol.put_bucket_website(@bucket, website_opts)
494
+
495
+ expect(WebMock).to have_requested(:put, request_path)
496
+ .with(:query => query, :body => mock_website(website_opts))
497
+ end
498
+
445
499
  it "should get website" do
446
- query = {'website' => ''}
500
+ query = {'website' => nil}
447
501
  website_opts = BucketWebsite.new(
448
502
  :enable => true, :index => 'index.html', :error => 'error.html')
449
503
 
@@ -459,7 +513,7 @@ module Aliyun
459
513
  end
460
514
 
461
515
  it "should delete website" do
462
- query = {'website' => ''}
516
+ query = {'website' => nil}
463
517
  stub_request(:delete, request_path).with(:query => query)
464
518
 
465
519
  @protocol.delete_bucket_website(@bucket)
@@ -468,8 +522,20 @@ module Aliyun
468
522
  .with(:query => query, :body => nil)
469
523
  end
470
524
 
525
+ it "should raise Exception when update website" do
526
+ query = {'website' => nil}
527
+ stub_request(:put, request_path).with(:query => query)
528
+
529
+ website_opts = BucketWebsite.new(
530
+ :enable => true, :index => nil)
531
+
532
+ expect {
533
+ @protocol.put_bucket_website(@bucket, website_opts)
534
+ }.to raise_error(ClientError)
535
+ end
536
+
471
537
  it "should update referer" do
472
- query = {'referer' => ''}
538
+ query = {'referer' => nil}
473
539
  stub_request(:put, request_path).with(:query => query)
474
540
 
475
541
  referer_opts = BucketReferer.new(
@@ -481,7 +547,7 @@ module Aliyun
481
547
  end
482
548
 
483
549
  it "should get referer" do
484
- query = {'referer' => ''}
550
+ query = {'referer' => nil}
485
551
  referer_opts = BucketReferer.new(
486
552
  :allow_empty => true, :whitelist => ['xxx', 'yyy'])
487
553
 
@@ -497,7 +563,7 @@ module Aliyun
497
563
  end
498
564
 
499
565
  it "should update lifecycle" do
500
- query = {'lifecycle' => ''}
566
+ query = {'lifecycle' => nil}
501
567
  stub_request(:put, request_path).with(:query => query)
502
568
 
503
569
  rules = (1..5).map do |i|
@@ -513,7 +579,7 @@ module Aliyun
513
579
  end
514
580
 
515
581
  it "should get lifecycle" do
516
- query = {'lifecycle' => ''}
582
+ query = {'lifecycle' => nil}
517
583
  return_rules = (1..5).map do |i|
518
584
  LifeCycleRule.new(
519
585
  :id => i, :enable => i % 2 == 0, :prefix => "foo#{i}",
@@ -532,7 +598,7 @@ module Aliyun
532
598
  end
533
599
 
534
600
  it "should delete lifecycle" do
535
- query = {'lifecycle' => ''}
601
+ query = {'lifecycle' => nil}
536
602
  stub_request(:delete, request_path).with(:query => query)
537
603
 
538
604
  @protocol.delete_bucket_lifecycle(@bucket)
@@ -541,8 +607,46 @@ module Aliyun
541
607
  .with(:query => query, :body => nil)
542
608
  end
543
609
 
610
+ it "should raise Exception when update lifecycle " do
611
+ query = {'lifecycle' => nil}
612
+ stub_request(:put, request_path).with(:query => query)
613
+
614
+ rules = (1..5).map do |i|
615
+ LifeCycleRule.new(
616
+ :id => i, :enable => i % 2 == 0, :prefix => "foo#{i}",
617
+ :expiry => 'invalid')
618
+ end
619
+
620
+ expect {
621
+ @protocol.put_bucket_lifecycle(@bucket, rules)
622
+ }.to raise_error(ClientError)
623
+ end
624
+
625
+ it "should raise Exception when get lifecycle " do
626
+ query = {'lifecycle' => nil}
627
+ body = '<LifecycleConfiguration>
628
+ <Rule>
629
+ <ID>delete after one day</ID>
630
+ <Prefix>logs/</Prefix>
631
+ <Status>Enabled</Status>
632
+ <Expiration>
633
+ <Days>1</Days>
634
+ <Date>2017-01-01T00:00:00.000Z</Date>
635
+ </Expiration>
636
+ </Rule>
637
+ </LifecycleConfiguration>'
638
+
639
+ stub_request(:get, request_path)
640
+ .with(:query => query)
641
+ .to_return(:body => body)
642
+
643
+ expect {
644
+ rules = @protocol.get_bucket_lifecycle(@bucket)
645
+ }.to raise_error(ClientError)
646
+ end
647
+
544
648
  it "should set cors" do
545
- query = {'cors' => ''}
649
+ query = {'cors' => nil}
546
650
  stub_request(:put, request_path).with(:query => query)
547
651
 
548
652
  rules = (1..5).map do |i|
@@ -558,8 +662,26 @@ module Aliyun
558
662
  .with(:query => query, :body => mock_cors(rules))
559
663
  end
560
664
 
665
+ it "should set cors with MaxAgeSeconds " do
666
+ query = {'cors' => nil}
667
+ stub_request(:put, request_path).with(:query => query)
668
+
669
+ rules = (1..5).map do |i|
670
+ CORSRule.new(
671
+ :allowed_origins => (1..3).map {|x| "origin-#{x}"},
672
+ :allowed_methods => ['PUT', 'GET'],
673
+ :allowed_headers => (1..3).map {|x| "header-#{x}"},
674
+ :expose_headers => (1..3).map {|x| "header-#{x}"},
675
+ :max_age_seconds => 5)
676
+ end
677
+ @protocol.set_bucket_cors(@bucket, rules)
678
+
679
+ expect(WebMock).to have_requested(:put, request_path)
680
+ .with(:query => query, :body => mock_cors(rules))
681
+ end
682
+
561
683
  it "should get cors" do
562
- query = {'cors' => ''}
684
+ query = {'cors' => nil}
563
685
  return_rules = (1..5).map do |i|
564
686
  CORSRule.new(
565
687
  :allowed_origins => (1..3).map {|x| "origin-#{x}"},
@@ -580,7 +702,7 @@ module Aliyun
580
702
  end
581
703
 
582
704
  it "should delete cors" do
583
- query = {'cors' => ''}
705
+ query = {'cors' => nil}
584
706
 
585
707
  stub_request(:delete, request_path).with(:query => query)
586
708
 
@@ -591,6 +713,60 @@ module Aliyun
591
713
 
592
714
  end # acl, logging, cors, etc
593
715
 
716
+ context "crc" do
717
+ it "should download crc enable equal config setting" do
718
+ protocol = Protocol.new(
719
+ Config.new(:endpoint => @endpoint,
720
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
721
+ :download_crc_enable => 'true'))
722
+ expect(protocol.download_crc_enable).to eq(true)
723
+
724
+ protocol = Protocol.new(
725
+ Config.new(:endpoint => @endpoint,
726
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
727
+ :download_crc_enable => true))
728
+ expect(protocol.download_crc_enable).to eq(true)
729
+
730
+ protocol = Protocol.new(
731
+ Config.new(:endpoint => @endpoint,
732
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
733
+ :download_crc_enable => 'false'))
734
+ expect(protocol.download_crc_enable).to eq(false)
735
+
736
+ protocol = Protocol.new(
737
+ Config.new(:endpoint => @endpoint,
738
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
739
+ :download_crc_enable => false))
740
+ expect(protocol.download_crc_enable).to eq(false)
741
+ end
742
+
743
+ it "should upload crc enable equal config setting" do
744
+ protocol = Protocol.new(
745
+ Config.new(:endpoint => @endpoint,
746
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
747
+ :upload_crc_enable => 'true'))
748
+ expect(protocol.upload_crc_enable).to eq(true)
749
+
750
+ protocol = Protocol.new(
751
+ Config.new(:endpoint => @endpoint,
752
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
753
+ :upload_crc_enable => true))
754
+ expect(protocol.upload_crc_enable).to eq(true)
755
+
756
+ protocol = Protocol.new(
757
+ Config.new(:endpoint => @endpoint,
758
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
759
+ :upload_crc_enable => 'false'))
760
+ expect(protocol.upload_crc_enable).to eq(false)
761
+
762
+ protocol = Protocol.new(
763
+ Config.new(:endpoint => @endpoint,
764
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
765
+ :upload_crc_enable => false))
766
+ expect(protocol.upload_crc_enable).to eq(false)
767
+ end
768
+ end # crc
769
+
594
770
  end # Bucket
595
771
 
596
772
  end # OSS
@@ -120,7 +120,7 @@ module Aliyun
120
120
 
121
121
  context "bucket operations" do
122
122
  it "should get acl" do
123
- query = {'acl' => ''}
123
+ query = {'acl' => nil}
124
124
  return_acl = ACL::PUBLIC_READ
125
125
 
126
126
  stub_request(:get, bucket_url)
@@ -135,7 +135,7 @@ module Aliyun
135
135
  end
136
136
 
137
137
  it "should set acl" do
138
- query = {'acl' => ''}
138
+ query = {'acl' => nil}
139
139
 
140
140
  stub_request(:put, bucket_url).with(:query => query)
141
141
 
@@ -146,7 +146,7 @@ module Aliyun
146
146
  end
147
147
 
148
148
  it "should delete logging setting" do
149
- query = {'logging' => ''}
149
+ query = {'logging' => nil}
150
150
 
151
151
  stub_request(:delete, bucket_url).with(:query => query)
152
152
 
@@ -156,6 +156,226 @@ module Aliyun
156
156
  .with(:query => query, :body => nil)
157
157
  end
158
158
 
159
+ it "should set logging setting" do
160
+ query = {'logging' => nil}
161
+
162
+ body = Nokogiri::XML::Builder.new do |xml|
163
+ xml.BucketLoggingStatus {
164
+ xml.LoggingEnabled {
165
+ xml.TargetBucket 'target-bucket'
166
+ }
167
+ }
168
+ end.to_xml
169
+
170
+ stub_request(:put, bucket_url).with(:query => query)
171
+
172
+ @bucket.logging = BucketLogging.new(:enable => true, :target_bucket => 'target-bucket')
173
+
174
+ expect(WebMock).to have_requested(:put, bucket_url)
175
+ .with(:query => query, :body => body)
176
+ end
177
+
178
+ it "should get logging setting" do
179
+ query = {'logging' => nil}
180
+
181
+ retbody = Nokogiri::XML::Builder.new do |xml|
182
+ xml.BucketLoggingStatus {
183
+ xml.LoggingEnabled {
184
+ xml.TargetBucket 'target-bucket'
185
+ xml.TargetPrefix 'target-prefix'
186
+ }
187
+ }
188
+ end.to_xml
189
+
190
+ stub_request(:get, bucket_url)
191
+ .with(:query => query)
192
+ .to_return(status: 200, :body => retbody)
193
+
194
+ logging = @bucket.logging
195
+
196
+ expect(WebMock).to have_requested(:get, bucket_url)
197
+ .with(:query => query, :body => nil)
198
+ expect(logging.enable).to eq(true)
199
+ expect(logging.target_bucket).to eq('target-bucket')
200
+
201
+ end
202
+
203
+ it "should set webseit" do
204
+ query = {'website' => nil}
205
+
206
+ body = Nokogiri::XML::Builder.new do |xml|
207
+ xml.WebsiteConfiguration {
208
+ xml.IndexDocument {
209
+ xml.Suffix 'index.html'
210
+ }
211
+ }
212
+ end.to_xml
213
+
214
+ stub_request(:put, bucket_url)
215
+ .with(:query => query)
216
+ .to_return(status: 200, :body => nil)
217
+
218
+ @bucket.website = BucketWebsite.new(:enable => true, :index => 'index.html')
219
+
220
+ expect(WebMock).to have_requested(:put, bucket_url)
221
+ .with(:query => query, :body => body)
222
+ end
223
+
224
+ it "should delete webseit" do
225
+ query = {'website' => nil}
226
+
227
+ stub_request(:delete, bucket_url)
228
+ .with(:query => query)
229
+ .to_return(status: 204, :body => nil)
230
+
231
+ @bucket.website = BucketWebsite.new(:enable => false)
232
+
233
+ expect(WebMock).to have_requested(:delete, bucket_url)
234
+ .with(:query => query, :body => nil)
235
+ end
236
+
237
+ it "should get webseit" do
238
+ query = {'website' => nil}
239
+
240
+ body = Nokogiri::XML::Builder.new do |xml|
241
+ xml.WebsiteConfiguration {
242
+ xml.IndexDocument {
243
+ xml.Suffix 'index.html'
244
+ }
245
+ xml.ErrorDocument {
246
+ xml.Key 'error.html'
247
+ }
248
+ }
249
+ end.to_xml
250
+
251
+ stub_request(:get, bucket_url)
252
+ .with(:query => query)
253
+ .to_return(status: 200, :body => body)
254
+
255
+ website = @bucket.website
256
+
257
+ expect(WebMock).to have_requested(:get, bucket_url)
258
+ .with(:query => query, :body => nil)
259
+
260
+ expect(website.enable).to eq(true)
261
+ expect(website.index).to eq('index.html')
262
+ expect(website.error).to eq('error.html')
263
+ end
264
+
265
+ it "should set referer" do
266
+ query = {'referer' => nil}
267
+
268
+ body = Nokogiri::XML::Builder.new do |xml|
269
+ xml.RefererConfiguration {
270
+ xml.AllowEmptyReferer 'true'
271
+ xml.RefererList {
272
+ xml.Referer 'http://www.aliyun.com'
273
+ }
274
+ }
275
+ end.to_xml
276
+
277
+ stub_request(:put, bucket_url)
278
+ .with(:query => query)
279
+ .to_return(status: 200, :body => nil)
280
+
281
+ @bucket.referer = BucketReferer.new(:allow_empty => true, :whitelist => ['http://www.aliyun.com'])
282
+
283
+ expect(WebMock).to have_requested(:put, bucket_url)
284
+ .with(:query => query, :body => body)
285
+ end
286
+
287
+ it "should get referer" do
288
+ query = {'referer' => nil}
289
+
290
+ body = Nokogiri::XML::Builder.new do |xml|
291
+ xml.RefererConfiguration {
292
+ xml.AllowEmptyReferer 'true'
293
+ xml.RefererList {
294
+ xml.Referer 'http://www.aliyun.com'
295
+ }
296
+ }
297
+ end.to_xml
298
+
299
+ stub_request(:get, bucket_url)
300
+ .with(:query => query)
301
+ .to_return(status: 200, :body => body)
302
+
303
+ referer = @bucket.referer
304
+
305
+ expect(WebMock).to have_requested(:get, bucket_url)
306
+ .with(:query => query, :body => nil)
307
+
308
+ expect(referer.allow_empty).to eq(true)
309
+ expect(referer.whitelist).to eq(['http://www.aliyun.com'])
310
+ end
311
+
312
+ it "should set cors" do
313
+ query = {'cors' => nil}
314
+
315
+ body = Nokogiri::XML::Builder.new do |xml|
316
+ xml.CORSConfiguration {
317
+ xml.CORSRule {
318
+ xml.AllowedOrigin '*'
319
+ xml.AllowedMethod 'PUT'
320
+ xml.AllowedHeader 'Authorization'
321
+ }
322
+ }
323
+ end.to_xml
324
+
325
+ stub_request(:put, bucket_url)
326
+ .with(:query => query)
327
+ .to_return(status: 200, :body => nil)
328
+
329
+ rules = [
330
+ CORSRule.new(
331
+ :allowed_origins => ['*'],
332
+ :allowed_methods => ['PUT'],
333
+ :allowed_headers => ['Authorization'],
334
+ :expose_headers =>[])
335
+ ]
336
+
337
+ @bucket.cors = rules
338
+
339
+ expect(WebMock).to have_requested(:put, bucket_url)
340
+ .with(:query => query, :body => body)
341
+ end
342
+
343
+ it "should delete cors" do
344
+ query = {'cors' => nil}
345
+
346
+ stub_request(:delete, bucket_url)
347
+ .with(:query => query)
348
+ .to_return(status: 204, :body => nil)
349
+
350
+ @bucket.cors = []
351
+
352
+ expect(WebMock).to have_requested(:delete, bucket_url)
353
+ .with(:query => query, :body => nil)
354
+ end
355
+
356
+ it "should get cors" do
357
+ query = {'cors' => nil}
358
+
359
+ body = Nokogiri::XML::Builder.new do |xml|
360
+ xml.CORSConfiguration {
361
+ xml.CORSRule {
362
+ xml.AllowedOrigin '*'
363
+ xml.AllowedMethod 'PUT'
364
+ xml.AllowedHeader 'Authorization'
365
+ }
366
+ }
367
+ end.to_xml
368
+
369
+ stub_request(:get, bucket_url)
370
+ .with(:query => query)
371
+ .to_return(status: 200, :body => body)
372
+
373
+ cors = @bucket.cors
374
+
375
+ expect(WebMock).to have_requested(:get, bucket_url)
376
+ .with(:query => query, :body => nil)
377
+ end
378
+
159
379
  it "should get bucket url" do
160
380
  expect(@bucket.bucket_url)
161
381
  .to eq('http://rubysdk-bucket.oss-cn-hangzhou.aliyuncs.com/')
@@ -303,7 +523,7 @@ module Aliyun
303
523
 
304
524
  it "should set custom headers when append object" do
305
525
  key = 'ruby'
306
- query = {'append' => '', 'position' => 11}
526
+ query = {'append' => nil, 'position' => 11}
307
527
  stub_request(:post, object_url(key)).with(:query => query)
308
528
 
309
529
  @bucket.append_object(
@@ -362,7 +582,7 @@ module Aliyun
362
582
 
363
583
  it "should append object from file" do
364
584
  key = 'ruby'
365
- query = {'append' => '', 'position' => 11}
585
+ query = {'append' => nil, 'position' => 11}
366
586
  stub_request(:post, object_url(key)).with(:query => query)
367
587
 
368
588
  content = (1..10).map{ |i| i.to_s.rjust(9, '0') }.join("\n")
@@ -378,7 +598,7 @@ module Aliyun
378
598
 
379
599
  it "should append object with acl" do
380
600
  key = 'ruby'
381
- query = {'append' => '', 'position' => 11}
601
+ query = {'append' => nil, 'position' => 11}
382
602
  stub_request(:post, object_url(key)).with(:query => query)
383
603
 
384
604
  @bucket.append_object(key, 11, :acl => ACL::PUBLIC_READ_WRITE)
@@ -467,29 +687,55 @@ module Aliyun
467
687
  expect(signature).to eq(sig)
468
688
  end
469
689
 
470
- it "should get object url with STS" do
471
- sts_bucket = Client.new(
472
- :endpoint => @endpoint,
473
- :access_key_id => 'xxx',
474
- :access_key_secret => 'yyy',
475
- :sts_token => 'zzz').get_bucket(@bucket_name)
476
-
477
- object_url = 'http://rubysdk-bucket.oss-cn-hangzhou.aliyuncs.com/yeah'
478
-
479
- url = sts_bucket.object_url('yeah')
480
- path = url[0, url.index('?')]
481
- expect(path).to eq(object_url)
482
-
483
- query = {}
484
- url[url.index('?') + 1, url.size].split('&')
485
- .each { |s| k, v = s.split('='); query[k] = v }
486
-
487
- expect(query.key?('Expires')).to be true
488
- expect(query.key?('Signature')).to be true
489
- expect(query['OSSAccessKeyId']).to eq('xxx')
490
- expect(query['security-token']).to eq('zzz')
690
+ context 'should use STS' do
691
+ it "get object url" do
692
+ sts_bucket = Client.new(
693
+ :endpoint => @endpoint,
694
+ :access_key_id => 'xxx',
695
+ :access_key_secret => 'yyy',
696
+ :sts_token => 'zzz').get_bucket(@bucket_name)
697
+
698
+ object_url = 'http://rubysdk-bucket.oss-cn-hangzhou.aliyuncs.com/yeah'
699
+
700
+ url = sts_bucket.object_url('yeah')
701
+ path = url[0, url.index('?')]
702
+ expect(path).to eq(object_url)
703
+
704
+ query = {}
705
+ url[url.index('?') + 1, url.size].split('&')
706
+ .each { |s| k, v = s.split('='); query[k] = v }
707
+
708
+ expect(query.key?('Expires')).to be true
709
+ expect(query.key?('Signature')).to be true
710
+ expect(query['OSSAccessKeyId']).to eq('xxx')
711
+ expect(query['security-token']).to eq('zzz')
712
+ end
713
+
714
+ it "get object url with query string" do
715
+ sts_bucket = Client.new(
716
+ :endpoint => @endpoint,
717
+ :access_key_id => 'xxx',
718
+ :access_key_secret => 'yyy',
719
+ :sts_token => 'zzz').get_bucket(@bucket_name)
720
+
721
+ param = {
722
+ 'x-oss-process' => 'image/resize,m_fill,h_100,w_100',
723
+ }
724
+ url = sts_bucket.object_url('ico.png', true, 60, param)
725
+ path = url[0, url.index('?')]
726
+ expect(path).to eq('http://rubysdk-bucket.oss-cn-hangzhou.aliyuncs.com/ico.png')
727
+
728
+ query = {}
729
+ url[url.index('?') + 1, url.size].split('&')
730
+ .each { |s| k, v = s.split('='); query[k] = v }
731
+
732
+ expect(query.key?('Expires')).to be true
733
+ expect(query.key?('Signature')).to be true
734
+ expect(query['OSSAccessKeyId']).to eq('xxx')
735
+ expect(query['security-token']).to eq('zzz')
736
+ expect(query['x-oss-process']).to eq('image%2Fresize%2Cm_fill%2Ch_100%2Cw_100')
737
+ end
491
738
  end
492
-
493
739
  end # object operations
494
740
 
495
741
  context "multipart operations" do
@@ -497,7 +743,7 @@ module Aliyun
497
743
  query_1 = {
498
744
  :prefix => 'list-',
499
745
  'encoding-type' => 'url',
500
- 'uploads' => ''
746
+ 'uploads' => nil
501
747
  }
502
748
  return_up_1 = (1..5).map{ |i| Multipart::Transaction.new(
503
749
  :id => "txn-#{i}",
@@ -513,7 +759,7 @@ module Aliyun
513
759
  :prefix => 'list-',
514
760
  'upload-id-marker' => 'txn-5',
515
761
  'encoding-type' => 'url',
516
- 'uploads' => ''
762
+ 'uploads' => nil
517
763
  }
518
764
  return_up_2 = (6..8).map{ |i| Multipart::Transaction.new(
519
765
  :id => "txn-#{i}",
@@ -549,6 +795,72 @@ module Aliyun
549
795
  end
550
796
  end # multipart operations
551
797
 
798
+ context "crc" do
799
+ it "should download crc enable equal config setting" do
800
+ bucket = Client.new(
801
+ :endpoint => @endpoint,
802
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
803
+ :download_crc_enable => 'true').get_bucket(@bucket_name)
804
+ expect(bucket.download_crc_enable).to eq(true)
805
+
806
+ bucket = Client.new(
807
+ :endpoint => @endpoint,
808
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
809
+ :download_crc_enable => true).get_bucket(@bucket_name)
810
+ expect(bucket.download_crc_enable).to eq(true)
811
+
812
+ bucket = Client.new(
813
+ :endpoint => @endpoint,
814
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
815
+ :download_crc_enable => 'false').get_bucket(@bucket_name)
816
+ expect(bucket.download_crc_enable).to eq(false)
817
+
818
+ bucket = Client.new(
819
+ :endpoint => @endpoint,
820
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
821
+ :download_crc_enable => false).get_bucket(@bucket_name)
822
+ expect(bucket.download_crc_enable).to eq(false)
823
+
824
+ # check default value
825
+ bucket = Client.new(
826
+ :endpoint => @endpoint,
827
+ :access_key_id => 'xxx', :access_key_secret => 'yyy').get_bucket(@bucket_name)
828
+ expect(bucket.download_crc_enable).to eq(false)
829
+ end
830
+
831
+ it "should upload crc enable equal config setting" do
832
+ bucket = Client.new(
833
+ :endpoint => @endpoint,
834
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
835
+ :upload_crc_enable => 'true').get_bucket(@bucket_name)
836
+ expect(bucket.upload_crc_enable).to eq(true)
837
+
838
+ bucket = Client.new(
839
+ :endpoint => @endpoint,
840
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
841
+ :upload_crc_enable => true).get_bucket(@bucket_name)
842
+ expect(bucket.upload_crc_enable).to eq(true)
843
+
844
+ bucket = Client.new(
845
+ :endpoint => @endpoint,
846
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
847
+ :upload_crc_enable => 'false').get_bucket(@bucket_name)
848
+ expect(bucket.upload_crc_enable).to eq(false)
849
+
850
+ bucket = Client.new(
851
+ :endpoint => @endpoint,
852
+ :access_key_id => 'xxx', :access_key_secret => 'yyy',
853
+ :upload_crc_enable => false).get_bucket(@bucket_name)
854
+ expect(bucket.upload_crc_enable).to eq(false)
855
+
856
+ # check default value
857
+ bucket = Client.new(
858
+ :endpoint => @endpoint,
859
+ :access_key_id => 'xxx', :access_key_secret => 'yyy').get_bucket(@bucket_name)
860
+ expect(bucket.upload_crc_enable).to eq(true)
861
+ end
862
+ end # crc
863
+
552
864
  end # Bucket
553
865
  end # OSS
554
866
  end # Aliyun