steamcannon-s3 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,111 @@
1
+ require "test_helper"
2
+
3
+ class ServiceTest < Test::Unit::TestCase
4
+ def setup
5
+ @buckets_list_body = <<-EOBuckets
6
+ <?xml version="1.0" encoding="UTF-8"?>\n<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Owner> <ID>123u1odhkhfoadf</ID> <DisplayName>JohnDoe</DisplayName> </Owner> <Buckets> <Bucket> <Name>data.example.com</Name> <CreationDate>2009-07-02T11:56:58.000Z</CreationDate> </Bucket> <Bucket> <Name>images</Name> <CreationDate>2009-06-05T12:26:33.000Z</CreationDate> </Bucket> </Buckets> </ListAllMyBucketsResult>
7
+ EOBuckets
8
+
9
+ @bucket_not_exists = <<-EOBucketNoexists
10
+ <?xml version="1.0" encoding="UTF-8"?>\n<Error> <Code>NoSuchBucket</Code> <Message>The specified bucket does not exists</Message> <BucketName>data2.example.com</BucketName> <RequestId>8D7519AAE74E9E99</RequestId> <HostId>DvKnnNSMnPHd1oXukyRaFNv8Lg/bpwhuUtY8Kj7eDLbaIrIT8JebSnHwi89AK1P+</HostId> </Error>
11
+ EOBucketNoexists
12
+
13
+ @bucket_exists = <<-EOBucketexists
14
+ <?xml version="1.0" encoding="UTF-8"?>\n<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Name>data.synergypeople.net</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> </ListBucketResult>
15
+ EOBucketexists
16
+
17
+ @service_empty_buckets_list = S3::Service.new(
18
+ :access_key_id => "12345678901234567890",
19
+ :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
20
+ )
21
+ @response_empty_buckets_list = Net::HTTPOK.new("1.1", "200", "OK")
22
+ @service_empty_buckets_list.stubs(:service_request).returns(@response_empty_buckets_list)
23
+ @response_empty_buckets_list.stubs(:body).returns(@buckets_empty_list_body)
24
+
25
+ @service_buckets_list = S3::Service.new(
26
+ :access_key_id => "12345678901234567890",
27
+ :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
28
+ )
29
+ @response_buckets_list = Net::HTTPOK.new("1.1", "200", "OK")
30
+ @service_buckets_list.stubs(:service_request).returns(@response_buckets_list)
31
+ @response_buckets_list.stubs(:body).returns(@buckets_list_body)
32
+
33
+ @service_bucket_exists = S3::Service.new(
34
+ :access_key_id => "12345678901234567890",
35
+ :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
36
+ )
37
+ @response_bucket_exists = Net::HTTPNotFound.new("1.1", "200", "OK")
38
+ @service_bucket_exists.stubs(:service_request).returns(@response_bucket_exists)
39
+ @response_bucket_exists.stubs(:body).returns(@bucket_exists)
40
+
41
+ @service_bucket_not_exists = S3::Service.new(
42
+ :access_key_id => "12345678901234567890",
43
+ :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
44
+ )
45
+ @response_bucket_not_exists = Net::HTTPNotFound.new("1.1", "404", "Not Found")
46
+ @service_bucket_not_exists.stubs(:service_request).raises(S3::Error::NoSuchBucket.new(404, @response_bucket_not_exists))
47
+ @response_bucket_not_exists.stubs(:body).returns(@bucket_not_exists)
48
+
49
+ @buckets_empty_list = []
50
+ @buckets_empty_list_body = <<-EOEmptyBuckets
51
+ <?xml version="1.0" encoding="UTF-8"?>\n<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Owner> <ID>123u1odhkhfoadf</ID> <DisplayName>JohnDoe</DisplayName> </Owner> <Buckets> </Buckets> </ListAllMyBucketsResult>
52
+ EOEmptyBuckets
53
+
54
+ @buckets_list = [
55
+ S3::Bucket.send(:new, @service_buckets_list, "data.example.com"),
56
+ S3::Bucket.send(:new, @service_buckets_list, "images")
57
+ ]
58
+ end
59
+
60
+ test "buckets and parse buckets empty" do
61
+ expected = @buckets_empty_list
62
+ actual = @service_empty_buckets_list.buckets
63
+ assert_equal expected.length, actual.length
64
+ assert_equal expected, actual
65
+ end
66
+
67
+ test "buckets and parse buckets" do
68
+ expected = @buckets_list
69
+ # ugly hack
70
+ actual = @service_buckets_list.buckets.map { |obj| obj }
71
+ assert_equal expected, actual
72
+ end
73
+
74
+ test "buckets build" do
75
+ @service_empty_buckets_list.stubs(:service_request)
76
+
77
+ expected = "bucket_name"
78
+ actual = @service_empty_buckets_list.buckets.build("bucket_name")
79
+ assert_kind_of S3::Bucket, actual
80
+ assert_equal expected, actual.name
81
+ end
82
+
83
+ test "buckets find first" do
84
+ assert_nothing_raised do
85
+ actual = @service_buckets_list.buckets.find_first("data.example.com")
86
+ assert_equal "data.example.com", actual.name
87
+ end
88
+ end
89
+
90
+ test "buckets find first fail" do
91
+ assert_raise S3::Error::NoSuchBucket do
92
+ @service_bucket_not_exists.buckets.find_first("data2.example.com")
93
+ end
94
+ end
95
+
96
+ test "buckets find all on empty list" do
97
+ assert_nothing_raised do
98
+ expected = @buckets_empty_list
99
+ actual = @service_empty_buckets_list.buckets.find_all
100
+ assert_equal expected, actual
101
+ end
102
+ end
103
+
104
+ test "buckets find all" do
105
+ assert_nothing_raised do
106
+ expected = @buckets_list
107
+ actual = @service_buckets_list.buckets.find_all
108
+ assert_equal expected, actual
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,205 @@
1
+ require "test_helper"
2
+
3
+ class SignatureTest < Test::Unit::TestCase
4
+ # from http://docs.amazonwebservices.com/AmazonS3/latest/RESTAuthentication.html
5
+ test "signature for object get" do
6
+ request = Net::HTTP::Get.new("/photos/puppy.jpg")
7
+ request["host"] = "johnsmith.s3.amazonaws.com"
8
+ request["date"] = "Tue, 27 Mar 2007 19:36:42 +0000"
9
+
10
+ actual = S3::Signature.generate(
11
+ :host => request["host"],
12
+ :request => request,
13
+ :access_key_id => "0PN5J17HBGZHT7JJ3X82",
14
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
15
+ )
16
+ expected = "AWS 0PN5J17HBGZHT7JJ3X82:xXjDGYUmKxnwqr5KXNPGldn5LbA="
17
+ assert_equal expected, actual
18
+ end
19
+
20
+ test "signature for object put" do
21
+ request = Net::HTTP::Put.new("/photos/puppy.jpg");
22
+ request["content-type"] = "image/jpeg"
23
+ request["content-length"] = "94328"
24
+ request["host"] = "johnsmith.s3.amazonaws.com"
25
+ request["date"] = "Tue, 27 Mar 2007 21:15:45 +0000"
26
+
27
+ actual = S3::Signature.generate(
28
+ :host => request["host"],
29
+ :request => request,
30
+ :access_key_id => "0PN5J17HBGZHT7JJ3X82",
31
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
32
+ )
33
+ expected = "AWS 0PN5J17HBGZHT7JJ3X82:hcicpDDvL9SsO6AkvxqmIWkmOuQ="
34
+ assert_equal expected, actual
35
+ end
36
+
37
+ test "signature for list" do
38
+ request = Net::HTTP::Get.new("/?prefix=photos&max-keys=50&marker=puppy");
39
+ request["user-agent"] = "Mozilla/5.0"
40
+ request["host"] = "johnsmith.s3.amazonaws.com"
41
+ request["date"] = "Tue, 27 Mar 2007 19:42:41 +0000"
42
+
43
+ actual = S3::Signature.generate(
44
+ :host => request["host"],
45
+ :request => request,
46
+ :access_key_id => "0PN5J17HBGZHT7JJ3X82",
47
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
48
+ )
49
+ expected = "AWS 0PN5J17HBGZHT7JJ3X82:jsRt/rhG+Vtp88HrYL706QhE4w4="
50
+ assert_equal expected, actual
51
+ end
52
+
53
+ test "signature for fetch" do
54
+ request = Net::HTTP::Get.new("/?acl");
55
+ request["host"] = "johnsmith.s3.amazonaws.com"
56
+ request["date"] = "Tue, 27 Mar 2007 19:44:46 +0000"
57
+
58
+ actual = S3::Signature.generate(
59
+ :host => request["host"],
60
+ :request => request,
61
+ :access_key_id => "0PN5J17HBGZHT7JJ3X82",
62
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
63
+ )
64
+ expected = "AWS 0PN5J17HBGZHT7JJ3X82:thdUi9VAkzhkniLj96JIrOPGi0g="
65
+ assert_equal expected, actual
66
+ end
67
+
68
+ test "signature for delete" do
69
+ request = Net::HTTP::Delete.new("/johnsmith/photos/puppy.jpg");
70
+ request["user-agent"] = "dotnet"
71
+ request["host"] = "s3.amazonaws.com"
72
+ request["date"] = "Tue, 27 Mar 2007 21:20:27 +0000"
73
+ request["x-amz-date"] = "Tue, 27 Mar 2007 21:20:26 +0000"
74
+
75
+ actual = S3::Signature.generate(
76
+ :host => request["host"],
77
+ :request => request,
78
+ :access_key_id => "0PN5J17HBGZHT7JJ3X82",
79
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
80
+ )
81
+ expected = "AWS 0PN5J17HBGZHT7JJ3X82:k3nL7gH3+PadhTEVn5Ip83xlYzk="
82
+ assert_equal expected, actual
83
+ end
84
+
85
+ test "signature for upload" do
86
+ request = Net::HTTP::Put.new("/db-backup.dat.gz");
87
+ request["user-agent"] = "curl/7.15.5"
88
+ request["host"] = "static.johnsmith.net:8080"
89
+ request["date"] = "Tue, 27 Mar 2007 21:06:08 +0000"
90
+ request["x-amz-acl"] = "public-read"
91
+ request["content-type"] = "application/x-download"
92
+ request["content-md5"] = "4gJE4saaMU4BqNR0kLY+lw=="
93
+ # FIXME: Net::HTTP doesn't allow to have multiple headers with the same name
94
+ # request.add_field add additional spaces (breaks signature)
95
+ #request["x-amz-meta-reviewedby"] = "joe@johnsmith.net"
96
+ #request["x-amz-meta-reviewedby"] = "jane@johnsmith.net"
97
+ request["x-amz-meta-reviewedby"] = "joe@johnsmith.net,jane@johnsmith.net"
98
+ request["x-amz-meta-filechecksum"] = "0x02661779"
99
+ request["x-amz-meta-checksumalgorithm"] = "crc32"
100
+ request["content-disposition"] = "attachment; filename=database.dat"
101
+ request["content-encoding"] = "gzip"
102
+ request["content-length"] = "5913339"
103
+
104
+ actual = S3::Signature.generate(
105
+ :host => "static.johnsmith.net",
106
+ :request => request,
107
+ :access_key_id => "0PN5J17HBGZHT7JJ3X82",
108
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
109
+ )
110
+ expected = "AWS 0PN5J17HBGZHT7JJ3X82:C0FlOtU8Ylb9KDTpZqYkZPX91iI="
111
+ assert_equal expected, actual
112
+ end
113
+
114
+ test "signature for list all my buckets" do
115
+ request = Net::HTTP::Get.new("/");
116
+ request["host"] = "s3.amazonaws.com"
117
+ request["date"] = "Wed, 28 Mar 2007 01:29:59 +0000"
118
+
119
+ actual = S3::Signature.generate(
120
+ :host => request["host"],
121
+ :request => request,
122
+ :access_key_id => "0PN5J17HBGZHT7JJ3X82",
123
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
124
+ )
125
+ expected = "AWS 0PN5J17HBGZHT7JJ3X82:Db+gepJSUbZKwpx1FR0DLtEYoZA="
126
+ assert_equal expected, actual
127
+ end
128
+
129
+ test "signature for unicode keys" do
130
+ request = Net::HTTP::Get.new("/dictionary/fran%C3%A7ais/pr%c3%a9f%c3%a8re");
131
+ request["host"] = "s3.amazonaws.com"
132
+ request["date"] = "Wed, 28 Mar 2007 01:49:49 +0000"
133
+
134
+ actual = S3::Signature.generate(
135
+ :host => request["host"],
136
+ :request => request,
137
+ :access_key_id => "0PN5J17HBGZHT7JJ3X82",
138
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
139
+ )
140
+ expected = "AWS 0PN5J17HBGZHT7JJ3X82:dxhSBHoI6eVSPcXJqEghlUzZMnY="
141
+ assert_equal expected, actual
142
+ end
143
+
144
+ test "temporary signature for object get" do
145
+ actual = S3::Signature.generate_temporary_url_signature(
146
+ :bucket => "johnsmith",
147
+ :resource => "photos/puppy.jpg",
148
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
149
+ :expires_at => 1175046589
150
+ )
151
+ expected = "gs6xNznrLJ4Bd%2B1y9pcy2HOSVeg%3D"
152
+ assert_equal expected, actual
153
+ end
154
+
155
+ test "temporary signature for object post" do
156
+ actual = S3::Signature.generate_temporary_url_signature(
157
+ :bucket => "johnsmith",
158
+ :resource => "photos/puppy.jpg",
159
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
160
+ :expires_at => 1175046589,
161
+ :method => :post
162
+ )
163
+ expected = "duIzwO2KTEMIlbSYbFFS86Wj0LI%3D"
164
+ assert_equal expected, actual
165
+ end
166
+
167
+ test "temporary signature for object put with headers" do
168
+ actual = S3::Signature.generate_temporary_url_signature(
169
+ :bucket => "johnsmith",
170
+ :resource => "photos/puppy.jpg",
171
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
172
+ :expires_at => 1175046589,
173
+ :method => :put,
174
+ :headers => {'x-amz-acl' => 'public-read'}
175
+ )
176
+ expected = "SDMxjIkOKIVR47nWfJ57UNPXxFM%3D"
177
+ assert_equal expected, actual
178
+ end
179
+
180
+ test "temporary signature for object delete" do
181
+ actual = S3::Signature.generate_temporary_url_signature(
182
+ :bucket => "johnsmith",
183
+ :resource => "photos/puppy.jpg",
184
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
185
+ :expires_at => 1175046589,
186
+ :method => :delete
187
+ )
188
+ expected = "5Vg7A4HxgS6tVCYzBx%2BkMR8sztY%3D"
189
+ assert_equal expected, actual
190
+ end
191
+
192
+ test "temporary url for object put with headers" do
193
+ actual = S3::Signature.generate_temporary_url(
194
+ :bucket => "johnsmith",
195
+ :resource => "photos/puppy.jpg",
196
+ :access_key => '0PN5J17HBGZHT7JJ3X82',
197
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
198
+ :expires_at => 1175046589,
199
+ :method => :put,
200
+ :headers => {'x-amz-acl' => 'public-read'}
201
+ )
202
+ expected = "http://s3.amazonaws.com/johnsmith/photos/puppy.jpg?AWSAccessKeyId=0PN5J17HBGZHT7JJ3X82&Expires=1175046589&Signature=SDMxjIkOKIVR47nWfJ57UNPXxFM%3D"
203
+ assert_equal expected, actual
204
+ end
205
+ end
@@ -0,0 +1,6 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ Bundler.require
5
+ require "test/unit"
6
+ require "mocha"
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steamcannon-s3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 2
10
+ version: 0.3.2
11
+ platform: ruby
12
+ authors:
13
+ - "Jakub Ku\xC5\xBAma"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-23 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: trollop
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: proxies
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: test-unit
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 2
60
+ - 0
61
+ version: "2.0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: mocha
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 23
87
+ segments:
88
+ - 1
89
+ - 0
90
+ - 0
91
+ version: 1.0.0
92
+ type: :development
93
+ version_requirements: *id005
94
+ description: "S3 library provides access to Amazon's Simple Storage Service. It supports both: European and US buckets through REST API."
95
+ email:
96
+ - qoobaa@gmail.com
97
+ executables:
98
+ - s3
99
+ extensions: []
100
+
101
+ extra_rdoc_files: []
102
+
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - LICENSE
108
+ - README.rdoc
109
+ - Rakefile
110
+ - bin/s3
111
+ - extra/s3_attachment_fu.rb
112
+ - extra/s3_paperclip.rb
113
+ - lib/s3.rb
114
+ - lib/s3/bucket.rb
115
+ - lib/s3/buckets_extension.rb
116
+ - lib/s3/connection.rb
117
+ - lib/s3/exceptions.rb
118
+ - lib/s3/object.rb
119
+ - lib/s3/objects_extension.rb
120
+ - lib/s3/parser.rb
121
+ - lib/s3/service.rb
122
+ - lib/s3/signature.rb
123
+ - lib/s3/version.rb
124
+ - s3.gemspec
125
+ - test/bucket_test.rb
126
+ - test/connection_test.rb
127
+ - test/object_test.rb
128
+ - test/service_test.rb
129
+ - test/signature_test.rb
130
+ - test/test_helper.rb
131
+ has_rdoc: true
132
+ homepage: http://jah.pl/projects/s3.html
133
+ licenses: []
134
+
135
+ post_install_message:
136
+ rdoc_options: []
137
+
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 23
155
+ segments:
156
+ - 1
157
+ - 3
158
+ - 6
159
+ version: 1.3.6
160
+ requirements: []
161
+
162
+ rubyforge_project: s3
163
+ rubygems_version: 1.3.7
164
+ signing_key:
165
+ specification_version: 3
166
+ summary: Library for accessing S3 objects and buckets, with command line tool
167
+ test_files: []
168
+