scashin133-s3 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,218 @@
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://johnsmith.s3.amazonaws.com/photos/puppy.jpg?AWSAccessKeyId=0PN5J17HBGZHT7JJ3X82&Expires=1175046589&Signature=SDMxjIkOKIVR47nWfJ57UNPXxFM%3D"
203
+ assert_equal expected, actual
204
+ end
205
+ test "temporary url for object get over https" do
206
+ actual = S3::Signature.generate_temporary_url(
207
+ :bucket => "johnsmith",
208
+ :resource => "photos/puppy.jpg",
209
+ :access_key => '0PN5J17HBGZHT7JJ3X82',
210
+ :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
211
+ :expires_at => 1175046589,
212
+ :method => :get,
213
+ :use_ssl => true
214
+ )
215
+ expected = /https:\/\/johnsmith\.s3\.amazonaws\.com\/photos\/puppy\.jpg\?AWSAccessKeyId=0PN5J17HBGZHT7JJ3X82\&Expires=1175046589\&Signature=/
216
+ assert_match expected, actual
217
+ end
218
+ end
@@ -0,0 +1,3 @@
1
+ require "test/unit"
2
+ require "mocha"
3
+ require "s3"
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scashin133-s3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 3
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 8
10
+ version: 0.3.8
11
+ platform: ruby
12
+ authors:
13
+ - "Jakub Ku\xC5\xBAma"
14
+ - Sean Cashin
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-10-23 00:00:00 -07:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ requirement: *id001
33
+ name: proxies
34
+ prerelease: false
35
+ type: :runtime
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 2
45
+ - 0
46
+ version: "2.0"
47
+ requirement: *id002
48
+ name: test-unit
49
+ prerelease: false
50
+ type: :development
51
+ - !ruby/object:Gem::Dependency
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirement: *id003
62
+ name: mocha
63
+ prerelease: false
64
+ type: :development
65
+ - !ruby/object:Gem::Dependency
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 23
72
+ segments:
73
+ - 1
74
+ - 0
75
+ - 0
76
+ version: 1.0.0
77
+ requirement: *id004
78
+ name: bundler
79
+ prerelease: false
80
+ type: :development
81
+ description: "S3 library provides access to Amazon's Simple Storage Service. It supports both: European and US buckets through REST API."
82
+ email:
83
+ - qoobaa@gmail.com
84
+ - scashin133@gmail.com
85
+ executables: []
86
+
87
+ extensions: []
88
+
89
+ extra_rdoc_files: []
90
+
91
+ files:
92
+ - .gitignore
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE
96
+ - README.rdoc
97
+ - Rakefile
98
+ - extra/s3_attachment_fu.rb
99
+ - extra/s3_paperclip.rb
100
+ - lib/s3.rb
101
+ - lib/s3/bucket.rb
102
+ - lib/s3/buckets_extension.rb
103
+ - lib/s3/connection.rb
104
+ - lib/s3/exceptions.rb
105
+ - lib/s3/object.rb
106
+ - lib/s3/objects_extension.rb
107
+ - lib/s3/parser.rb
108
+ - lib/s3/request.rb
109
+ - lib/s3/service.rb
110
+ - lib/s3/signature.rb
111
+ - lib/s3/version.rb
112
+ - s3.gemspec
113
+ - test/bucket_test.rb
114
+ - test/connection_test.rb
115
+ - test/object_test.rb
116
+ - test/service_test.rb
117
+ - test/signature_test.rb
118
+ - test/test_helper.rb
119
+ has_rdoc: true
120
+ homepage: http://jah.pl/projects/s3.html
121
+ licenses: []
122
+
123
+ post_install_message:
124
+ rdoc_options: []
125
+
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ hash: 3
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ hash: 23
143
+ segments:
144
+ - 1
145
+ - 3
146
+ - 6
147
+ version: 1.3.6
148
+ requirements: []
149
+
150
+ rubyforge_project: scashin133-s3
151
+ rubygems_version: 1.3.7
152
+ signing_key:
153
+ specification_version: 3
154
+ summary: Library for accessing S3 objects and buckets
155
+ test_files: []
156
+