aliyun-oss-rails4 0.7.0.1448446959
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +19 -0
- data/INSTALL +35 -0
- data/README +443 -0
- data/Rakefile +334 -0
- data/bin/oss +6 -0
- data/bin/setup.rb +11 -0
- data/lib/aliyun/oss.rb +55 -0
- data/lib/aliyun/oss/acl.rb +132 -0
- data/lib/aliyun/oss/authentication.rb +222 -0
- data/lib/aliyun/oss/base.rb +241 -0
- data/lib/aliyun/oss/bucket.rb +320 -0
- data/lib/aliyun/oss/connection.rb +279 -0
- data/lib/aliyun/oss/error.rb +70 -0
- data/lib/aliyun/oss/exceptions.rb +134 -0
- data/lib/aliyun/oss/extensions.rb +364 -0
- data/lib/aliyun/oss/logging.rb +304 -0
- data/lib/aliyun/oss/object.rb +612 -0
- data/lib/aliyun/oss/owner.rb +45 -0
- data/lib/aliyun/oss/parsing.rb +100 -0
- data/lib/aliyun/oss/response.rb +181 -0
- data/lib/aliyun/oss/service.rb +52 -0
- data/lib/aliyun/oss/version.rb +14 -0
- data/support/faster-xml-simple/lib/faster_xml_simple.rb +188 -0
- data/support/faster-xml-simple/test/regression_test.rb +48 -0
- data/support/faster-xml-simple/test/test_helper.rb +18 -0
- data/support/faster-xml-simple/test/xml_simple_comparison_test.rb +47 -0
- data/support/rdoc/code_info.rb +212 -0
- data/test/acl_test.rb +70 -0
- data/test/authentication_test.rb +114 -0
- data/test/base_test.rb +137 -0
- data/test/bucket_test.rb +75 -0
- data/test/connection_test.rb +218 -0
- data/test/error_test.rb +71 -0
- data/test/extensions_test.rb +346 -0
- data/test/fixtures.rb +90 -0
- data/test/fixtures/buckets.yml +133 -0
- data/test/fixtures/errors.yml +34 -0
- data/test/fixtures/headers.yml +3 -0
- data/test/fixtures/logging.yml +15 -0
- data/test/fixtures/loglines.yml +5 -0
- data/test/fixtures/logs.yml +7 -0
- data/test/fixtures/policies.yml +16 -0
- data/test/logging_test.rb +90 -0
- data/test/mocks/fake_response.rb +27 -0
- data/test/object_test.rb +221 -0
- data/test/parsing_test.rb +67 -0
- data/test/remote/acl_test.rb +28 -0
- data/test/remote/bucket_test.rb +147 -0
- data/test/remote/logging_test.rb +86 -0
- data/test/remote/object_test.rb +350 -0
- data/test/remote/test_file.data +0 -0
- data/test/remote/test_helper.rb +34 -0
- data/test/response_test.rb +69 -0
- data/test/service_test.rb +24 -0
- data/test/test_helper.rb +110 -0
- metadata +177 -0
Binary file
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require 'uri'
|
4
|
+
$:.unshift File.dirname(__FILE__) + '/../../lib'
|
5
|
+
require 'aliyun/oss'
|
6
|
+
begin
|
7
|
+
require_library_or_gem 'breakpoint'
|
8
|
+
rescue LoadError
|
9
|
+
end
|
10
|
+
|
11
|
+
TEST_BUCKET = 'aliyun-oss-tests'
|
12
|
+
TEST_FILE = File.dirname(__FILE__) + '/test_file.data'
|
13
|
+
|
14
|
+
class Test::Unit::TestCase
|
15
|
+
include Aliyun::OSS
|
16
|
+
def establish_real_connection
|
17
|
+
Base.establish_connection!(
|
18
|
+
:access_key_id => ENV['OSS_ACCESS_KEY_ID'],
|
19
|
+
:secret_access_key => ENV['OSS_SECRET_ACCESS_KEY']
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def disconnect!
|
24
|
+
Base.disconnect
|
25
|
+
end
|
26
|
+
|
27
|
+
class TestBucket < Bucket
|
28
|
+
set_current_bucket_to TEST_BUCKET
|
29
|
+
end
|
30
|
+
|
31
|
+
class TestOSSObject < OSSObject
|
32
|
+
set_current_bucket_to TEST_BUCKET
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require File.dirname(__FILE__) + '/test_helper'
|
3
|
+
class BaseResponseTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@headers = {'content-type' => 'text/plain', 'date' => Time.now}
|
6
|
+
@response = FakeResponse.new()
|
7
|
+
@base_response = Base::Response.new(@response)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_status_predicates
|
11
|
+
response = Proc.new {|code| Base::Response.new(FakeResponse.new(:code => code))}
|
12
|
+
assert response[200].success?
|
13
|
+
assert response[300].redirect?
|
14
|
+
assert response[400].client_error?
|
15
|
+
assert response[500].server_error?
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_headers_passed_along_from_original_response
|
19
|
+
assert_equal @response.headers, @base_response.headers
|
20
|
+
assert_equal @response['date'], @base_response['date']
|
21
|
+
original_headers, new_headers = {}, {}
|
22
|
+
@response.headers.each {|k,v| original_headers[k] = v}
|
23
|
+
@base_response.each {|k,v| new_headers[k] = v}
|
24
|
+
assert_equal original_headers, new_headers
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class ErrorResponseTest < Test::Unit::TestCase
|
29
|
+
def test_error_responses_are_always_in_error
|
30
|
+
assert Error::Response.new(FakeResponse.new).error?
|
31
|
+
assert Error::Response.new(FakeResponse.new(:code => 200)).error?
|
32
|
+
assert Error::Response.new(FakeResponse.new(:headers => {'content-type' => 'text/plain'})).error?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class OSSObjectResponseTest < Test::Unit::TestCase
|
37
|
+
def test_etag_extracted
|
38
|
+
mock_connection_for(OSSObject, :returns => {:headers => {"etag" => %("acbd18db4cc2f85cedef654fccc4a4d8")}}).once
|
39
|
+
object_response = OSSObject.create('name_does_not_matter', 'data does not matter', 'bucket does not matter')
|
40
|
+
assert_equal "acbd18db4cc2f85cedef654fccc4a4d8", object_response.etag
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class ResponseClassFinderTest < Test::Unit::TestCase
|
45
|
+
class CampfireBucket < Bucket
|
46
|
+
end
|
47
|
+
|
48
|
+
class BabyBase < Base
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_on_base
|
52
|
+
assert_equal Base::Response, FindResponseClass.for(Base)
|
53
|
+
assert_equal Base::Response, FindResponseClass.for(Aliyun::OSS::Base)
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_on_subclass_with_corresponding_response_class
|
58
|
+
assert_equal Bucket::Response, FindResponseClass.for(Bucket)
|
59
|
+
assert_equal Bucket::Response, FindResponseClass.for(Aliyun::OSS::Bucket)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_on_subclass_with_intermediary_parent_that_has_corresponding_response_class
|
63
|
+
assert_equal Bucket::Response, FindResponseClass.for(CampfireBucket)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_on_subclass_with_no_corresponding_response_class_and_no_intermediary_parent
|
67
|
+
assert_equal Base::Response, FindResponseClass.for(BabyBase)
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require File.dirname(__FILE__) + '/test_helper'
|
3
|
+
|
4
|
+
class ServiceTest < Test::Unit::TestCase
|
5
|
+
def test_bucket_list_with_empty_bucket_list
|
6
|
+
mock_connection_for(Service, :returns => {:body => Fixtures::Buckets.empty_bucket_list, :code => 200})
|
7
|
+
list = Service.buckets(:reload)
|
8
|
+
assert_equal [], list
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_bucket_list_with_bucket_list_containing_one_bucket
|
12
|
+
mock_connection_for(Service, :returns => {:body => Fixtures::Buckets.bucket_list_with_one_bucket, :code => 200})
|
13
|
+
list = Service.buckets(:reload)
|
14
|
+
assert_equal 1, list.size
|
15
|
+
assert_equal 'marcel_molina', list.first.name
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_bucket_list_with_bucket_list_containing_more_than_one_bucket
|
19
|
+
mock_connection_for(Service, :returns => {:body => Fixtures::Buckets.bucket_list_with_more_than_one_bucket, :code => 200})
|
20
|
+
list = Service.buckets(:reload)
|
21
|
+
assert_equal 2, list.size
|
22
|
+
assert_equal %w(marcel_molina marcel_molina_jr), list.map {|bucket| bucket.name}.sort
|
23
|
+
end
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
4
|
+
require 'aliyun/oss'
|
5
|
+
require File.dirname(__FILE__) + '/mocks/fake_response'
|
6
|
+
require File.dirname(__FILE__) + '/fixtures'
|
7
|
+
begin
|
8
|
+
require_library_or_gem 'ruby-debug'
|
9
|
+
rescue LoadError
|
10
|
+
end
|
11
|
+
require_library_or_gem 'flexmock'
|
12
|
+
require_library_or_gem 'flexmock/test_unit'
|
13
|
+
|
14
|
+
|
15
|
+
module AliyunDocExampleData
|
16
|
+
module Example1
|
17
|
+
module_function
|
18
|
+
|
19
|
+
def request
|
20
|
+
request = Net::HTTP::Put.new('/quotes/nelson')
|
21
|
+
request['Content-Md5'] = 'c8fdb181845a4ca6b8fec737b3581d76'
|
22
|
+
request['Content-Type'] = 'text/html'
|
23
|
+
request['Date'] = 'Thu, 17 Nov 2005 18:49:58 GMT'
|
24
|
+
request['X-OSS-Meta-Author'] = 'foo@bar.com'
|
25
|
+
request['X-OSS-Magic'] = 'abracadabra'
|
26
|
+
request
|
27
|
+
end
|
28
|
+
|
29
|
+
def canonical_string
|
30
|
+
"PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu, 17 Nov 2005 18:49:58 GMT\nx-oss-magic:abracadabra\nx-oss-meta-author:foo@bar.com\n/quotes/nelson"
|
31
|
+
end
|
32
|
+
|
33
|
+
def access_key_id
|
34
|
+
'44CF9590006BF252F707'
|
35
|
+
end
|
36
|
+
|
37
|
+
def secret_access_key
|
38
|
+
'OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV'
|
39
|
+
end
|
40
|
+
|
41
|
+
def signature
|
42
|
+
'63mwfl+zYIOG6k95yxbgMruQ6QI='
|
43
|
+
end
|
44
|
+
|
45
|
+
def authorization_header
|
46
|
+
'OSS 44CF9590006BF252F707:63mwfl+zYIOG6k95yxbgMruQ6QI='
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module Example3
|
51
|
+
module_function
|
52
|
+
|
53
|
+
def request
|
54
|
+
request = Net::HTTP::Get.new('/quotes/nelson')
|
55
|
+
request['Date'] = date
|
56
|
+
request
|
57
|
+
end
|
58
|
+
|
59
|
+
def date
|
60
|
+
'Thu Mar 9 01:24:20 CST 2006'
|
61
|
+
end
|
62
|
+
|
63
|
+
def access_key_id
|
64
|
+
Example1.access_key_id
|
65
|
+
end
|
66
|
+
|
67
|
+
def secret_access_key
|
68
|
+
Example1.secret_access_key
|
69
|
+
end
|
70
|
+
|
71
|
+
def expires
|
72
|
+
1141889120
|
73
|
+
end
|
74
|
+
|
75
|
+
def query_string
|
76
|
+
'OSSAccessKeyId=44CF9590006BF252F707&Expires=1141889120&Signature=vjbyPxybdZaNmGa%2ByT272YEAiv4%3D'
|
77
|
+
end
|
78
|
+
|
79
|
+
def canonical_string
|
80
|
+
"GET\n\n\n1141889120\n/quotes/nelson"
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class Test::Unit::TestCase
|
87
|
+
include Aliyun::OSS
|
88
|
+
|
89
|
+
def sample_proxy_settings
|
90
|
+
{:host => 'http://google.com', :port => 8080, :user => 'marcel', :password => 'secret'}
|
91
|
+
end
|
92
|
+
|
93
|
+
def mock_connection_for(klass, options = {})
|
94
|
+
data = options[:returns]
|
95
|
+
return_values = case data
|
96
|
+
when Hash
|
97
|
+
FakeResponse.new(data)
|
98
|
+
when Array
|
99
|
+
data.map {|hash| FakeResponse.new(hash)}
|
100
|
+
else
|
101
|
+
abort "Response data for mock connection must be a Hash or an Array. Was #{data.inspect}."
|
102
|
+
end
|
103
|
+
|
104
|
+
connection = flexmock('Mock connection') do |mock|
|
105
|
+
mock.should_receive(:request).and_return(*return_values).at_least.once
|
106
|
+
end
|
107
|
+
|
108
|
+
flexmock(klass).should_receive(:connection).and_return(connection)
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aliyun-oss-rails4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0.1448446959
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mangege
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: xml-simple
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: builder
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mime-types
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Client library for Aliyun's Open Storage Service's REST API
|
56
|
+
email: langyong135@gmail.com
|
57
|
+
executables:
|
58
|
+
- oss
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files:
|
61
|
+
- README
|
62
|
+
- COPYING
|
63
|
+
- INSTALL
|
64
|
+
files:
|
65
|
+
- COPYING
|
66
|
+
- INSTALL
|
67
|
+
- README
|
68
|
+
- Rakefile
|
69
|
+
- bin/oss
|
70
|
+
- bin/setup.rb
|
71
|
+
- lib/aliyun/oss.rb
|
72
|
+
- lib/aliyun/oss/acl.rb
|
73
|
+
- lib/aliyun/oss/authentication.rb
|
74
|
+
- lib/aliyun/oss/base.rb
|
75
|
+
- lib/aliyun/oss/bucket.rb
|
76
|
+
- lib/aliyun/oss/connection.rb
|
77
|
+
- lib/aliyun/oss/error.rb
|
78
|
+
- lib/aliyun/oss/exceptions.rb
|
79
|
+
- lib/aliyun/oss/extensions.rb
|
80
|
+
- lib/aliyun/oss/logging.rb
|
81
|
+
- lib/aliyun/oss/object.rb
|
82
|
+
- lib/aliyun/oss/owner.rb
|
83
|
+
- lib/aliyun/oss/parsing.rb
|
84
|
+
- lib/aliyun/oss/response.rb
|
85
|
+
- lib/aliyun/oss/service.rb
|
86
|
+
- lib/aliyun/oss/version.rb
|
87
|
+
- support/faster-xml-simple/lib/faster_xml_simple.rb
|
88
|
+
- support/faster-xml-simple/test/regression_test.rb
|
89
|
+
- support/faster-xml-simple/test/test_helper.rb
|
90
|
+
- support/faster-xml-simple/test/xml_simple_comparison_test.rb
|
91
|
+
- support/rdoc/code_info.rb
|
92
|
+
- test/acl_test.rb
|
93
|
+
- test/authentication_test.rb
|
94
|
+
- test/base_test.rb
|
95
|
+
- test/bucket_test.rb
|
96
|
+
- test/connection_test.rb
|
97
|
+
- test/error_test.rb
|
98
|
+
- test/extensions_test.rb
|
99
|
+
- test/fixtures.rb
|
100
|
+
- test/fixtures/buckets.yml
|
101
|
+
- test/fixtures/errors.yml
|
102
|
+
- test/fixtures/headers.yml
|
103
|
+
- test/fixtures/logging.yml
|
104
|
+
- test/fixtures/loglines.yml
|
105
|
+
- test/fixtures/logs.yml
|
106
|
+
- test/fixtures/policies.yml
|
107
|
+
- test/logging_test.rb
|
108
|
+
- test/mocks/fake_response.rb
|
109
|
+
- test/object_test.rb
|
110
|
+
- test/parsing_test.rb
|
111
|
+
- test/remote/acl_test.rb
|
112
|
+
- test/remote/bucket_test.rb
|
113
|
+
- test/remote/logging_test.rb
|
114
|
+
- test/remote/object_test.rb
|
115
|
+
- test/remote/test_file.data
|
116
|
+
- test/remote/test_helper.rb
|
117
|
+
- test/response_test.rb
|
118
|
+
- test/service_test.rb
|
119
|
+
- test/test_helper.rb
|
120
|
+
homepage: https://github.com/TimLang/aliyun-oss-sdk-for-ruby
|
121
|
+
licenses: []
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options:
|
125
|
+
- "--title"
|
126
|
+
- Aliyun::OSS -- Support for Aliyun OSS's REST api
|
127
|
+
- "--main"
|
128
|
+
- README
|
129
|
+
- "--line-numbers"
|
130
|
+
- "--inline-source"
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.4.5.1
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: Client library for Aliyun's Open Storage Service's REST API
|
149
|
+
test_files:
|
150
|
+
- test/acl_test.rb
|
151
|
+
- test/authentication_test.rb
|
152
|
+
- test/base_test.rb
|
153
|
+
- test/bucket_test.rb
|
154
|
+
- test/connection_test.rb
|
155
|
+
- test/error_test.rb
|
156
|
+
- test/extensions_test.rb
|
157
|
+
- test/fixtures/buckets.yml
|
158
|
+
- test/fixtures/errors.yml
|
159
|
+
- test/fixtures/headers.yml
|
160
|
+
- test/fixtures/logging.yml
|
161
|
+
- test/fixtures/loglines.yml
|
162
|
+
- test/fixtures/logs.yml
|
163
|
+
- test/fixtures/policies.yml
|
164
|
+
- test/fixtures.rb
|
165
|
+
- test/logging_test.rb
|
166
|
+
- test/mocks/fake_response.rb
|
167
|
+
- test/object_test.rb
|
168
|
+
- test/parsing_test.rb
|
169
|
+
- test/remote/acl_test.rb
|
170
|
+
- test/remote/bucket_test.rb
|
171
|
+
- test/remote/logging_test.rb
|
172
|
+
- test/remote/object_test.rb
|
173
|
+
- test/remote/test_file.data
|
174
|
+
- test/remote/test_helper.rb
|
175
|
+
- test/response_test.rb
|
176
|
+
- test/service_test.rb
|
177
|
+
- test/test_helper.rb
|