aws 1.11.38 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,10 +21,10 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #
23
23
 
24
- module RightAws
24
+ module Aws
25
25
 
26
26
  #
27
- # Right::Aws::SqsGen2Interface - RightScale's low-level Amazon SQS interface
27
+ # Right::Aws::SqsInterface - RightScale's low-level Amazon SQS interface
28
28
  # for API version 2008-01-01 and later.
29
29
  # For explanations of the semantics
30
30
  # of each call, please refer to Amazon's documentation at
@@ -33,10 +33,10 @@ module RightAws
33
33
  # This class provides a procedural interface to SQS. Conceptually it is
34
34
  # mostly a pass-through interface to SQS and its API is very similar to the
35
35
  # bare SQS API. For a somewhat higher-level and object-oriented interface, see
36
- # RightAws::SqsGen2.
36
+ # Aws::Sqs.
37
37
 
38
- class SqsInterface < RightAwsBase
39
- include RightAwsBaseInterface
38
+ class SqsInterface < AwsBase
39
+ include AwsBaseInterface
40
40
 
41
41
  API_VERSION = "2008-01-01"
42
42
  DEFAULT_HOST = "queue.amazonaws.com"
@@ -65,7 +65,7 @@ module RightAws
65
65
  # Amazon's article "Migrating to Amazon SQS API version 2008-01-01" at:
66
66
  # http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1148
67
67
  #
68
- # sqs = RightAws::SqsGen2Interface.new('1E3GDYEOGFJPIT75KDT40','hgTHt68JY07JKUY08ftHYtERkjgtfERn57DFE379', {:multi_thread => true, :logger => Logger.new('/tmp/x.log')})
68
+ # sqs = Aws::SqsInterface.new('1E3GDYEOGFJPIT75KDT40','hgTHt68JY07JKUY08ftHYtERkjgtfERn57DFE379', {:multi_thread => true, :logger => Logger.new('/tmp/x.log')})
69
69
  #
70
70
  # Params is a hash:
71
71
  #
@@ -367,7 +367,7 @@ module RightAws
367
367
  # PARSERS: Status Response Parser
368
368
  #-----------------------------------------------------------------
369
369
 
370
- class SqsStatusParser < RightAWSParser # :nodoc:
370
+ class SqsStatusParser < AwsParser # :nodoc:
371
371
  def tagend(name)
372
372
  if name == 'ResponseMetadata'
373
373
  @result = true
@@ -379,13 +379,13 @@ module RightAws
379
379
  # PARSERS: Queue
380
380
  #-----------------------------------------------------------------
381
381
 
382
- class SqsCreateQueueParser < RightAWSParser # :nodoc:
382
+ class SqsCreateQueueParser < AwsParser # :nodoc:
383
383
  def tagend(name)
384
384
  @result = @text if name == 'QueueUrl'
385
385
  end
386
386
  end
387
387
 
388
- class SqsListQueuesParser < RightAWSParser # :nodoc:
388
+ class SqsListQueuesParser < AwsParser # :nodoc:
389
389
  def reset
390
390
  @result = []
391
391
  end
@@ -394,7 +394,7 @@ module RightAws
394
394
  end
395
395
  end
396
396
 
397
- class SqsGetQueueAttributesParser < RightAWSParser # :nodoc:
397
+ class SqsGetQueueAttributesParser < AwsParser # :nodoc:
398
398
  def reset
399
399
  @result = {}
400
400
  end
@@ -410,7 +410,7 @@ module RightAws
410
410
  # PARSERS: Messages
411
411
  #-----------------------------------------------------------------
412
412
 
413
- class SqsReceiveMessageParser < RightAWSParser # :nodoc:
413
+ class SqsReceiveMessageParser < AwsParser # :nodoc:
414
414
  def reset
415
415
  @result = []
416
416
  end
@@ -427,7 +427,7 @@ module RightAws
427
427
  end
428
428
  end
429
429
 
430
- class SqsSendMessagesParser < RightAWSParser # :nodoc:
430
+ class SqsSendMessagesParser < AwsParser # :nodoc:
431
431
  def reset
432
432
  @result = {}
433
433
  end
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require File.dirname(__FILE__) + '/../test_credentials.rb'
2
3
 
3
4
  class TestAcf < Test::Unit::TestCase
4
5
 
@@ -7,15 +8,16 @@ class TestAcf < Test::Unit::TestCase
7
8
  STDOUT.sync = true
8
9
 
9
10
  def setup
10
- @acf= Rightscale::AcfInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
11
- @s3 = Rightscale::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
11
+ TestCredentials.get_credentials
12
+ @acf= Aws::AcfInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
13
+ @s3 = Aws::S3.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key)
12
14
  @bucket_name = "right-acf-awesome-test-bucket-0001"
13
15
  @bucket_domain = "#{@bucket_name}.s3.amazonaws.com"
14
16
  end
15
17
 
16
18
  def test_01_list_distributions_part1
17
19
  distributions = nil
18
- assert_nothing_raised(Rightscale::AwsError) do
20
+ assert_nothing_raised(Aws::AwsError) do
19
21
  distributions = @acf.list_distributions
20
22
  end
21
23
  assert distributions.is_a?(Array)
@@ -23,13 +25,13 @@ class TestAcf < Test::Unit::TestCase
23
25
 
24
26
  def test_02_try_to_create_for_bad_bucket
25
27
  # a bucket does not exist
26
- assert_raise(Rightscale::AwsError) do
28
+ assert_raise(Aws::AwsError) do
27
29
  @acf.create_distribution("right-cloudfront-awesome-test-bucket-not-exist", "Mustn't to be born", true)
28
30
  end
29
31
  # a bucket is not a domain naming complied guy
30
32
  bucket_name = 'right_cloudfront_awesome_test_bucket_BAD'
31
33
  @s3.bucket(bucket_name, :create)
32
- assert_raise(Rightscale::AwsError) do
34
+ assert_raise(Aws::AwsError) do
33
35
  @acf.create_distribution(bucket_name, "Mustn't to be born", true)
34
36
  end
35
37
  end
@@ -87,7 +89,7 @@ class TestAcf < Test::Unit::TestCase
87
89
  assert_not_equal config[:e_tag], new_config[:e_tag]
88
90
 
89
91
  # try to update the old config again (must fail because ETAG has changed)
90
- assert_raise(Rightscale::AwsError) do
92
+ assert_raise(Aws::AwsError) do
91
93
  @acf.set_distribution_config(old[:aws_id], config)
92
94
  end
93
95
  end
@@ -98,7 +100,7 @@ class TestAcf < Test::Unit::TestCase
98
100
  # list distributions
99
101
  @acf.list_distributions
100
102
  # list the distributions again - cache should hit
101
- assert_raise(Rightscale::AwsNoChange) do
103
+ assert_raise(Aws::AwsNoChange) do
102
104
  @acf.list_distributions
103
105
  end
104
106
  # disable caching
@@ -112,7 +114,7 @@ class TestAcf < Test::Unit::TestCase
112
114
  # should fail because
113
115
  if distribution[:status] == 'InProgress'
114
116
  # should fail because the distribution is not deployed yet
115
- assert_raise(Rightscale::AwsError) do
117
+ assert_raise(Aws::AwsError) do
116
118
  @acf.delete_distribution(distribution[:aws_id], distribution[:e_tag])
117
119
  end
118
120
  # wait for a deployed state
@@ -1,2 +1,2 @@
1
1
  require 'test/unit'
2
- require File.dirname(__FILE__) + '/../../lib/right_aws'
2
+ require File.dirname(__FILE__) + '/../../lib/aws'
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require File.dirname(__FILE__) + '/../test_credentials.rb'
3
+ require 'pp'
4
+
5
+ class TestEc2 < Test::Unit::TestCase
6
+
7
+ # Some of RightEc2 instance methods concerning instance launching and image registration
8
+ # are not tested here due to their potentially risk.
9
+
10
+ def setup
11
+ TestCredentials.get_credentials
12
+ @ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id,
13
+ TestCredentials.aws_secret_access_key)
14
+ @key = 'right_ec2_awesome_test_key'
15
+ @group = 'right_ec2_awesome_test_security_group'
16
+ end
17
+ end
@@ -1,5 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
  require 'pp'
3
+ require File.dirname(__FILE__) + '/../test_credentials.rb'
3
4
 
4
5
  class TestEc2 < Test::Unit::TestCase
5
6
 
@@ -7,7 +8,8 @@ class TestEc2 < Test::Unit::TestCase
7
8
  # are not tested here due to their potentially risk.
8
9
 
9
10
  def setup
10
- @ec2 = Rightscale::Ec2.new(TestCredentials.aws_access_key_id,
11
+ TestCredentials.get_credentials
12
+ @ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id,
11
13
  TestCredentials.aws_secret_access_key)
12
14
  @key = 'right_ec2_awesome_test_key'
13
15
  @group = 'right_ec2_awesome_test_security_group'
@@ -45,13 +47,13 @@ class TestEc2 < Test::Unit::TestCase
45
47
  images = @ec2.describe_images
46
48
  assert images.size>0, 'Amazon must have at least some public images'
47
49
  # unknown image
48
- assert_raise(Rightscale::AwsError){ @ec2.describe_images(['ami-ABCDEFGH'])}
50
+ assert_raise(Aws::AwsError){ @ec2.describe_images(['ami-ABCDEFGH'])}
49
51
  end
50
52
 
51
53
  def test_07_describe_instanses
52
54
  assert @ec2.describe_instances
53
55
  # unknown image
54
- assert_raise(Rightscale::AwsError){ @ec2.describe_instances(['i-ABCDEFGH'])}
56
+ assert_raise(Aws::AwsError){ @ec2.describe_instances(['i-ABCDEFGH'])}
55
57
  end
56
58
 
57
59
  def test_08_delete_security_group
@@ -62,11 +64,11 @@ class TestEc2 < Test::Unit::TestCase
62
64
  assert @ec2.delete_key_pair(@key), 'Delete_key_pair fail'
63
65
  ## Hmmm... Amazon does not through the exception any more. It now just returns a 'true' if the key does not exist any more...
64
66
  ## # key must be deleted already
65
- ## assert_raise(Rightscale::AwsError) { @ec2.delete_key_pair(@key) }
67
+ ## assert_raise(Aws::AwsError) { @ec2.delete_key_pair(@key) }
66
68
  end
67
69
 
68
70
  def test_10_signature_version_0
69
- ec2 = Rightscale::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '0')
71
+ ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '0')
70
72
  images = ec2.describe_images
71
73
  assert images.size>0, 'Amazon must have at least some public images'
72
74
  # check that the request has correct signature version
@@ -82,7 +84,7 @@ class TestEc2 < Test::Unit::TestCase
82
84
  assert regions.size > 0
83
85
  # check an access to regions
84
86
  regions.each do |region|
85
- regional_ec2 = Rightscale::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :region => region)
87
+ regional_ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :region => region)
86
88
  # do we have a correct endpoint server?
87
89
  assert_equal "#{region}.ec2.amazonaws.com", regional_ec2.params[:server]
88
90
  # get a list of images from every region
@@ -96,7 +98,7 @@ class TestEc2 < Test::Unit::TestCase
96
98
  end
97
99
 
98
100
  def test_12_endpoint_url
99
- ec2 = Rightscale::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :endpoint_url => 'a://b.c:0/d/', :region => 'z')
101
+ ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :endpoint_url => 'a://b.c:0/d/', :region => 'z')
100
102
  # :endpoint_url has a priority hence :region should be ommitted
101
103
  assert_equal 'a', ec2.params[:protocol]
102
104
  assert_equal 'b.c', ec2.params[:server]
@@ -1,2 +1,3 @@
1
1
  require 'test/unit'
2
- require File.dirname(__FILE__) + '/../../lib/right_aws'
2
+ require File.dirname(__FILE__) + '/../../lib/aws'
3
+
@@ -1,419 +1,425 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require File.dirname(__FILE__) + '/../test_credentials.rb'
2
3
 
3
4
  class TestS3 < Test::Unit::TestCase
4
5
 
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
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
285
291
 
286
292
  # 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
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
418
424
 
419
425
  end