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