s3lib 0.1.0
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.
- data/Rakefile +24 -0
- data/VERSION.yml +5 -0
- data/bin/s3lib +15 -0
- data/bin/s3sh_as +15 -0
- data/github-test.rb +22 -0
- data/lib/acl.rb +134 -0
- data/lib/acl_access.rb +20 -0
- data/lib/acl_creating_a_grant_recipe.rb +95 -0
- data/lib/acl_reading_acl_recipe.rb +59 -0
- data/lib/acl_refreshing_cached_grants_recipe.rb +54 -0
- data/lib/bucket.rb +116 -0
- data/lib/bucket_before_refactoring.rb +120 -0
- data/lib/bucket_create.rb +39 -0
- data/lib/bucket_find.rb +41 -0
- data/lib/bucket_with_acl_mixin.rb +103 -0
- data/lib/error_handling.rb +12 -0
- data/lib/grant.rb +107 -0
- data/lib/grant_creating_a_grant_recipe.rb +103 -0
- data/lib/grant_reading_acl_recipe.rb +51 -0
- data/lib/object.rb +144 -0
- data/lib/object_from_bucket_test.rb +18 -0
- data/lib/object_take1.rb +150 -0
- data/lib/object_with_acl_mixin.rb +131 -0
- data/lib/put_with_curl_test.rb +39 -0
- data/lib/s3_authenticator.rb +155 -0
- data/lib/s3_authenticator_dev.rb +117 -0
- data/lib/s3_authenticator_dev_private.rb +40 -0
- data/lib/s3_errors.rb +58 -0
- data/lib/s3lib.rb +10 -0
- data/lib/s3lib_with_mixin.rb +11 -0
- data/lib/service.rb +24 -0
- data/lib/service_dev.rb +36 -0
- data/s3lib.gemspec +74 -0
- data/sample_usage.rb +45 -0
- data/test/acl_test.rb +89 -0
- data/test/amazon_headers_test.rb +87 -0
- data/test/canonical_resource_test.rb +53 -0
- data/test/canonical_string_tests.rb +73 -0
- data/test/first_test.rb +34 -0
- data/test/first_test_private.rb +55 -0
- data/test/full_test.rb +84 -0
- data/test/s3_authenticator_test.rb +291 -0
- metadata +109 -0
data/test/full_test.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/s3_authenticator')
|
3
|
+
|
4
|
+
class S3AuthenticatorTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
# The id and secret key are non-working credentials from the S3 Developer's Guide
|
8
|
+
# See http://developer.amazonwebservices.com/connect/entry.jspa?externalID=123&categoryID=48
|
9
|
+
ENV['AMAZON_ACCESS_KEY_ID'] = '0PN6J17HBGXHT7JJ3X82'
|
10
|
+
ENV['AMAZON_SECRET_ACCESS_KEY'] = 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o'
|
11
|
+
@s3_test = S3Lib::AuthenticatedRequest.new
|
12
|
+
end
|
13
|
+
|
14
|
+
# See http://developer.amazonwebservices.com/connect/entry.jspa?externalID=123&categoryID=48
|
15
|
+
def test_dg_sample_one
|
16
|
+
@s3_test.make_authenticated_request(:get, '/photos/puppy.jpg', {'Host' => 'johnsmith.s3.amazonaws.com',
|
17
|
+
'Date' => 'Tue, 27 Mar 2007 19:36:42 +0000'})
|
18
|
+
expected_canonical_string = "GET\n\n\nTue, 27 Mar 2007 19:36:42 +0000\n/johnsmith/photos/puppy.jpg"
|
19
|
+
assert_equal expected_canonical_string, @s3_test.canonical_string
|
20
|
+
assert_equal "AWS 0PN6J17HBGXHT7JJ3X82:xXjDGYUmKxnwqr5KXNPGldn5LbA=", @s3_test.authorization_string
|
21
|
+
end
|
22
|
+
|
23
|
+
# See http://developer.amazonwebservices.com/connect/entry.jspa?externalID=123&categoryID=48
|
24
|
+
def test_dg_sample_two
|
25
|
+
@s3_test.make_authenticated_request(:put, '/photos/puppy.jpg', {'Content-Type' => 'image/jpeg',
|
26
|
+
'Content-Length' => '94328',
|
27
|
+
'Host' => 'johnsmith.s3.amazonaws.com',
|
28
|
+
'Date' => 'Tue, 27 Mar 2007 21:15:45 +0000'})
|
29
|
+
expected_canonical_string = "PUT\n\nimage/jpeg\nTue, 27 Mar 2007 21:15:45 +0000\n/johnsmith/photos/puppy.jpg"
|
30
|
+
assert_equal expected_canonical_string, @s3_test.canonical_string
|
31
|
+
assert_equal "AWS 0PN6J17HBGXHT7JJ3X82:hcicpDDvL9SsO6AkvxqmIWkmOuQ=", @s3_test.authorization_string
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_dg_sample_three
|
35
|
+
@s3_test.make_authenticated_request(:get, '', {'prefix' => 'photos',
|
36
|
+
'max-keys' => '50',
|
37
|
+
'marker' => 'puppy',
|
38
|
+
'host' => 'johnsmith.s3.amazonaws.com',
|
39
|
+
'date' => 'Tue, 27 Mar 2007 19:42:41 +0000'})
|
40
|
+
assert_equal "GET\n\n\nTue, 27 Mar 2007 19:42:41 +0000\n/johnsmith/", @s3_test.canonical_string
|
41
|
+
assert_equal 'AWS 0PN6J17HBGXHT7JJ3X82:jsRt/rhG+Vtp88HrYL706QhE4w4=', @s3_test.authorization_string
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_dg_sample_four
|
45
|
+
@s3_test.make_authenticated_request(:get, '?acl', {'host' => 'johnsmith.s3.amazonaws.com',
|
46
|
+
'date' => 'Tue, 27 Mar 2007 19:44:46 +0000'})
|
47
|
+
|
48
|
+
assert_equal "GET\n\n\nTue, 27 Mar 2007 19:44:46 +0000\n/johnsmith/?acl", @s3_test.canonical_string
|
49
|
+
assert_equal 'AWS 0PN6J17HBGXHT7JJ3X82:thdUi9VAkzhkniLj96JIrOPGi0g=', @s3_test.authorization_string
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_dg_sample_five
|
54
|
+
@s3_test.make_authenticated_request(:delete, '/johnsmith/photos/puppy.jpg',
|
55
|
+
{'User-Agent' => 'dotnet',
|
56
|
+
'host' => 's3.amazonaws.com',
|
57
|
+
'date' => 'Tue, 27 Mar 2007 21:20:27 +0000',
|
58
|
+
'x-amz-date' => 'Tue, 27 Mar 2007 21:20:26 +0000' })
|
59
|
+
assert_equal "DELETE\n\n\n\nx-amz-date:Tue, 27 Mar 2007 21:20:26 +0000\n/johnsmith/photos/puppy.jpg", @s3_test.canonical_string
|
60
|
+
assert_equal 'AWS 0PN6J17HBGXHT7JJ3X82:k3nL7gH3+PadhTEVn5Ip83xlYzk=', @s3_test.authorization_string
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_dg_sample_six
|
64
|
+
@s3_test.make_authenticated_request(:put, '/db-backup.dat.gz',
|
65
|
+
{'User-Agent' => 'curl/7.15.5',
|
66
|
+
'host' => 'static.johnsmith.net:8080',
|
67
|
+
'date' => 'Tue, 27 Mar 2007 21:06:08 +0000',
|
68
|
+
'x-amz-acl' => 'public-read',
|
69
|
+
'content-type' => 'application/x-download',
|
70
|
+
'Content-MD5' => '4gJE4saaMU4BqNR0kLY+lw==',
|
71
|
+
'X-Amz-Meta-ReviewedBy' => ['joe@johnsmith.net', 'jane@johnsmith.net'],
|
72
|
+
'X-Amz-Meta-FileChecksum' => '0x02661779',
|
73
|
+
'X-Amz-Meta-ChecksumAlgorithm' => 'crc32',
|
74
|
+
'Content-Disposition' => 'attachment; filename=database.dat',
|
75
|
+
'Content-Encoding' => 'gzip',
|
76
|
+
'Content-Length' => '5913339' })
|
77
|
+
expected_canonical_string = "PUT\n4gJE4saaMU4BqNR0kLY+lw==\napplication/x-download\nTue, 27 Mar 2007 21:06:08 +0000\n" +
|
78
|
+
"x-amz-acl:public-read\nx-amz-meta-checksumalgorithm:crc32\nx-amz-meta-filechecksum:0x02661779\n" +
|
79
|
+
"x-amz-meta-reviewedby:joe@johnsmith.net,jane@johnsmith.net\n/static.johnsmith.net/db-backup.dat.gz"
|
80
|
+
assert_equal expected_canonical_string, @s3_test.canonical_string
|
81
|
+
assert_equal 'AWS 0PN6J17HBGXHT7JJ3X82:C0FlOtU8Ylb9KDTpZqYkZPX91iI=', @s3_test.authorization_string
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,291 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/s3_authenticator')
|
3
|
+
|
4
|
+
# Make private methods and attributes public so that you can test them
|
5
|
+
module S3Lib
|
6
|
+
class AuthenticatedRequest
|
7
|
+
|
8
|
+
@@test_mode = false
|
9
|
+
|
10
|
+
attr_reader :bucket, :headers
|
11
|
+
|
12
|
+
def initialize()
|
13
|
+
end
|
14
|
+
|
15
|
+
def public_canonicalized_resource
|
16
|
+
canonicalized_resource
|
17
|
+
end
|
18
|
+
|
19
|
+
def public_canonicalized_headers
|
20
|
+
canonicalized_headers
|
21
|
+
end
|
22
|
+
|
23
|
+
def public_canonicalized_positional_headers
|
24
|
+
canonicalized_positional_headers
|
25
|
+
end
|
26
|
+
|
27
|
+
def public_canonicalized_amazon_headers
|
28
|
+
canonicalized_amazon_headers
|
29
|
+
end
|
30
|
+
|
31
|
+
def public_canonical_string
|
32
|
+
canonical_string
|
33
|
+
end
|
34
|
+
|
35
|
+
def public_authorization_string
|
36
|
+
authorization_string
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.test_mode
|
40
|
+
@@test_mode = true
|
41
|
+
end
|
42
|
+
|
43
|
+
def make_authenticated_request(verb, request_path, headers = {})
|
44
|
+
@verb = verb
|
45
|
+
@request_path = request_path.gsub(/^\//,'') # Strip off the leading '/'
|
46
|
+
|
47
|
+
@amazon_id = ENV['AMAZON_ACCESS_KEY_ID']
|
48
|
+
@amazon_secret = ENV['AMAZON_SECRET_ACCESS_KEY']
|
49
|
+
|
50
|
+
@headers = headers.downcase_keys.join_values
|
51
|
+
get_bucket_list_params
|
52
|
+
get_bucket_name
|
53
|
+
fix_date
|
54
|
+
|
55
|
+
if @@test_mode
|
56
|
+
test_open(uri_with_bucket_list_params, @headers.merge(:method => @verb, 'Authorization' => authorization_string))
|
57
|
+
else
|
58
|
+
req = open(uri_with_bucket_list_params, @headers.merge(:method => @verb, 'Authorization' => authorization_string))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Over-ride RestOpenURI#open
|
63
|
+
def test_open(uri, headers)
|
64
|
+
{:uri => uri, :headers => headers}
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
class S3AuthenticatorTest < Test::Unit::TestCase
|
72
|
+
|
73
|
+
def setup
|
74
|
+
# The id and secret key are non-working credentials from the S3 Developer's Guide
|
75
|
+
# See http://developer.amazonwebservices.com/connect/entry.jspa?externalID=123&categoryID=48
|
76
|
+
ENV['AMAZON_ACCESS_KEY_ID'] = '0PN6J17HBGXHT7JJ3X82'
|
77
|
+
ENV['AMAZON_SECRET_ACCESS_KEY'] = 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o'
|
78
|
+
S3Lib::AuthenticatedRequest.test_mode
|
79
|
+
@s3_test = S3Lib::AuthenticatedRequest.new
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_http_verb_is_uppercase
|
84
|
+
@s3_test.make_authenticated_request(:get, '/', {'host' => 's3.amazonaws.com'})
|
85
|
+
assert_match /^GET\n/, @s3_test.canonical_string
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_bucket_name_is_correct_with_virtual_hosting
|
89
|
+
@s3_test.make_authenticated_request(:get, '/', {'host' => 'some_bucket.s3.amazonaws.com'})
|
90
|
+
assert_equal 'some_bucket/', @s3_test.bucket
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_bucket_name_is_correct_with_cname_virtual_hosting
|
94
|
+
@s3_test.make_authenticated_request(:get, '/', {'host' => 'some_bucket.example.com'})
|
95
|
+
assert_equal 'some_bucket.example.com/', @s3_test.bucket
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_bucket_name_is_lowercase_with_virtual_hosting
|
99
|
+
@s3_test.make_authenticated_request(:get, '/', {'host' => 'Some_Bucket.s3.amazonaws.com'})
|
100
|
+
assert_equal 'some_bucket/', @s3_test.bucket
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_bucket_name_is_lowercase_with_cname_virtual_hosting
|
104
|
+
@s3_test.make_authenticated_request(:get, '/', {'host' => 'Some_Bucket.example.com'})
|
105
|
+
assert_equal 'some_bucket.example.com/', @s3_test.bucket
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_forward_slash_is_always_added
|
109
|
+
@s3_test.make_authenticated_request(:get, '')
|
110
|
+
assert_match /^\//, @s3_test.public_canonicalized_resource
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_positional_headers_with_all_headers
|
114
|
+
@s3_test.make_authenticated_request(:get, '', {'content-type' => 'some crazy content type',
|
115
|
+
'date' => 'December 25th, 2007',
|
116
|
+
'content-md5' => 'whee'})
|
117
|
+
assert_equal "whee\nsome crazy content type\nDecember 25th, 2007\n", @s3_test.public_canonicalized_positional_headers
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_positional_headers_with_only_date_header
|
121
|
+
@s3_test.make_authenticated_request(:get, '', {'date' => 'December 25th, 2007'})
|
122
|
+
assert_equal "\n\nDecember 25th, 2007\n", @s3_test.public_canonicalized_positional_headers
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_positional_headers_with_no_headers_should_have_date_defined
|
126
|
+
@s3_test.make_authenticated_request(:get, '' )
|
127
|
+
date = @s3_test.headers['date']
|
128
|
+
assert_equal "\n\n#{date}\n", @s3_test.public_canonicalized_positional_headers
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_amazon_headers_should_remove_non_amazon_headers
|
132
|
+
@s3_test.make_authenticated_request(:get, '', {'content-type' => 'content',
|
133
|
+
'some-other-header' => 'other',
|
134
|
+
'x-amz-meta-one' => 'one',
|
135
|
+
'x-amz-meta-two' => 'two'})
|
136
|
+
headers = @s3_test.public_canonicalized_amazon_headers
|
137
|
+
assert_no_match /other/, headers
|
138
|
+
assert_no_match /content/, headers
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_amazon_headers_should_keep_amazon_headers
|
142
|
+
@s3_test.make_authenticated_request(:get, '', {'content-type' => 'content',
|
143
|
+
'some-other-header' => 'other',
|
144
|
+
'x-amz-meta-one' => 'one',
|
145
|
+
'x-amz-meta-two' => 'two'})
|
146
|
+
headers = @s3_test.public_canonicalized_amazon_headers
|
147
|
+
assert_match /x-amz-meta-one/, headers
|
148
|
+
assert_match /x-amz-meta-two/, headers
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_amazon_headers_should_be_lowercase
|
152
|
+
@s3_test.make_authenticated_request(:get, '', {'content-type' => 'content',
|
153
|
+
'some-other-header' => 'other',
|
154
|
+
'X-amz-meta-one' => 'one',
|
155
|
+
'x-Amz-meta-two' => 'two'})
|
156
|
+
headers = @s3_test.public_canonicalized_amazon_headers
|
157
|
+
assert_match /x-amz-meta-one/, headers
|
158
|
+
assert_match /x-amz-meta-two/, headers
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_amazon_headers_should_be_alphabetized
|
162
|
+
@s3_test.make_authenticated_request(:get, '', {'content-type' => 'content',
|
163
|
+
'some-other-header' => 'other',
|
164
|
+
'X-amz-meta-one' => 'one',
|
165
|
+
'x-Amz-meta-two' => 'two',
|
166
|
+
'x-amz-meta-zed' => 'zed',
|
167
|
+
'x-amz-meta-alpha' => 'alpha'})
|
168
|
+
headers = @s3_test.public_canonicalized_amazon_headers
|
169
|
+
assert_match /alpha.*one.*two.*zed/m, headers # /m on the reg-exp makes .* include newlines
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_xamzdate_should_override_date_header
|
173
|
+
@s3_test.make_authenticated_request(:get, '', {'date' => 'December 15, 2005', 'x-amz-date' => 'Tue, 27 Mar 2007 21:20:26 +0000'})
|
174
|
+
headers = @s3_test.public_canonicalized_headers
|
175
|
+
assert_match /2007/, headers
|
176
|
+
assert_no_match /2005/, headers
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_xamzdate_should_override_capitalized_date_header
|
180
|
+
@s3_test.make_authenticated_request(:get, '', {'date' => 'December 15, 2005', 'X-amz-date' => 'Tue, 27 Mar 2007 21:20:26 +0000'})
|
181
|
+
headers = @s3_test.public_canonicalized_headers
|
182
|
+
assert_match /2007/, headers
|
183
|
+
assert_no_match /2005/, headers
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_leading_spaces_get_stripped_from_header_values
|
187
|
+
@s3_test.make_authenticated_request(:get, '', {'x-amz-meta-one' => ' one with a leading space',
|
188
|
+
'x-Amz-meta-two' => ' two with a leading and trailing space '})
|
189
|
+
headers = @s3_test.public_canonicalized_amazon_headers
|
190
|
+
assert_match /x-amz-meta-one:one with a leading space/, headers
|
191
|
+
assert_match /x-amz-meta-two:two with a leading and trailing space /, headers
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_values_as_arrays_should_be_joined_as_commas
|
195
|
+
@s3_test.make_authenticated_request(:get, '', {'x-amz-mult' => ['a', 'b', 'c']})
|
196
|
+
|
197
|
+
headers = @s3_test.public_canonicalized_amazon_headers
|
198
|
+
assert_match /a,b,c/, headers
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_date_should_be_added_if_not_passed_in
|
202
|
+
@s3_test.make_authenticated_request(:get, '')
|
203
|
+
assert @s3_test.headers.has_key?('date')
|
204
|
+
end
|
205
|
+
|
206
|
+
# See http://developer.amazonwebservices.com/connect/entry.jspa?externalID=123&categoryID=48
|
207
|
+
def test_dg_sample_one
|
208
|
+
@s3_test.make_authenticated_request(:get, '/photos/puppy.jpg', {'Host' => 'johnsmith.s3.amazonaws.com',
|
209
|
+
'Date' => 'Tue, 27 Mar 2007 19:36:42 +0000'})
|
210
|
+
assert_equal 'johnsmith/', @s3_test.bucket
|
211
|
+
expected_canonical_string = "GET\n\n\nTue, 27 Mar 2007 19:36:42 +0000\n/johnsmith/photos/puppy.jpg"
|
212
|
+
assert_equal expected_canonical_string, @s3_test.public_canonical_string
|
213
|
+
assert_equal "AWS 0PN6J17HBGXHT7JJ3X82:xXjDGYUmKxnwqr5KXNPGldn5LbA=", @s3_test.public_authorization_string
|
214
|
+
end
|
215
|
+
|
216
|
+
# See http://developer.amazonwebservices.com/connect/entry.jspa?externalID=123&categoryID=48
|
217
|
+
def test_dg_sample_two
|
218
|
+
@s3_test.make_authenticated_request(:put, '/photos/puppy.jpg', {'Content-Type' => 'image/jpeg',
|
219
|
+
'Content-Length' => '94328',
|
220
|
+
'Host' => 'johnsmith.s3.amazonaws.com',
|
221
|
+
'Date' => 'Tue, 27 Mar 2007 21:15:45 +0000'})
|
222
|
+
assert_equal 'johnsmith/', @s3_test.bucket
|
223
|
+
expected_canonical_string = "PUT\n\nimage/jpeg\nTue, 27 Mar 2007 21:15:45 +0000\n/johnsmith/photos/puppy.jpg"
|
224
|
+
assert_equal expected_canonical_string, @s3_test.public_canonical_string
|
225
|
+
assert_equal "AWS 0PN6J17HBGXHT7JJ3X82:hcicpDDvL9SsO6AkvxqmIWkmOuQ=", @s3_test.public_authorization_string
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_dg_sample_three
|
229
|
+
@s3_test.make_authenticated_request(:get, '', {'prefix' => 'photos',
|
230
|
+
'max-keys' => '50',
|
231
|
+
'marker' => 'puppy',
|
232
|
+
'host' => 'johnsmith.s3.amazonaws.com',
|
233
|
+
'date' => 'Tue, 27 Mar 2007 19:42:41 +0000'})
|
234
|
+
assert_equal 'johnsmith/', @s3_test.bucket
|
235
|
+
assert_equal "GET\n\n\nTue, 27 Mar 2007 19:42:41 +0000\n/johnsmith/", @s3_test.public_canonical_string
|
236
|
+
assert_equal 'AWS 0PN6J17HBGXHT7JJ3X82:jsRt/rhG+Vtp88HrYL706QhE4w4=', @s3_test.public_authorization_string
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_dg_sample_four
|
240
|
+
@s3_test.make_authenticated_request(:get, '?acl', {'host' => 'johnsmith.s3.amazonaws.com',
|
241
|
+
'date' => 'Tue, 27 Mar 2007 19:44:46 +0000'})
|
242
|
+
|
243
|
+
assert_equal "GET\n\n\nTue, 27 Mar 2007 19:44:46 +0000\n/johnsmith/?acl", @s3_test.public_canonical_string
|
244
|
+
assert_equal 'AWS 0PN6J17HBGXHT7JJ3X82:thdUi9VAkzhkniLj96JIrOPGi0g=', @s3_test.public_authorization_string
|
245
|
+
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_dg_sample_five
|
249
|
+
@s3_test.make_authenticated_request(:delete, '/johnsmith/photos/puppy.jpg',
|
250
|
+
{'User-Agent' => 'dotnet',
|
251
|
+
'host' => 's3.amazonaws.com',
|
252
|
+
'date' => 'Tue, 27 Mar 2007 21:20:27 +0000',
|
253
|
+
'x-amz-date' => 'Tue, 27 Mar 2007 21:20:26 +0000' })
|
254
|
+
assert_equal "DELETE\n\n\n\nx-amz-date:Tue, 27 Mar 2007 21:20:26 +0000\n/johnsmith/photos/puppy.jpg", @s3_test.public_canonical_string
|
255
|
+
assert_equal 'AWS 0PN6J17HBGXHT7JJ3X82:k3nL7gH3+PadhTEVn5Ip83xlYzk=', @s3_test.public_authorization_string
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_dg_sample_six
|
259
|
+
@s3_test.make_authenticated_request(:put, '/db-backup.dat.gz',
|
260
|
+
{'User-Agent' => 'curl/7.15.5',
|
261
|
+
'host' => 'static.johnsmith.net:8080',
|
262
|
+
'date' => 'Tue, 27 Mar 2007 21:06:08 +0000',
|
263
|
+
'x-amz-acl' => 'public-read',
|
264
|
+
'content-type' => 'application/x-download',
|
265
|
+
'Content-MD5' => '4gJE4saaMU4BqNR0kLY+lw==',
|
266
|
+
'X-Amz-Meta-ReviewedBy' => ['joe@johnsmith.net', 'jane@johnsmith.net'],
|
267
|
+
'X-Amz-Meta-FileChecksum' => '0x02661779',
|
268
|
+
'X-Amz-Meta-ChecksumAlgorithm' => 'crc32',
|
269
|
+
'Content-Disposition' => 'attachment; filename=database.dat',
|
270
|
+
'Content-Encoding' => 'gzip',
|
271
|
+
'Content-Length' => '5913339' })
|
272
|
+
assert_equal 'static.johnsmith.net/', @s3_test.bucket
|
273
|
+
expected_canonical_string = "PUT\n4gJE4saaMU4BqNR0kLY+lw==\napplication/x-download\nTue, 27 Mar 2007 21:06:08 +0000\n" +
|
274
|
+
"x-amz-acl:public-read\nx-amz-meta-checksumalgorithm:crc32\nx-amz-meta-filechecksum:0x02661779\n" +
|
275
|
+
"x-amz-meta-reviewedby:joe@johnsmith.net,jane@johnsmith.net\n/static.johnsmith.net/db-backup.dat.gz"
|
276
|
+
assert_equal expected_canonical_string, @s3_test.public_canonical_string
|
277
|
+
assert_equal 'AWS 0PN6J17HBGXHT7JJ3X82:C0FlOtU8Ylb9KDTpZqYkZPX91iI=', @s3_test.public_authorization_string
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_url_has_http_on_it
|
281
|
+
request = @s3_test.make_authenticated_request(:get, '')
|
282
|
+
assert_match /^http:\/\//, request[:uri]
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_url_is_sane
|
286
|
+
request = @s3_test.make_authenticated_request(:get, 'photos')
|
287
|
+
assert_equal 'http://s3.amazonaws.com/photos', request[:uri]
|
288
|
+
end
|
289
|
+
|
290
|
+
|
291
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: s3lib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Scott Patten
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-11-11 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: This library forms the basis for building a library to talk to Amazon S3 using Ruby. It is used as an example of how to build an Amazon S3 interface in The S3 Cookbook (http://thes3cookbook.com)
|
23
|
+
email: scott@scottpatten.ca
|
24
|
+
executables:
|
25
|
+
- s3lib
|
26
|
+
- s3sh_as
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- Rakefile
|
33
|
+
- VERSION.yml
|
34
|
+
- bin/s3lib
|
35
|
+
- bin/s3sh_as
|
36
|
+
- github-test.rb
|
37
|
+
- lib/acl.rb
|
38
|
+
- lib/acl_access.rb
|
39
|
+
- lib/acl_creating_a_grant_recipe.rb
|
40
|
+
- lib/acl_reading_acl_recipe.rb
|
41
|
+
- lib/acl_refreshing_cached_grants_recipe.rb
|
42
|
+
- lib/bucket.rb
|
43
|
+
- lib/bucket_before_refactoring.rb
|
44
|
+
- lib/bucket_create.rb
|
45
|
+
- lib/bucket_find.rb
|
46
|
+
- lib/bucket_with_acl_mixin.rb
|
47
|
+
- lib/error_handling.rb
|
48
|
+
- lib/grant.rb
|
49
|
+
- lib/grant_creating_a_grant_recipe.rb
|
50
|
+
- lib/grant_reading_acl_recipe.rb
|
51
|
+
- lib/object.rb
|
52
|
+
- lib/object_from_bucket_test.rb
|
53
|
+
- lib/object_take1.rb
|
54
|
+
- lib/object_with_acl_mixin.rb
|
55
|
+
- lib/put_with_curl_test.rb
|
56
|
+
- lib/s3_authenticator.rb
|
57
|
+
- lib/s3_authenticator_dev.rb
|
58
|
+
- lib/s3_authenticator_dev_private.rb
|
59
|
+
- lib/s3_errors.rb
|
60
|
+
- lib/s3lib.rb
|
61
|
+
- lib/s3lib_with_mixin.rb
|
62
|
+
- lib/service.rb
|
63
|
+
- lib/service_dev.rb
|
64
|
+
- s3lib.gemspec
|
65
|
+
- sample_usage.rb
|
66
|
+
- test/acl_test.rb
|
67
|
+
- test/amazon_headers_test.rb
|
68
|
+
- test/canonical_resource_test.rb
|
69
|
+
- test/canonical_string_tests.rb
|
70
|
+
- test/first_test.rb
|
71
|
+
- test/first_test_private.rb
|
72
|
+
- test/full_test.rb
|
73
|
+
- test/s3_authenticator_test.rb
|
74
|
+
has_rdoc: true
|
75
|
+
homepage: http://thes3cookbook.com
|
76
|
+
licenses: []
|
77
|
+
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.6.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: An Amazon S3 interface library used as an example in The S3 Cookbook (http://thes3cookbook.com)
|
108
|
+
test_files: []
|
109
|
+
|