sndacs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,3 @@
1
+ require "test/unit"
2
+ require "mocha"
3
+ require "s3"
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sndacs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - LI Daobing
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: proxies
16
+ requirement: &19459980 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *19459980
25
+ - !ruby/object:Gem::Dependency
26
+ name: test-unit
27
+ requirement: &19459020 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *19459020
36
+ - !ruby/object:Gem::Dependency
37
+ name: mocha
38
+ requirement: &19443300 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *19443300
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &19441820 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *19441820
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &19441060 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '2.0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *19441060
69
+ description: sndacs library provides access to SNDA Cloud Storage.
70
+ email:
71
+ - lidaobing@snda.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE
81
+ - README.rdoc
82
+ - Rakefile
83
+ - lib/sndacs.rb
84
+ - lib/sndacs/bucket.rb
85
+ - lib/sndacs/buckets_extension.rb
86
+ - lib/sndacs/connection.rb
87
+ - lib/sndacs/exceptions.rb
88
+ - lib/sndacs/object.rb
89
+ - lib/sndacs/objects_extension.rb
90
+ - lib/sndacs/parser.rb
91
+ - lib/sndacs/request.rb
92
+ - lib/sndacs/service.rb
93
+ - lib/sndacs/signature.rb
94
+ - lib/sndacs/version.rb
95
+ - sndacs.gemspec
96
+ - spec/sndacs/service_spec.rb
97
+ - spec/spec_helper.rb
98
+ - test/bucket_test.rb
99
+ - test/connection_test.rb
100
+ - test/object_test.rb
101
+ - test/service_test.rb
102
+ - test/signature_test.rb
103
+ - test/test_helper.rb
104
+ homepage: https://github.com/grandcloud/sndacs-ruby
105
+ licenses: []
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: 1.3.6
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 1.8.15
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Library for accessing SNDA Cloud Storage objects and buckets
128
+ test_files: []