s3 0.3.25 → 0.3.26

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,222 +0,0 @@
1
- # encoding: utf-8
2
- require "test_helper"
3
-
4
- class ObjectTest < Test::Unit::TestCase
5
- def setup
6
- @service = S3::Service.new(
7
- :access_key_id => "1234",
8
- :secret_access_key => "1337"
9
- )
10
- @bucket_images = S3::Bucket.send(:new, @service, "images")
11
- @object_lena = S3::Object.send(:new, @bucket_images, :key => "Lena.png")
12
- @object_lena.content = "test"
13
- @object_carmen = S3::Object.send(:new, @bucket_images, :key => "Carmen.png")
14
- @object_mac = S3::Object.send(:new, @bucket_images, :key => "Mac.png", :cache_control => "max-age=315360000")
15
- @object_mac.content = "test2"
16
-
17
- @response_binary = Net::HTTPOK.new("1.1", "200", "OK")
18
- @response_binary.stubs(:body).returns("test".respond_to?(:force_encoding) ? "test".force_encoding(Encoding::BINARY) : "test")
19
- @response_binary["etag"] = ""
20
- @response_binary["content-type"] = "image/png"
21
- @response_binary["content-disposition"] = "inline"
22
- @response_binary["content-encoding"] = nil
23
- @response_binary["last-modified"] = Time.now.httpdate
24
- @response_binary["content-length"] = 20
25
- @response_binary["x-amz-meta-test"] = "metadata"
26
-
27
- @xml_body = <<-EOXML
28
- <?xml version="1.0" encoding="UTF-8"?>
29
- <CopyObjectResult> <LastModified>#{Time.now.httpdate}</LastModified> <ETag>"etag"</ETag> </CopyObjectResult>
30
- EOXML
31
- @response_xml = Net::HTTPOK.new("1.1", "200", "OK")
32
- @response_xml.stubs(:body).returns(@xml_body)
33
- end
34
-
35
- test "initializing" do
36
- assert_raise ArgumentError do S3::Object.send(:new, nil, :key => "") end # should not allow empty key
37
-
38
- assert_nothing_raised do
39
- S3::Object.send(:new, nil, :key => "Lena.png")
40
- S3::Object.send(:new, nil, :key => "Lena playboy.png")
41
- S3::Object.send(:new, nil, :key => "Lena Söderberg.png")
42
- S3::Object.send(:new, nil, :key => "/images/pictures/test images/Lena not full.png")
43
- end
44
- end
45
-
46
- test "==" do
47
- expected = false
48
- actual = @object_lena == nil
49
- assert_equal(expected, actual)
50
- end
51
-
52
- test "full key" do
53
- expected = "images/Lena.png"
54
- actual = @object_lena.full_key
55
- assert_equal expected, actual
56
- end
57
-
58
- test "url" do
59
- bucket1 = S3::Bucket.send(:new, @service, "images")
60
-
61
- object11 = S3::Object.send(:new, bucket1, :key => "Lena.png")
62
- expected = "http://images.s3.amazonaws.com/Lena.png"
63
- actual = object11.url
64
- assert_equal expected, actual
65
-
66
- object12 = S3::Object.send(:new, bucket1, :key => "Lena Söderberg.png")
67
- expected = "http://images.s3.amazonaws.com/Lena%20S%C3%B6derberg.png"
68
- actual = object12.url
69
- assert_equal expected, actual
70
-
71
- object13 = S3::Object.send(:new, bucket1, :key => "Lena Söderberg [1].png")
72
- expected = "http://images.s3.amazonaws.com/Lena%20S%C3%B6derberg%20%5B1%5D.png"
73
- actual = object13.url
74
- assert_equal expected, actual
75
-
76
- bucket2 = S3::Bucket.send(:new, @service, "images_new")
77
-
78
- object21 = S3::Object.send(:new, bucket2, :key => "Lena.png")
79
- expected = "http://s3.amazonaws.com/images_new/Lena.png"
80
- actual = object21.url
81
- assert_equal expected, actual
82
- end
83
-
84
- test "cname url" do
85
- bucket1 = S3::Bucket.send(:new, @service, "images.example.com")
86
-
87
- object11 = S3::Object.send(:new, bucket1, :key => "Lena.png")
88
- expected = "http://images.example.com/Lena.png"
89
- actual = object11.cname_url
90
- assert_equal expected, actual
91
-
92
- object12 = S3::Object.send(:new, bucket1, :key => "Lena Söderberg.png")
93
- expected = "http://images.example.com/Lena%20S%C3%B6derberg.png"
94
- actual = object12.cname_url
95
- assert_equal expected, actual
96
-
97
- bucket2 = S3::Bucket.send(:new, @service, "images_new")
98
-
99
- object21 = S3::Object.send(:new, bucket2, :key => "Lena.png")
100
- expected = nil
101
- actual = object21.cname_url
102
- assert_equal expected, actual
103
- end
104
-
105
- test "destroy" do
106
- @object_lena.expects(:object_request).with(:delete)
107
- assert @object_lena.destroy
108
- end
109
-
110
- test "save" do
111
- @object_lena.expects(:object_request).with(:put, :body=>"test", :headers=>{ :x_amz_acl=>"private", :x_amz_storage_class=>"STANDARD", :content_type=>"application/octet-stream" }).returns(@response_binary)
112
- assert @object_lena.save
113
- end
114
-
115
- test "save with cache control headers" do
116
- assert_equal "max-age=315360000", @object_mac.cache_control
117
- @object_mac.expects(:object_request).with(:put, :body=>"test2", :headers=>{ :x_amz_acl=>"private", :x_amz_storage_class=>"STANDARD", :content_type=>"application/octet-stream", :cache_control=>"max-age=315360000" }).returns(@response_binary)
118
- assert @object_mac.save
119
- end
120
-
121
- test "content and parse headers" do
122
- @object_lena.expects(:object_request).with(:get, {}).returns(@response_binary)
123
-
124
- expected = /test/n
125
- actual = @object_lena.content(true)
126
- assert_match expected, actual
127
- assert_equal "image/png", @object_lena.content_type
128
-
129
- assert @object_lena.content
130
-
131
- @object_lena.expects(:object_request).with(:get, {}).returns(@response_binary)
132
- assert @object_lena.content(true)
133
- end
134
-
135
- test "retrieve" do
136
- @object_lena.expects(:object_request).with(:head, {}).returns(@response_binary)
137
- assert @object_lena.retrieve
138
- end
139
-
140
- test "retrieve headers" do
141
- @object_lena.expects(:object_request).twice.with(:head, {}).returns(@response_binary)
142
- assert @object_lena.retrieve
143
-
144
- meta = {"x-amz-meta-test" => ["metadata"]}
145
- assert_equal meta, @object_lena.retrieve.metadata
146
- end
147
-
148
- test "retrieve dont set content" do
149
- @object_lena.send(:remove_instance_variable, :@content)
150
-
151
- @response_binary.stubs(:body).returns(nil)
152
- @object_lena.expects(:object_request).with(:head, {}).returns(@response_binary)
153
- assert @object_lena.retrieve
154
-
155
- @object_lena.expects(:object_request).with(:get, {}).returns(@response_binary)
156
- @response_binary.stubs(:body).returns("hello")
157
-
158
- assert_equal "hello", @object_lena.content
159
- end
160
-
161
- test "exists" do
162
- @object_lena.expects(:retrieve).returns(true)
163
- assert @object_lena.exists?
164
-
165
- @object_carmen.expects(:retrieve).raises(S3::Error::NoSuchKey.new(nil, nil))
166
- assert ! @object_carmen.exists?
167
- end
168
-
169
- test "ACL writer" do
170
- expected = nil
171
- actual = @object_lena.acl
172
- assert_equal expected, actual
173
-
174
- assert @object_lena.acl = :public_read
175
-
176
- expected = "public-read"
177
- actual = @object_lena.acl
178
- assert_equal expected, actual
179
-
180
- assert @object_lena.acl = :private
181
-
182
- expected = "private"
183
- actual = @object_lena.acl
184
- assert_equal expected, actual
185
- end
186
-
187
- test "storage-class writer" do
188
- expected = nil
189
- actual = @object_lena.storage_class
190
- assert_equal expected, actual
191
-
192
- assert @object_lena.storage_class = :standard
193
-
194
- expected = "STANDARD"
195
- actual = @object_lena.storage_class
196
- assert_equal expected, actual
197
-
198
- assert @object_lena.storage_class = :reduced_redundancy
199
-
200
- expected = "REDUCED_REDUNDANCY"
201
- actual = @object_lena.storage_class
202
- assert_equal expected, actual
203
- end
204
-
205
- test "replace" do
206
- @bucket_images.expects(:bucket_request).with(:put, :path => "Lena-copy.png", :headers => { :x_amz_acl => "private", :content_type => "application/octet-stream", :x_amz_copy_source => "images/Lena.png", :x_amz_metadata_directive => "REPLACE" }).returns(@response_xml)
207
-
208
- new_object = @object_lena.copy(:key => "Lena-copy.png")
209
-
210
- assert_equal "Lena-copy.png", new_object.key
211
- assert_equal "Lena.png", @object_lena.key
212
- end
213
-
214
- test "copy" do
215
- @bucket_images.expects(:bucket_request).with(:put, :path => "Lena-copy.png", :headers => { :x_amz_acl => "private", :content_type => "application/octet-stream", :x_amz_copy_source => "images/Lena.png", :x_amz_metadata_directive => "COPY" }).returns(@response_xml)
216
-
217
- new_object = @object_lena.copy(:key => "Lena-copy.png", :replace => false)
218
-
219
- assert_equal "Lena-copy.png", new_object.key
220
- assert_equal "Lena.png", @object_lena.key
221
- end
222
- end
@@ -1,127 +0,0 @@
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 "no :access_key_id" do
61
- assert_raise ArgumentError do
62
- @service_bucket_exists = S3::Service.new(
63
- :access_key_id => nil,
64
- :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
65
- )
66
- end
67
- end
68
-
69
- test "no :secret_access_key" do
70
- assert_raise ArgumentError do
71
- @service_bucket_exists = S3::Service.new(
72
- :access_key_id => "12345678901234567890",
73
- :secret_access_key => nil
74
- )
75
- end
76
- end
77
-
78
- test "buckets and parse buckets empty" do
79
- expected = @buckets_empty_list
80
- actual = @service_empty_buckets_list.buckets
81
- assert_equal expected.length, actual.length
82
- assert_equal expected, actual
83
- end
84
-
85
- test "buckets and parse buckets" do
86
- expected = @buckets_list
87
- # ugly hack
88
- actual = @service_buckets_list.buckets.map { |obj| obj }
89
- assert_equal expected, actual
90
- end
91
-
92
- test "buckets build" do
93
- @service_empty_buckets_list.stubs(:service_request)
94
-
95
- expected = "bucket_name"
96
- actual = @service_empty_buckets_list.buckets.build("bucket_name")
97
- assert_kind_of S3::Bucket, actual
98
- assert_equal expected, actual.name
99
- end
100
-
101
- test "buckets find first" do
102
- assert_nothing_raised do
103
- actual = @service_buckets_list.buckets.find_first("data.example.com")
104
- assert_equal "data.example.com", actual.name
105
- end
106
- end
107
-
108
- test "buckets find first return nil" do
109
- assert_equal nil, @service_bucket_not_exists.buckets.find_first("data2.example.com")
110
- end
111
-
112
- test "buckets find all on empty list" do
113
- assert_nothing_raised do
114
- expected = @buckets_empty_list
115
- actual = @service_empty_buckets_list.buckets.find_all
116
- assert_equal expected, actual
117
- end
118
- end
119
-
120
- test "buckets find all" do
121
- assert_nothing_raised do
122
- expected = @buckets_list
123
- actual = @service_buckets_list.buckets.find_all
124
- assert_equal expected, actual
125
- end
126
- end
127
- end
@@ -1,228 +0,0 @@
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 get with non-unreserved URI characters" do
156
- actual = S3::Signature.generate_temporary_url_signature(
157
- :bucket => "johnsmith",
158
- :resource => "photos/puppy[1].jpg",
159
- :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
160
- :expires_at => 1175046589
161
- )
162
- expected = "gwCM0mVb9IrEPiUf8iaml6EISPc%3D"
163
- assert_equal expected, actual
164
- end
165
-
166
- test "temporary signature for object post" do
167
- actual = S3::Signature.generate_temporary_url_signature(
168
- :bucket => "johnsmith",
169
- :resource => "photos/puppy.jpg",
170
- :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
171
- :expires_at => 1175046589,
172
- :method => :post
173
- )
174
- expected = "duIzwO2KTEMIlbSYbFFS86Wj0LI%3D"
175
- assert_equal expected, actual
176
- end
177
-
178
- test "temporary signature for object put with headers" do
179
- actual = S3::Signature.generate_temporary_url_signature(
180
- :bucket => "johnsmith",
181
- :resource => "photos/puppy.jpg",
182
- :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
183
- :expires_at => 1175046589,
184
- :method => :put,
185
- :headers => {'x-amz-acl' => 'public-read'}
186
- )
187
- expected = "SDMxjIkOKIVR47nWfJ57UNPXxFM%3D"
188
- assert_equal expected, actual
189
- end
190
-
191
- test "temporary signature for object delete" do
192
- actual = S3::Signature.generate_temporary_url_signature(
193
- :bucket => "johnsmith",
194
- :resource => "photos/puppy.jpg",
195
- :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
196
- :expires_at => 1175046589,
197
- :method => :delete
198
- )
199
- expected = "5Vg7A4HxgS6tVCYzBx%2BkMR8sztY%3D"
200
- assert_equal expected, actual
201
- end
202
-
203
- test "temporary url for object get with bucket in the hostname" do
204
- actual = S3::Signature.generate_temporary_url(
205
- :bucket => "johnsmith",
206
- :resource => "photos/puppy.jpg",
207
- :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
208
- :expires_at => 1175046589,
209
- :add_bucket_to_host => true
210
- )
211
- expected = "http://johnsmith.s3.amazonaws.com/photos/puppy.jpg?AWSAccessKeyId=&Expires=1175046589&Signature=gs6xNznrLJ4Bd%2B1y9pcy2HOSVeg%3D"
212
- assert_equal expected, actual
213
- end
214
-
215
- test "temporary url for object put with headers" do
216
- actual = S3::Signature.generate_temporary_url(
217
- :bucket => "johnsmith",
218
- :resource => "photos/puppy.jpg",
219
- :access_key => '0PN5J17HBGZHT7JJ3X82',
220
- :secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o",
221
- :expires_at => 1175046589,
222
- :method => :put,
223
- :headers => {'x-amz-acl' => 'public-read'}
224
- )
225
- expected = "http://s3.amazonaws.com/johnsmith/photos/puppy.jpg?AWSAccessKeyId=0PN5J17HBGZHT7JJ3X82&Expires=1175046589&Signature=SDMxjIkOKIVR47nWfJ57UNPXxFM%3D"
226
- assert_equal expected, actual
227
- end
228
- end