aliyun-oss-ex 0.7.0.1402831795

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.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +19 -0
  3. data/INSTALL +35 -0
  4. data/README +443 -0
  5. data/Rakefile +334 -0
  6. data/bin/oss +6 -0
  7. data/bin/setup.rb +11 -0
  8. data/lib/aliyun/oss.rb +55 -0
  9. data/lib/aliyun/oss/acl.rb +132 -0
  10. data/lib/aliyun/oss/authentication.rb +222 -0
  11. data/lib/aliyun/oss/base.rb +241 -0
  12. data/lib/aliyun/oss/bucket.rb +320 -0
  13. data/lib/aliyun/oss/connection.rb +279 -0
  14. data/lib/aliyun/oss/error.rb +70 -0
  15. data/lib/aliyun/oss/exceptions.rb +134 -0
  16. data/lib/aliyun/oss/extensions.rb +405 -0
  17. data/lib/aliyun/oss/logging.rb +304 -0
  18. data/lib/aliyun/oss/object.rb +612 -0
  19. data/lib/aliyun/oss/owner.rb +45 -0
  20. data/lib/aliyun/oss/parsing.rb +100 -0
  21. data/lib/aliyun/oss/response.rb +181 -0
  22. data/lib/aliyun/oss/service.rb +52 -0
  23. data/lib/aliyun/oss/version.rb +14 -0
  24. data/support/faster-xml-simple/lib/faster_xml_simple.rb +188 -0
  25. data/support/faster-xml-simple/test/regression_test.rb +48 -0
  26. data/support/faster-xml-simple/test/test_helper.rb +18 -0
  27. data/support/faster-xml-simple/test/xml_simple_comparison_test.rb +47 -0
  28. data/support/rdoc/code_info.rb +212 -0
  29. data/test/acl_test.rb +70 -0
  30. data/test/authentication_test.rb +114 -0
  31. data/test/base_test.rb +137 -0
  32. data/test/bucket_test.rb +75 -0
  33. data/test/connection_test.rb +218 -0
  34. data/test/error_test.rb +71 -0
  35. data/test/extensions_test.rb +346 -0
  36. data/test/fixtures.rb +90 -0
  37. data/test/fixtures/buckets.yml +133 -0
  38. data/test/fixtures/errors.yml +34 -0
  39. data/test/fixtures/headers.yml +3 -0
  40. data/test/fixtures/logging.yml +15 -0
  41. data/test/fixtures/loglines.yml +5 -0
  42. data/test/fixtures/logs.yml +7 -0
  43. data/test/fixtures/policies.yml +16 -0
  44. data/test/logging_test.rb +90 -0
  45. data/test/mocks/fake_response.rb +27 -0
  46. data/test/object_test.rb +221 -0
  47. data/test/parsing_test.rb +67 -0
  48. data/test/remote/acl_test.rb +28 -0
  49. data/test/remote/bucket_test.rb +147 -0
  50. data/test/remote/logging_test.rb +86 -0
  51. data/test/remote/object_test.rb +350 -0
  52. data/test/remote/test_file.data +0 -0
  53. data/test/remote/test_helper.rb +34 -0
  54. data/test/response_test.rb +69 -0
  55. data/test/service_test.rb +24 -0
  56. data/test/test_helper.rb +110 -0
  57. metadata +177 -0
@@ -0,0 +1,48 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require File.dirname(__FILE__) + '/test_helper'
3
+
4
+ class RegressionTest < FasterXSTest
5
+ def test_content_nil_regressions
6
+ expected = {"asdf"=>{"jklsemicolon"=>{}}}
7
+ assert_equal expected, FasterXmlSimple.xml_in("<asdf><jklsemicolon /></asdf>")
8
+ assert_equal expected, FasterXmlSimple.xml_in("<asdf><jklsemicolon /></asdf>", 'forcearray'=>['asdf'])
9
+ end
10
+
11
+ def test_oss_regression
12
+ str = File.read("test/fixtures/test-7.xml")
13
+ assert_nil FasterXmlSimple.xml_in(str)["AccessControlPolicy"]["AccessControlList"]["__content__"]
14
+ end
15
+
16
+ def test_xml_simple_transparency
17
+ assert_equal XmlSimple.xml_in("<asdf />"), FasterXmlSimple.xml_in("<asdf />")
18
+ end
19
+
20
+ def test_suppress_empty_variations
21
+ str = "<asdf><fdsa /></asdf>"
22
+
23
+ assert_equal Hash.new, FasterXmlSimple.xml_in(str)["asdf"]["fdsa"]
24
+ assert_nil FasterXmlSimple.xml_in(str, 'suppressempty'=>nil)["asdf"]["fdsa"]
25
+ assert_equal '', FasterXmlSimple.xml_in(str, 'suppressempty'=>'')["asdf"]["fdsa"]
26
+ assert !FasterXmlSimple.xml_in(str, 'suppressempty'=>true)["asdf"].has_key?("fdsa")
27
+ end
28
+
29
+ def test_empty_string_doesnt_crash
30
+ assert_raise(XML::Parser::ParseError) do
31
+ silence_stderr do
32
+ FasterXmlSimple.xml_in('')
33
+ end
34
+ end
35
+ end
36
+
37
+ def test_keeproot_false
38
+ str = "<asdf><fdsa>1</fdsa></asdf>"
39
+ expected = {"fdsa"=>"1"}
40
+ assert_equal expected, FasterXmlSimple.xml_in(str, 'keeproot'=>false)
41
+ end
42
+
43
+ def test_keeproot_false_with_force_content
44
+ str = "<asdf><fdsa>1</fdsa></asdf>"
45
+ expected = {"fdsa"=>{"__content__"=>"1"}}
46
+ assert_equal expected, FasterXmlSimple.xml_in(str, 'keeproot'=>false, 'forcecontent'=>true)
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'test/unit'
4
+ require 'faster_xml_simple'
5
+
6
+ class FasterXSTest < Test::Unit::TestCase
7
+ def default_test
8
+ end
9
+
10
+ def silence_stderr
11
+ str = STDERR.dup
12
+ STDERR.reopen("/dev/null")
13
+ STDERR.sync=true
14
+ yield
15
+ ensure
16
+ STDERR.reopen(str)
17
+ end
18
+ end
@@ -0,0 +1,47 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require File.dirname(__FILE__) + '/test_helper'
3
+ require 'yaml'
4
+
5
+ class XmlSimpleComparisonTest < FasterXSTest
6
+
7
+ # Define test methods
8
+
9
+ Dir["test/fixtures/test-*.xml"].each do |file_name|
10
+ xml_file_name = file_name
11
+ method_name = File.basename(file_name, ".xml").gsub('-', '_')
12
+ yml_file_name = file_name.gsub('xml', 'yml')
13
+ rails_yml_file_name = file_name.gsub('xml', 'rails.yml')
14
+ class_eval <<-EOV, __FILE__, __LINE__
15
+ def #{method_name}
16
+ assert_equal YAML.load(File.read('#{yml_file_name}')),
17
+ FasterXmlSimple.xml_in(File.read('#{xml_file_name}'), default_options )
18
+ end
19
+
20
+ def #{method_name}_rails
21
+ assert_equal YAML.load(File.read('#{rails_yml_file_name}')),
22
+ FasterXmlSimple.xml_in(File.read('#{xml_file_name}'), rails_options)
23
+ end
24
+ EOV
25
+ end
26
+
27
+ def default_options
28
+ {
29
+ 'keeproot' => true,
30
+ 'contentkey' => '__content__',
31
+ 'forcecontent' => true,
32
+ 'suppressempty' => nil,
33
+ 'forcearray' => ['something-else']
34
+ }
35
+ end
36
+
37
+ def rails_options
38
+ {
39
+ 'forcearray' => false,
40
+ 'forcecontent' => true,
41
+ 'keeproot' => true,
42
+ 'contentkey' => '__content__'
43
+ }
44
+ end
45
+
46
+
47
+ end
@@ -0,0 +1,212 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'rdoc/rdoc'
5
+
6
+ module RDoc
7
+ class CodeInfo
8
+ class << self
9
+ def parse(wildcard_pattern = nil)
10
+ @info_for_corpus = parse_files(wildcard_pattern)
11
+ end
12
+
13
+ def for(constant)
14
+ new(constant).info
15
+ end
16
+
17
+ def info_for_corpus
18
+ raise RuntimeError, "You must first generate a corpus to search by using RDoc::CodeInfo.parse" unless @info_for_corpus
19
+ @info_for_corpus
20
+ end
21
+
22
+ def parsed_files
23
+ info_for_corpus.map {|info| info.file_absolute_name}
24
+ end
25
+
26
+ def files_to_parse
27
+ @files_to_parse ||= Rake::FileList.new
28
+ end
29
+
30
+ private
31
+ def parse_files(pattern)
32
+ files = pattern ? Rake::FileList[pattern] : files_to_parse
33
+ options = Options.instance
34
+ options.parse(files << '-q', RDoc::GENERATORS)
35
+ rdoc.send(:parse_files, options)
36
+ end
37
+
38
+ def rdoc
39
+ TopLevel.reset
40
+ rdoc = RDoc.new
41
+ stats = Stats.new
42
+ # We don't want any output so we'll override the print method
43
+ stats.instance_eval { def print; nil end }
44
+ rdoc.instance_variable_set(:@stats, stats)
45
+ rdoc
46
+ end
47
+ end
48
+
49
+ attr_reader :info
50
+ def initialize(location)
51
+ @location = CodeLocation.new(location)
52
+ find_constant
53
+ find_method if @location.has_method?
54
+ end
55
+
56
+ private
57
+ attr_reader :location
58
+ attr_writer :info
59
+ def find_constant
60
+ parts = location.namespace_parts
61
+ self.class.info_for_corpus.each do |file_info|
62
+ @info = parts.inject(file_info) do |result, const_part|
63
+ (result.find_module_named(const_part) || result.find_class_named(const_part)) || break
64
+ end
65
+ return if info
66
+ end
67
+ end
68
+
69
+ def find_method
70
+ return unless info
71
+ self.info = info.method_list.detect do |method_info|
72
+ next unless method_info.name == location.method_name
73
+ if location.class_method?
74
+ method_info.singleton
75
+ elsif location.instance_method?
76
+ !method_info.singleton
77
+ else
78
+ true
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ class CodeLocation
85
+ attr_reader :location
86
+
87
+ def initialize(location)
88
+ @location = location
89
+ end
90
+
91
+ def parts
92
+ location.split(/::|\.|#/)
93
+ end
94
+
95
+ def namespace_parts
96
+ has_method? ? parts[0...-1] : parts
97
+ end
98
+
99
+ def has_method?
100
+ ('a'..'z').include?(parts.last[0, 1])
101
+ end
102
+
103
+ def instance_method?
104
+ !location['#'].nil?
105
+ end
106
+
107
+ def class_method?
108
+ has_method? && !location[/#|\./]
109
+ end
110
+
111
+ def method_name
112
+ parts.last if has_method?
113
+ end
114
+ end
115
+ end
116
+
117
+ if __FILE__ == $0
118
+ require 'test/unit'
119
+ class CodeInfoTest < Test::Unit::TestCase
120
+ def setup
121
+ RDoc::CodeInfo.parse(__FILE__)
122
+ end
123
+
124
+ def test_constant_lookup
125
+ assert RDoc::CodeInfo.for('RDoc')
126
+
127
+ info = RDoc::CodeInfo.for('RDoc::CodeInfo')
128
+ assert_equal 'CodeInfo', info.name
129
+ end
130
+
131
+ def test_method_lookup
132
+ {'RDoc::CodeInfo.parse' => true,
133
+ 'RDoc::CodeInfo::parse' => true,
134
+ 'RDoc::CodeInfo#parse' => false,
135
+ 'RDoc::CodeInfo.find_method' => true,
136
+ 'RDoc::CodeInfo::find_method' => false,
137
+ 'RDoc::CodeInfo#find_method' => true,
138
+ 'RDoc::CodeInfo#no_such_method' => false,
139
+ 'RDoc::NoSuchConst#foo' => false}.each do |location, result_of_lookup|
140
+ assert_equal result_of_lookup, !RDoc::CodeInfo.for(location).nil?
141
+ end
142
+ end
143
+ end
144
+
145
+ class CodeLocationTest < Test::Unit::TestCase
146
+ def test_parts
147
+ {'Foo' => %w(Foo),
148
+ 'Foo::Bar' => %w(Foo Bar),
149
+ 'Foo::Bar#baz' => %w(Foo Bar baz),
150
+ 'Foo::Bar.baz' => %w(Foo Bar baz),
151
+ 'Foo::Bar::baz' => %w(Foo Bar baz),
152
+ 'Foo::Bar::Baz' => %w(Foo Bar Baz)}.each do |location, parts|
153
+ assert_equal parts, RDoc::CodeLocation.new(location).parts
154
+ end
155
+ end
156
+
157
+ def test_namespace_parts
158
+ {'Foo' => %w(Foo),
159
+ 'Foo::Bar' => %w(Foo Bar),
160
+ 'Foo::Bar#baz' => %w(Foo Bar),
161
+ 'Foo::Bar.baz' => %w(Foo Bar),
162
+ 'Foo::Bar::baz' => %w(Foo Bar),
163
+ 'Foo::Bar::Baz' => %w(Foo Bar Baz)}.each do |location, namespace_parts|
164
+ assert_equal namespace_parts, RDoc::CodeLocation.new(location).namespace_parts
165
+ end
166
+ end
167
+
168
+ def test_has_method?
169
+ {'Foo' => false,
170
+ 'Foo::Bar' => false,
171
+ 'Foo::Bar#baz' => true,
172
+ 'Foo::Bar.baz' => true,
173
+ 'Foo::Bar::baz' => true,
174
+ 'Foo::Bar::Baz' => false}.each do |location, has_method_result|
175
+ assert_equal has_method_result, RDoc::CodeLocation.new(location).has_method?
176
+ end
177
+ end
178
+
179
+ def test_instance_method?
180
+ {'Foo' => false,
181
+ 'Foo::Bar' => false,
182
+ 'Foo::Bar#baz' => true,
183
+ 'Foo::Bar.baz' => false,
184
+ 'Foo::Bar::baz' => false,
185
+ 'Foo::Bar::Baz' => false}.each do |location, is_instance_method|
186
+ assert_equal is_instance_method, RDoc::CodeLocation.new(location).instance_method?
187
+ end
188
+ end
189
+
190
+ def test_class_method?
191
+ {'Foo' => false,
192
+ 'Foo::Bar' => false,
193
+ 'Foo::Bar#baz' => false,
194
+ 'Foo::Bar.baz' => false,
195
+ 'Foo::Bar::baz' => true,
196
+ 'Foo::Bar::Baz' => false}.each do |location, is_class_method|
197
+ assert_equal is_class_method, RDoc::CodeLocation.new(location).class_method?
198
+ end
199
+ end
200
+
201
+ def test_method_name
202
+ {'Foo' => nil,
203
+ 'Foo::Bar' => nil,
204
+ 'Foo::Bar#baz' => 'baz',
205
+ 'Foo::Bar.baz' => 'baz',
206
+ 'Foo::Bar::baz' => 'baz',
207
+ 'Foo::Bar::Baz' => nil}.each do |location, method_name|
208
+ assert_equal method_name, RDoc::CodeLocation.new(location).method_name
209
+ end
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,70 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require File.dirname(__FILE__) + '/test_helper'
3
+
4
+ class ACLOptionProcessorTest < Test::Unit::TestCase
5
+ def test_empty_options
6
+ options = {}
7
+ assert_nothing_raised do
8
+ process! options
9
+ end
10
+ assert_equal({}, options)
11
+ end
12
+
13
+ def test_invalid_access_level
14
+ options = {:access => :foo}
15
+ assert_raises(InvalidAccessControlLevel) do
16
+ process! options
17
+ end
18
+ end
19
+
20
+ def test_valid_access_level_is_normalized
21
+ valid_access_levels = [
22
+ {:access => :private},
23
+ {'access' => 'private'},
24
+ {:access => 'private'},
25
+ {'access' => :private},
26
+ {'x-oss-acl' => 'private'},
27
+ {:x_oss_acl => :private},
28
+ {:x_oss_acl => 'private'},
29
+ {'x_oss_acl' => :private}
30
+ ]
31
+
32
+ valid_access_levels.each do |options|
33
+ assert_nothing_raised do
34
+ process! options
35
+ end
36
+ assert_equal 'private', acl(options)
37
+ end
38
+
39
+ valid_hyphenated_access_levels = [
40
+ {:access => :public_read},
41
+ {'access' => 'public_read'},
42
+ {'access' => 'public-read'},
43
+ {:access => 'public_read'},
44
+ {:access => 'public-read'},
45
+ {'access' => :public_read},
46
+
47
+ {'x-oss-acl' => 'public_read'},
48
+ {:x_oss_acl => :public_read},
49
+ {:x_oss_acl => 'public_read'},
50
+ {:x_oss_acl => 'public-read'},
51
+ {'x_oss_acl' => :public_read}
52
+ ]
53
+
54
+ valid_hyphenated_access_levels.each do |options|
55
+ assert_nothing_raised do
56
+ process! options
57
+ end
58
+ assert_equal 'public-read', acl(options)
59
+ end
60
+ end
61
+
62
+ private
63
+ def process!(options)
64
+ ACL::OptionProcessor.process!(options)
65
+ end
66
+
67
+ def acl(options)
68
+ options['x-oss-acl']
69
+ end
70
+ end
@@ -0,0 +1,114 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require File.dirname(__FILE__) + '/test_helper'
3
+
4
+ class HeaderAuthenticationTest < Test::Unit::TestCase
5
+ def test_encoded_canonical
6
+ signature = Authentication::Signature.new(request, key_id, secret)
7
+ assert_equal AliyunDocExampleData::Example1.canonical_string, signature.send(:canonical_string)
8
+ assert_equal AliyunDocExampleData::Example1.signature, signature.send(:encoded_canonical)
9
+ end
10
+
11
+ def test_authorization_header
12
+ header = Authentication::Header.new(request, key_id, secret)
13
+ assert_equal AliyunDocExampleData::Example1.canonical_string, header.send(:canonical_string)
14
+ assert_equal AliyunDocExampleData::Example1.authorization_header, header
15
+ end
16
+
17
+ private
18
+ def request; AliyunDocExampleData::Example1.request end
19
+ def key_id ; AliyunDocExampleData::Example1.access_key_id end
20
+ def secret ; AliyunDocExampleData::Example1.secret_access_key end
21
+ end
22
+
23
+ class QueryStringAuthenticationTest < Test::Unit::TestCase
24
+ def test_query_string
25
+ query_string = Authentication::QueryString.new(request, key_id, secret, :expires_in => 60)
26
+ assert_equal AliyunDocExampleData::Example3.canonical_string, query_string.send(:canonical_string)
27
+ assert_equal AliyunDocExampleData::Example3.query_string, query_string
28
+ end
29
+
30
+ def test_query_string_with_explicit_expiry
31
+ query_string = Authentication::QueryString.new(request, key_id, secret, :expires => expires)
32
+ assert_equal expires, query_string.send(:canonical_string).instance_variable_get(:@options)[:expires]
33
+ assert_equal AliyunDocExampleData::Example3.query_string, query_string
34
+ end
35
+
36
+ def test_expires_in_is_coerced_to_being_an_integer_in_case_it_is_a_special_integer_proxy
37
+ # References bug: http://rubyforge.org/tracker/index.php?func=detail&aid=17458&group_id=2409&atid=9356
38
+ integer_proxy = Class.new do
39
+ attr_reader :integer
40
+ def initialize(integer)
41
+ @integer = integer
42
+ end
43
+
44
+ def to_int
45
+ integer
46
+ end
47
+ end
48
+
49
+ actual_integer = 25
50
+ query_string = Authentication::QueryString.new(request, key_id, secret, :expires_in => integer_proxy.new(actual_integer))
51
+ assert_equal actual_integer, query_string.send(:expires_in)
52
+ end
53
+
54
+ private
55
+ def request; AliyunDocExampleData::Example3.request end
56
+ def key_id ; AliyunDocExampleData::Example3.access_key_id end
57
+ def secret ; AliyunDocExampleData::Example3.secret_access_key end
58
+ def expires; AliyunDocExampleData::Example3.expires end
59
+ end
60
+
61
+ class CanonicalStringTest < Test::Unit::TestCase
62
+ def setup
63
+ @request = Net::HTTP::Post.new('/test')
64
+ @canonical_string = Authentication::CanonicalString.new(@request)
65
+ end
66
+
67
+ def test_path_does_not_include_query_string
68
+ request = Net::HTTP::Get.new('/test/query/string?foo=bar&baz=quux')
69
+ assert_equal '/test/query/string', Authentication::CanonicalString.new(request).send(:path)
70
+
71
+ # Make sure things still work when there is *no* query string
72
+ request = Net::HTTP::Get.new('/')
73
+ assert_equal '/', Authentication::CanonicalString.new(request).send(:path)
74
+ request = Net::HTTP::Get.new('/foo/bar')
75
+ assert_equal '/foo/bar', Authentication::CanonicalString.new(request).send(:path)
76
+ end
77
+
78
+ def test_path_includes_significant_query_strings
79
+ significant_query_strings = [
80
+ ['/test/query/string?acl', '/test/query/string?acl'],
81
+ ['/test/query/string?acl&foo=bar', '/test/query/string?acl'],
82
+ ['/test/query/string?foo=bar&acl', '/test/query/string?acl'],
83
+ ['/test/query/string?acl=foo', '/test/query/string?acl'],
84
+ ['/test/query/string?logging=foo', '/test/query/string?logging'],
85
+ ['/test/query/string?bar=baz&acl=foo', '/test/query/string?acl']
86
+ ]
87
+
88
+ significant_query_strings.each do |uncleaned_path, expected_cleaned_path|
89
+ assert_equal expected_cleaned_path, Authentication::CanonicalString.new(Net::HTTP::Get.new(uncleaned_path)).send(:path)
90
+ end
91
+ end
92
+
93
+ def test_default_headers_set
94
+ Authentication::CanonicalString.default_headers.each do |header|
95
+ assert @canonical_string.headers.include?(header)
96
+ end
97
+ end
98
+
99
+ def test_interesting_headers_are_copied_over
100
+ an_interesting_header = 'content-md5'
101
+ string_without_interesting_header = Authentication::CanonicalString.new(@request)
102
+ assert string_without_interesting_header.headers[an_interesting_header].empty?
103
+
104
+ # Add an interesting header
105
+ @request[an_interesting_header] = 'foo'
106
+ string_with_interesting_header = Authentication::CanonicalString.new(@request)
107
+ assert_equal 'foo', string_with_interesting_header.headers[an_interesting_header]
108
+ end
109
+
110
+ def test_canonical_string
111
+ request = AliyunDocExampleData::Example1.request
112
+ assert_equal AliyunDocExampleData::Example1.canonical_string, Authentication::CanonicalString.new(request)
113
+ end
114
+ end