aws 2.3.34 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ class S3TestBase < Test::Unit::TestCase
2
+
3
+ RIGHT_OBJECT_TEXT = 'Right test message'
4
+
5
+ def setup
6
+ TestCredentials.get_credentials
7
+ @s3 = Aws::S3Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
8
+ @bucket = TestCredentials.config['amazon']['my_prefix'] + '_awesome_test_bucket_000A1'
9
+ @bucket2 = TestCredentials.config['amazon']['my_prefix'] + '_awesome_test_bucket_000A2'
10
+ @key1 = 'test/woohoo1/'
11
+ @key2 = 'test1/key/woohoo2'
12
+ @key3 = 'test2/A%B@C_D&E?F+G=H"I'
13
+ @key1_copy = 'test/woohoo1_2'
14
+ @key1_new_name = 'test/woohoo1_3'
15
+ @key2_new_name = 'test1/key/woohoo2_new'
16
+ @s = Aws::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
17
+ end
18
+
19
+ def teardown
20
+
21
+ end
22
+
23
+ end
@@ -1,425 +1,162 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require_relative 's3_test_base'
2
3
  require File.dirname(__FILE__) + '/../test_credentials.rb'
3
4
 
4
- class TestS3 < Test::Unit::TestCase
5
+ class TestS3 < S3TestBase
6
+
7
+ #---------------------------
8
+ # Aws::S3Interface
9
+ #---------------------------
10
+
11
+ def test_01_create_bucket
12
+ assert @s3.create_bucket(@bucket), 'Create_bucket fail'
13
+ end
14
+
15
+ def test_02_list_all_my_buckets
16
+ assert @s3.list_all_my_buckets.map { |bucket| bucket[:name] }.include?(@bucket), "#{@bucket} must exist in bucket list"
17
+ end
18
+
19
+ def test_03_list_empty_bucket
20
+ assert_equal 0, @s3.list_bucket(@bucket).size, "#{@bucket} isn't empty, arrgh!"
21
+ end
22
+
23
+ def test_04_put
24
+ assert @s3.put(@bucket, @key1, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo1!'), 'Put bucket fail'
25
+ assert @s3.put(@bucket, @key2, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo2!'), 'Put bucket fail'
26
+ assert @s3.put(@bucket, @key3, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo3!'), 'Put bucket fail'
27
+ end
28
+
29
+ def test_04a_put
30
+ super_big_string = ""
31
+ 1000000.times {|i| super_big_string << "abcde" }
32
+ assert @s3.put(@bucket, "super_big", super_big_string), 'Put bucket fail'
33
+ end
34
+
35
+ def test_05_get_and_get_object
36
+ assert_raise(Aws::AwsError) { @s3.get(@bucket, 'undefined/key') }
37
+ data1 = @s3.get(@bucket, @key1)
38
+ assert_equal RIGHT_OBJECT_TEXT, data1[:object], "Object text must be equal to '#{RIGHT_OBJECT_TEXT}'"
39
+ assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1), "Get_object text must return '#{RIGHT_OBJECT_TEXT}'"
40
+ assert_equal 'Woohoo1!', data1[:headers]['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
41
+ assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key3), "Get_object text must return '#{RIGHT_OBJECT_TEXT}'"
42
+ end
43
+
44
+ def test_06_head
45
+ assert_equal 'Woohoo1!', @s3.head(@bucket, @key1)['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
46
+ end
47
+
48
+
49
+ def test_07_streaming_get
50
+ resp = String.new
51
+ assert_raise(Aws::AwsError) do
52
+ @s3.get(@bucket, 'undefined/key') do |chunk|
53
+ resp += chunk
54
+ end
55
+ end
56
+
57
+ resp = String.new
58
+ data1 = @s3.get(@bucket, @key1) do |chunk|
59
+ resp += chunk
60
+ end
61
+ assert_equal RIGHT_OBJECT_TEXT, resp, "Object text must be equal to '#{RIGHT_OBJECT_TEXT}'"
62
+ assert_equal @s3.get_object(@bucket, @key1), resp, "Streaming iface must return same as non-streaming"
63
+ assert_equal 'Woohoo1!', data1[:headers]['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
64
+ end
65
+
66
+ def test_08_keys
67
+ keys = @s3.list_bucket(@bucket).map { |b| b[:key] }
68
+ assert_equal keys.size, 3, "There should be 3 keys"
69
+ assert(keys.include?(@key1))
70
+ assert(keys.include?(@key2))
71
+ assert(keys.include?(@key3))
72
+ end
73
+
74
+ def test_09_copy_key
75
+ #--- test COPY
76
+ # copy a key
77
+ assert @s3.copy(@bucket, @key1, @bucket, @key1_copy)
78
+ # check it was copied well
79
+ assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1_copy), "copied object must have the same data"
80
+ # check meta-headers were copied
81
+ headers = @s3.head(@bucket, @key1_copy)
82
+ assert_equal 'Woohoo1!', headers['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
83
+ #--- test REPLACE
84
+ assert @s3.copy(@bucket, @key1, @bucket, @key1_copy, :replace, 'x-amz-meta-family' => 'oooops!')
85
+ # check it was copied well
86
+ assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1_copy), "copied object must have the same data"
87
+ # check meta-headers were overwrittenn
88
+ headers = @s3.head(@bucket, @key1_copy)
89
+ assert_equal 'oooops!', headers['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'oooops!'"
90
+ end
91
+
92
+ def test_10_move_key
93
+ # move a key
94
+ assert @s3.move(@bucket, @key1, @bucket, @key1_new_name)
95
+ # check it's data was moved correctly
96
+ assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1_new_name), "moved object must have the same data"
97
+ # check meta-headers were moved
98
+ headers = @s3.head(@bucket, @key1_new_name)
99
+ assert_equal 'Woohoo1!', headers['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
100
+ # check the original key is not exists any more
101
+ keys = @s3.list_bucket(@bucket).map { |b| b[:key] }
102
+ assert(!keys.include?(@key1))
103
+ end
104
+
105
+ def test_11_rename_key
106
+ # rename a key
107
+ assert @s3.rename(@bucket, @key2, @key2_new_name)
108
+ # check the new key data
109
+ assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key2_new_name), "moved object must have the same data"
110
+ # check meta-headers
111
+ headers = @s3.head(@bucket, @key2_new_name)
112
+ assert_equal 'Woohoo2!', headers['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo2!'"
113
+ # check the original key is not exists any more
114
+ keys = @s3.list_bucket(@bucket).map { |b| b[:key] }
115
+ assert(!keys.include?(@key2))
116
+ end
117
+
118
+ def test_12_retrieve_object
119
+ assert_raise(Aws::AwsError) { @s3.retrieve_object(:bucket => @bucket, :key => 'undefined/key') }
120
+ data1 = @s3.retrieve_object(:bucket => @bucket, :key => @key1_new_name)
121
+ assert_equal RIGHT_OBJECT_TEXT, data1[:object], "Object text must be equal to '#{RIGHT_OBJECT_TEXT}'"
122
+ assert_equal 'Woohoo1!', data1[:headers]['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
123
+ end
124
+
125
+ def test_13_delete_folder
126
+ assert_equal 1, @s3.delete_folder(@bucket, 'test').size, "Only one key(#{@key1}) must be deleted!"
127
+ end
128
+
129
+ # idle timeout is 20 seconds
130
+ # https://forums.aws.amazon.com/thread.jspa?threadID=58038
131
+ def test_14_idle_timeout
132
+ @s3 = Aws::S3Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key,
133
+ :connection_mode=>:single)
134
+ # Disable connection retrying
135
+ Aws::AWSErrorHandler.close_on_error = false
136
+ assert @s3.put(@bucket, @key1, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo1!'), 'Put bucket fail'
137
+ sleep 300
138
+ assert_raises Aws::AwsError do
139
+ @s3.put(@bucket, @key2, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo1!')
140
+ end
141
+
142
+ # now try again with retry mode
143
+ @s3 = Aws::S3Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key,
144
+ :connection_mode=>:single)
145
+ Aws::AWSErrorHandler.close_on_error = true
146
+ assert @s3.put(@bucket, @key1, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo1!'), 'Put bucket fail'
147
+ sleep 30
148
+ assert @s3.put(@bucket, @key2, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo1!'), 'Put bucket fail'
149
+
150
+
151
+ end
152
+
153
+ def test_99_delete_bucket
154
+ assert_raise(Aws::AwsError) { @s3.delete_bucket(@bucket) }
155
+ assert @s3.clear_bucket(@bucket), 'Clear_bucket fail'
156
+ assert_equal 0, @s3.list_bucket(@bucket).size, 'Bucket must be empty'
157
+ assert @s3.delete_bucket(@bucket)
158
+ assert !@s3.list_all_my_buckets.map { |bucket| bucket[:name] }.include?(@bucket), "#{@bucket} must not exist"
159
+ end
5
160
 
6
- RIGHT_OBJECT_TEXT = 'Right test message'
7
-
8
- def setup
9
- TestCredentials.get_credentials
10
- @s3 = Aws::S3Interface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
11
- @bucket = TestCredentials.config['amazon']['my_prefix'] + '_awesome_test_bucket_000A1'
12
- @bucket2 = TestCredentials.config['amazon']['my_prefix'] + '_awesome_test_bucket_000A2'
13
- @key1 = 'test/woohoo1/'
14
- @key2 = 'test1/key/woohoo2'
15
- @key3 = 'test2/A%B@C_D&E?F+G=H"I'
16
- @key1_copy = 'test/woohoo1_2'
17
- @key1_new_name = 'test/woohoo1_3'
18
- @key2_new_name = 'test1/key/woohoo2_new'
19
- @s = Aws::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
20
- end
21
-
22
- def teardown
23
-
24
- end
25
-
26
- #---------------------------
27
- # Aws::S3Interface
28
- #---------------------------
29
-
30
- def test_01_create_bucket
31
- assert @s3.create_bucket(@bucket), 'Create_bucket fail'
32
- end
33
-
34
- def test_02_list_all_my_buckets
35
- assert @s3.list_all_my_buckets.map{|bucket| bucket[:name]}.include?(@bucket), "#{@bucket} must exist in bucket list"
36
- end
37
-
38
- def test_03_list_empty_bucket
39
- assert_equal 0, @s3.list_bucket(@bucket).size, "#{@bucket} isn't empty, arrgh!"
40
- end
41
-
42
- def test_04_put
43
- assert @s3.put(@bucket, @key1, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo1!'), 'Put bucket fail'
44
- assert @s3.put(@bucket, @key2, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo2!'), 'Put bucket fail'
45
- assert @s3.put(@bucket, @key3, RIGHT_OBJECT_TEXT, 'x-amz-meta-family'=>'Woohoo3!'), 'Put bucket fail'
46
- end
47
-
48
- def test_05_get_and_get_object
49
- assert_raise(Aws::AwsError) { @s3.get(@bucket, 'undefined/key') }
50
- data1 = @s3.get(@bucket, @key1)
51
- assert_equal RIGHT_OBJECT_TEXT, data1[:object], "Object text must be equal to '#{RIGHT_OBJECT_TEXT}'"
52
- assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1), "Get_object text must return '#{RIGHT_OBJECT_TEXT}'"
53
- assert_equal 'Woohoo1!', data1[:headers]['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
54
- assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key3), "Get_object text must return '#{RIGHT_OBJECT_TEXT}'"
55
- end
56
-
57
- def test_06_head
58
- assert_equal 'Woohoo1!', @s3.head(@bucket, @key1)['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
59
- end
60
-
61
-
62
- def test_07_streaming_get
63
- resp = String.new
64
- assert_raise(Aws::AwsError) do
65
- @s3.get(@bucket, 'undefined/key') do |chunk|
66
- resp += chunk
67
- end
68
- end
69
-
70
- resp = String.new
71
- data1 = @s3.get(@bucket, @key1) do |chunk|
72
- resp += chunk
73
- end
74
- assert_equal RIGHT_OBJECT_TEXT, resp, "Object text must be equal to '#{RIGHT_OBJECT_TEXT}'"
75
- assert_equal @s3.get_object(@bucket, @key1), resp, "Streaming iface must return same as non-streaming"
76
- assert_equal 'Woohoo1!', data1[:headers]['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
77
- end
78
-
79
- def test_08_keys
80
- keys = @s3.list_bucket(@bucket).map{|b| b[:key]}
81
- assert_equal keys.size, 3, "There should be 3 keys"
82
- assert(keys.include?(@key1))
83
- assert(keys.include?(@key2))
84
- assert(keys.include?(@key3))
85
- end
86
-
87
- def test_09_copy_key
88
- #--- test COPY
89
- # copy a key
90
- assert @s3.copy(@bucket, @key1, @bucket, @key1_copy)
91
- # check it was copied well
92
- assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1_copy), "copied object must have the same data"
93
- # check meta-headers were copied
94
- headers = @s3.head(@bucket, @key1_copy)
95
- assert_equal 'Woohoo1!', headers['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
96
- #--- test REPLACE
97
- assert @s3.copy(@bucket, @key1, @bucket, @key1_copy, :replace, 'x-amz-meta-family' => 'oooops!')
98
- # check it was copied well
99
- assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1_copy), "copied object must have the same data"
100
- # check meta-headers were overwrittenn
101
- headers = @s3.head(@bucket, @key1_copy)
102
- assert_equal 'oooops!', headers['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'oooops!'"
103
- end
104
-
105
- def test_10_move_key
106
- # move a key
107
- assert @s3.move(@bucket, @key1, @bucket, @key1_new_name)
108
- # check it's data was moved correctly
109
- assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key1_new_name), "moved object must have the same data"
110
- # check meta-headers were moved
111
- headers = @s3.head(@bucket, @key1_new_name)
112
- assert_equal 'Woohoo1!', headers['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
113
- # check the original key is not exists any more
114
- keys = @s3.list_bucket(@bucket).map{|b| b[:key]}
115
- assert(!keys.include?(@key1))
116
- end
117
-
118
- def test_11_rename_key
119
- # rename a key
120
- assert @s3.rename(@bucket, @key2, @key2_new_name)
121
- # check the new key data
122
- assert_equal RIGHT_OBJECT_TEXT, @s3.get_object(@bucket, @key2_new_name), "moved object must have the same data"
123
- # check meta-headers
124
- headers = @s3.head(@bucket, @key2_new_name)
125
- assert_equal 'Woohoo2!', headers['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo2!'"
126
- # check the original key is not exists any more
127
- keys = @s3.list_bucket(@bucket).map{|b| b[:key]}
128
- assert(!keys.include?(@key2))
129
- end
130
-
131
- def test_12_retrieve_object
132
- assert_raise(Aws::AwsError) { @s3.retrieve_object(:bucket => @bucket, :key => 'undefined/key') }
133
- data1 = @s3.retrieve_object(:bucket => @bucket, :key => @key1_new_name)
134
- assert_equal RIGHT_OBJECT_TEXT, data1[:object], "Object text must be equal to '#{RIGHT_OBJECT_TEXT}'"
135
- assert_equal 'Woohoo1!', data1[:headers]['x-amz-meta-family'], "x-amz-meta-family header must be equal to 'Woohoo1!'"
136
- end
137
-
138
- def test_13_delete_folder
139
- assert_equal 1, @s3.delete_folder(@bucket, 'test').size, "Only one key(#{@key1}) must be deleted!"
140
- end
141
-
142
- def test_14_delete_bucket
143
- assert_raise(Aws::AwsError) { @s3.delete_bucket(@bucket) }
144
- assert @s3.clear_bucket(@bucket), 'Clear_bucket fail'
145
- assert_equal 0, @s3.list_bucket(@bucket).size, 'Bucket must be empty'
146
- assert @s3.delete_bucket(@bucket)
147
- assert !@s3.list_all_my_buckets.map{|bucket| bucket[:name]}.include?(@bucket), "#{@bucket} must not exist"
148
- end
149
-
150
-
151
- #---------------------------
152
- # Aws::S3 classes
153
- #---------------------------
154
-
155
- def test_20_s3
156
- # create bucket
157
- bucket = @s.bucket(@bucket, true)
158
- assert bucket
159
- # check that the bucket exists
160
- assert @s.buckets.map{|b| b.name}.include?(@bucket)
161
- # delete bucket
162
- assert bucket.clear
163
- assert bucket.delete
164
- end
165
-
166
- def test_21_bucket_create_put_get_key
167
- bucket = Aws::S3::Bucket.create(@s, @bucket, true)
168
- # check that the bucket exists
169
- assert @s.buckets.map{|b| b.name}.include?(@bucket)
170
- assert bucket.keys.empty?
171
- # put data
172
- assert bucket.put(@key3, RIGHT_OBJECT_TEXT, {'family'=>'123456'})
173
- # get data and compare
174
- assert_equal RIGHT_OBJECT_TEXT, bucket.get(@key3)
175
- # get key object
176
- key = bucket.key(@key3, true)
177
- assert_equal Aws::S3::Key, key.class
178
- assert key.exists?
179
- assert_equal '123456', key.meta_headers['family']
180
- end
181
-
182
- def test_22_keys
183
- bucket = Aws::S3::Bucket.create(@s, @bucket, false)
184
- # create first key
185
- key3 = Aws::S3::Key.create(bucket, @key3)
186
- key3.refresh
187
- assert key3.exists?
188
- assert_equal '123456', key3.meta_headers['family']
189
- # create second key
190
- key2 = Aws::S3::Key.create(bucket, @key2)
191
- assert !key2.refresh
192
- assert !key2.exists?
193
- assert_raise(Aws::AwsError) { key2.head }
194
- # store key
195
- key2.meta_headers = {'family'=>'111222333'}
196
- assert key2.put(RIGHT_OBJECT_TEXT)
197
- # make sure that the key exists
198
- assert key2.refresh
199
- assert key2.exists?
200
- assert key2.head
201
- # get its data
202
- assert_equal RIGHT_OBJECT_TEXT, key2.get
203
- # drop key
204
- assert key2.delete
205
- assert !key2.exists?
206
- end
207
-
208
- def test_23_rename_key
209
- bucket = Aws::S3::Bucket.create(@s, @bucket, false)
210
- # -- 1 -- (key based rename)
211
- # create a key
212
- key = bucket.key('test/copy/1')
213
- key.put(RIGHT_OBJECT_TEXT)
214
- original_key = key.clone
215
- assert key.exists?, "'test/copy/1' should exist"
216
- # rename it
217
- key.rename('test/copy/2')
218
- assert_equal 'test/copy/2', key.name
219
- assert key.exists?, "'test/copy/2' should exist"
220
- # the original key should not exist
221
- assert !original_key.exists?, "'test/copy/1' should not exist"
222
- # -- 2 -- (bucket based rename)
223
- bucket.rename_key('test/copy/2', 'test/copy/3')
224
- assert bucket.key('test/copy/3').exists?, "'test/copy/3' should exist"
225
- assert !bucket.key('test/copy/2').exists?, "'test/copy/2' should not exist"
226
- end
227
-
228
- def test_24_copy_key
229
- bucket = Aws::S3::Bucket.create(@s, @bucket, false)
230
- # -- 1 -- (key based copy)
231
- # create a key
232
- key = bucket.key('test/copy/10')
233
- key.put(RIGHT_OBJECT_TEXT)
234
- # make copy
235
- new_key = key.copy('test/copy/11')
236
- # make sure both the keys exist and have a correct data
237
- assert key.exists?, "'test/copy/10' should exist"
238
- assert new_key.exists?, "'test/copy/11' should exist"
239
- assert_equal RIGHT_OBJECT_TEXT, key.get
240
- assert_equal RIGHT_OBJECT_TEXT, new_key.get
241
- # -- 2 -- (bucket based copy)
242
- bucket.copy_key('test/copy/11', 'test/copy/12')
243
- assert bucket.key('test/copy/11').exists?, "'test/copy/11' should exist"
244
- assert bucket.key('test/copy/12').exists?, "'test/copy/12' should exist"
245
- assert_equal RIGHT_OBJECT_TEXT, bucket.key('test/copy/11').get
246
- assert_equal RIGHT_OBJECT_TEXT, bucket.key('test/copy/12').get
247
- end
248
-
249
- def test_25_move_key
250
- bucket = Aws::S3::Bucket.create(@s, @bucket, false)
251
- # -- 1 -- (key based copy)
252
- # create a key
253
- key = bucket.key('test/copy/20')
254
- key.put(RIGHT_OBJECT_TEXT)
255
- # move
256
- new_key = key.move('test/copy/21')
257
- # make sure both the keys exist and have a correct data
258
- assert !key.exists?, "'test/copy/20' should not exist"
259
- assert new_key.exists?, "'test/copy/21' should exist"
260
- assert_equal RIGHT_OBJECT_TEXT, new_key.get
261
- # -- 2 -- (bucket based copy)
262
- bucket.copy_key('test/copy/21', 'test/copy/22')
263
- assert bucket.key('test/copy/21').exists?, "'test/copy/21' should not exist"
264
- assert bucket.key('test/copy/22').exists?, "'test/copy/22' should exist"
265
- assert_equal RIGHT_OBJECT_TEXT, bucket.key('test/copy/22').get
266
- end
267
-
268
- def test_26_save_meta
269
- bucket = Aws::S3::Bucket.create(@s, @bucket, false)
270
- # create a key
271
- key = bucket.key('test/copy/30')
272
- key.put(RIGHT_OBJECT_TEXT)
273
- assert key.meta_headers.blank?
274
- # store some meta keys
275
- meta = {'family' => 'oops', 'race' => 'troll'}
276
- assert_equal meta, key.save_meta(meta)
277
- # reload meta
278
- assert_equal meta, key.reload_meta
279
- end
280
-
281
- def test_27_clear_delete
282
- bucket = Aws::S3::Bucket.create(@s, @bucket, false)
283
- # add another key
284
- bucket.put(@key2, RIGHT_OBJECT_TEXT)
285
- # delete 'folder'
286
- assert_equal 1, bucket.delete_folder(@key1).size
287
- # delete
288
- assert_raise(Aws::AwsError) { bucket.delete }
289
- bucket.delete(true)
290
- end
291
-
292
- # Grantees
293
-
294
- def test_30_create_bucket
295
- bucket = @s.bucket(@bucket, true, 'public-read')
296
- assert bucket
297
- end
298
-
299
- def test_31_list_grantees
300
- bucket = Aws::S3::Bucket.create(@s, @bucket, false)
301
- # get grantees list
302
- grantees = bucket.grantees
303
- # check that the grantees count equal to 2 (root, AllUsers)
304
- assert_equal 2, grantees.size
305
- end
306
-
307
- def test_32_grant_revoke_drop
308
- bucket = Aws::S3::Bucket.create(@s, @bucket, false)
309
- # Take 'AllUsers' grantee
310
- grantee = Aws::S3::Grantee.new(bucket, 'http://acs.amazonaws.com/groups/global/AllUsers')
311
- # Check exists?
312
- assert grantee.exists?
313
- # Add grant as String
314
- assert grantee.grant('WRITE')
315
- # Add grants as Array
316
- assert grantee.grant(['READ_ACP', 'WRITE_ACP'])
317
- # Check perms count
318
- assert_equal 4, grantee.perms.size
319
- # revoke 'WRITE_ACP'
320
- assert grantee.revoke('WRITE_ACP')
321
- # Check manual perm removal method
322
- grantee.perms -= ['READ_ACP']
323
- grantee.apply
324
- assert_equal 2, grantee.perms.size
325
- # Check grantee removal if it has no permissions
326
- assert grantee.perms = []
327
- assert grantee.apply
328
- assert !grantee.exists?
329
- # Check multiple perms assignment
330
- assert grantee.grant('FULL_CONTROL', 'READ', 'WRITE')
331
- assert_equal ['FULL_CONTROL', 'READ', 'WRITE'].sort, grantee.perms.sort
332
- # Check multiple perms removal
333
- assert grantee.revoke('FULL_CONTROL', 'WRITE')
334
- assert_equal ['READ'], grantee.perms
335
- # check 'Drop' method
336
- assert grantee.drop
337
- assert !grantee.exists?
338
- assert_equal 1, bucket.grantees.size
339
- # Delete bucket
340
- bucket.delete(true)
341
- end
342
-
343
- def test_33_key_grantees
344
- # Create bucket
345
- bucket = @s.bucket(@bucket, true)
346
- # Create key
347
- key = bucket.key(@key1)
348
- assert key.put(RIGHT_OBJECT_TEXT, 'public-read')
349
- # Get grantees list (must be == 2)
350
- grantees = key.grantees
351
- assert grantees
352
- assert_equal 2, grantees.size
353
- # Take one of grantees and give him 'Write' perms
354
- grantee = grantees[0]
355
- assert grantee.grant('WRITE')
356
- # Drop grantee
357
- assert grantee.drop
358
- # Drop bucket
359
- bucket.delete(true)
360
- end
361
-
362
- def test_34_bucket_create_put_with_perms
363
- bucket = Aws::S3::Bucket.create(@s, @bucket, true)
364
- # check that the bucket exists
365
- assert @s.buckets.map{|b| b.name}.include?(@bucket)
366
- assert bucket.keys.empty?
367
- # put data (with canned ACL)
368
- assert bucket.put(@key1, RIGHT_OBJECT_TEXT, {'family'=>'123456'}, "public-read")
369
- # get data and compare
370
- assert_equal RIGHT_OBJECT_TEXT, bucket.get(@key1)
371
- # get key object
372
- key = bucket.key(@key1, true)
373
- assert_equal Aws::S3::Key, key.class
374
- assert key.exists?
375
- assert_equal '123456', key.meta_headers['family']
376
- end
377
-
378
- def test_35_key_put_with_perms
379
- bucket = Aws::S3::Bucket.create(@s, @bucket, false)
380
- # create first key
381
- key1 = Aws::S3::Key.create(bucket, @key1)
382
- key1.refresh
383
- assert key1.exists?
384
- assert key1.put(RIGHT_OBJECT_TEXT, "public-read")
385
- # get its data
386
- assert_equal RIGHT_OBJECT_TEXT, key1.get
387
- # drop key
388
- assert key1.delete
389
- assert !key1.exists?
390
- end
391
-
392
- def test_36_set_amazon_problems
393
- original_problems = Aws::S3Interface.amazon_problems
394
- assert(original_problems.length > 0)
395
- Aws::S3Interface.amazon_problems= original_problems << "A New Problem"
396
- new_problems = Aws::S3Interface.amazon_problems
397
- assert_equal(new_problems, original_problems)
398
-
399
- Aws::S3Interface.amazon_problems= nil
400
- assert_nil(Aws::S3Interface.amazon_problems)
401
- end
402
-
403
- def test_37_access_logging
404
- bucket = Aws::S3::Bucket.create(@s, @bucket, false)
405
- targetbucket = Aws::S3::Bucket.create(@s, @bucket2, true)
406
- # Take 'AllUsers' grantee
407
- grantee = Aws::S3::Grantee.new(targetbucket, 'http://acs.amazonaws.com/groups/s3/LogDelivery')
408
-
409
- assert grantee.grant(['READ_ACP', 'WRITE'])
410
-
411
- assert bucket.enable_logging(:targetbucket => targetbucket, :targetprefix => "loggylogs/")
412
-
413
- assert_equal(bucket.logging_info, {:enabled => true, :targetbucket => @bucket2, :targetprefix => "loggylogs/"})
414
-
415
- assert bucket.disable_logging
416
-
417
- # check 'Drop' method
418
- assert grantee.drop
419
-
420
- # Delete bucket
421
- bucket.delete(true)
422
- targetbucket.delete(true)
423
- end
424
161
 
425
162
  end