fmalamitsas-aws-s3 0.6.2.1254423625

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/CHANGELOG +107 -0
  2. data/COPYING +19 -0
  3. data/INSTALL +55 -0
  4. data/README.erb +58 -0
  5. data/Rakefile +334 -0
  6. data/TODO +26 -0
  7. data/aws-s3.gemspec +42 -0
  8. data/bin/s3sh +6 -0
  9. data/bin/setup.rb +10 -0
  10. data/lib/aws/s3.rb +60 -0
  11. data/lib/aws/s3/acl.rb +636 -0
  12. data/lib/aws/s3/authentication.rb +222 -0
  13. data/lib/aws/s3/base.rb +270 -0
  14. data/lib/aws/s3/bittorrent.rb +58 -0
  15. data/lib/aws/s3/bucket.rb +372 -0
  16. data/lib/aws/s3/connection.rb +288 -0
  17. data/lib/aws/s3/error.rb +69 -0
  18. data/lib/aws/s3/exceptions.rb +133 -0
  19. data/lib/aws/s3/extensions.rb +342 -0
  20. data/lib/aws/s3/logging.rb +317 -0
  21. data/lib/aws/s3/object.rb +626 -0
  22. data/lib/aws/s3/owner.rb +46 -0
  23. data/lib/aws/s3/parsing.rb +99 -0
  24. data/lib/aws/s3/response.rb +180 -0
  25. data/lib/aws/s3/service.rb +51 -0
  26. data/lib/aws/s3/version.rb +12 -0
  27. data/site/index.erb +41 -0
  28. data/site/public/images/box-and-gem.gif +0 -0
  29. data/site/public/images/favicon.ico +0 -0
  30. data/site/public/ruby.css +18 -0
  31. data/site/public/screen.css +99 -0
  32. data/support/faster-xml-simple/COPYING +18 -0
  33. data/support/faster-xml-simple/README +8 -0
  34. data/support/faster-xml-simple/Rakefile +54 -0
  35. data/support/faster-xml-simple/lib/faster_xml_simple.rb +190 -0
  36. data/support/faster-xml-simple/test/fixtures/test-1.rails.yml +4 -0
  37. data/support/faster-xml-simple/test/fixtures/test-1.xml +3 -0
  38. data/support/faster-xml-simple/test/fixtures/test-1.yml +4 -0
  39. data/support/faster-xml-simple/test/fixtures/test-2.rails.yml +6 -0
  40. data/support/faster-xml-simple/test/fixtures/test-2.xml +3 -0
  41. data/support/faster-xml-simple/test/fixtures/test-2.yml +6 -0
  42. data/support/faster-xml-simple/test/fixtures/test-3.rails.yml +6 -0
  43. data/support/faster-xml-simple/test/fixtures/test-3.xml +5 -0
  44. data/support/faster-xml-simple/test/fixtures/test-3.yml +6 -0
  45. data/support/faster-xml-simple/test/fixtures/test-4.rails.yml +5 -0
  46. data/support/faster-xml-simple/test/fixtures/test-4.xml +7 -0
  47. data/support/faster-xml-simple/test/fixtures/test-4.yml +5 -0
  48. data/support/faster-xml-simple/test/fixtures/test-5.rails.yml +8 -0
  49. data/support/faster-xml-simple/test/fixtures/test-5.xml +7 -0
  50. data/support/faster-xml-simple/test/fixtures/test-5.yml +8 -0
  51. data/support/faster-xml-simple/test/fixtures/test-6.rails.yml +43 -0
  52. data/support/faster-xml-simple/test/fixtures/test-6.xml +29 -0
  53. data/support/faster-xml-simple/test/fixtures/test-6.yml +41 -0
  54. data/support/faster-xml-simple/test/fixtures/test-7.rails.yml +23 -0
  55. data/support/faster-xml-simple/test/fixtures/test-7.xml +22 -0
  56. data/support/faster-xml-simple/test/fixtures/test-7.yml +22 -0
  57. data/support/faster-xml-simple/test/fixtures/test-8.rails.yml +14 -0
  58. data/support/faster-xml-simple/test/fixtures/test-8.xml +8 -0
  59. data/support/faster-xml-simple/test/fixtures/test-8.yml +11 -0
  60. data/support/faster-xml-simple/test/regression_test.rb +47 -0
  61. data/support/faster-xml-simple/test/test_helper.rb +17 -0
  62. data/support/faster-xml-simple/test/xml_simple_comparison_test.rb +46 -0
  63. data/support/rdoc/code_info.rb +211 -0
  64. data/test/acl_test.rb +254 -0
  65. data/test/authentication_test.rb +118 -0
  66. data/test/base_test.rb +136 -0
  67. data/test/bucket_test.rb +74 -0
  68. data/test/connection_test.rb +216 -0
  69. data/test/error_test.rb +70 -0
  70. data/test/extensions_test.rb +340 -0
  71. data/test/fixtures.rb +89 -0
  72. data/test/fixtures/buckets.yml +133 -0
  73. data/test/fixtures/errors.yml +34 -0
  74. data/test/fixtures/headers.yml +3 -0
  75. data/test/fixtures/logging.yml +15 -0
  76. data/test/fixtures/loglines.yml +5 -0
  77. data/test/fixtures/logs.yml +7 -0
  78. data/test/fixtures/policies.yml +16 -0
  79. data/test/logging_test.rb +89 -0
  80. data/test/mocks/fake_response.rb +26 -0
  81. data/test/object_test.rb +205 -0
  82. data/test/parsing_test.rb +66 -0
  83. data/test/remote/acl_test.rb +116 -0
  84. data/test/remote/bittorrent_test.rb +45 -0
  85. data/test/remote/bucket_test.rb +146 -0
  86. data/test/remote/logging_test.rb +82 -0
  87. data/test/remote/object_test.rb +379 -0
  88. data/test/remote/test_file.data +0 -0
  89. data/test/remote/test_helper.rb +33 -0
  90. data/test/response_test.rb +68 -0
  91. data/test/service_test.rb +23 -0
  92. data/test/test_helper.rb +118 -0
  93. metadata +241 -0
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class TypecastingTest < Test::Unit::TestCase
4
+ # Make it easier to call methods in tests
5
+ Parsing::Typecasting.public_instance_methods.each do |method|
6
+ Parsing::Typecasting.send(:module_function, method)
7
+ end
8
+
9
+ def test_array_with_one_element_that_is_a_hash
10
+ value = [{'Available' => 'true'}]
11
+ assert_equal [{'available' => true}], Parsing::Typecasting.typecast(value)
12
+ end
13
+
14
+ def test_hash_with_one_key_whose_value_is_an_array
15
+ value = {
16
+ 'Bucket' =>
17
+ [
18
+ {'Available' => 'true'}
19
+ ]
20
+ }
21
+
22
+ expected = {
23
+ 'bucket' =>
24
+ [
25
+ {'available' => true}
26
+ ]
27
+ }
28
+ assert_equal expected, Parsing::Typecasting.typecast(value)
29
+ end
30
+
31
+ end
32
+
33
+ class XmlParserTest < Test::Unit::TestCase
34
+ def test_bucket_is_always_forced_to_be_an_array_unless_empty
35
+ one_bucket = Parsing::XmlParser.new(Fixtures::Buckets.bucket_list_with_one_bucket)
36
+ more_than_one = Parsing::XmlParser.new(Fixtures::Buckets.bucket_list_with_more_than_one_bucket)
37
+
38
+ [one_bucket, more_than_one].each do |bucket_list|
39
+ assert_kind_of Array, bucket_list['buckets']['bucket']
40
+ end
41
+
42
+ no_buckets = Parsing::XmlParser.new(Fixtures::Buckets.empty_bucket_list)
43
+ assert no_buckets.has_key?('buckets')
44
+ assert_nil no_buckets['buckets']
45
+ end
46
+
47
+ def test_bucket_contents_are_forced_to_be_an_array_unless_empty
48
+ one_key = Parsing::XmlParser.new(Fixtures::Buckets.bucket_with_one_key)
49
+ more_than_one = Parsing::XmlParser.new(Fixtures::Buckets.bucket_with_more_than_one_key)
50
+ [one_key, more_than_one].each do |bucket_with_contents|
51
+ assert_kind_of Array, bucket_with_contents['contents']
52
+ end
53
+
54
+ no_keys = Parsing::XmlParser.new(Fixtures::Buckets.empty_bucket)
55
+ assert !no_keys.has_key?('contents')
56
+ end
57
+
58
+ def test_policy_grants_are_always_an_array
59
+ policy = Parsing::XmlParser.new(Fixtures::Policies.policy_with_one_grant)
60
+ assert_kind_of Array, policy['access_control_list']['grant']
61
+ end
62
+
63
+ def test_empty_xml_response_is_not_parsed
64
+ assert_equal({}, Parsing::XmlParser.new(''))
65
+ end
66
+ end
@@ -0,0 +1,116 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class RemoteACLTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ establish_real_connection
7
+ end
8
+
9
+ def teardown
10
+ disconnect!
11
+ end
12
+
13
+ def test_acl
14
+ Bucket.create(TEST_BUCKET) # Wipe out the existing bucket's ACL
15
+
16
+ bucket_policy = Bucket.acl(TEST_BUCKET)
17
+ assert_equal 1, bucket_policy.grants.size
18
+ assert !bucket_policy.grants.include?(:public_read_acp)
19
+
20
+ bucket_policy.grants << ACL::Grant.grant(:public_read_acp)
21
+
22
+ assert_nothing_raised do
23
+ Bucket.acl(TEST_BUCKET, bucket_policy)
24
+ end
25
+
26
+ bucket = Bucket.find(TEST_BUCKET)
27
+ assert bucket.acl.grants.include?(:public_read_acp)
28
+
29
+ bucket.acl.grants.pop # Get rid of the newly added grant
30
+
31
+ assert !bucket.acl.grants.include?(:public_read_acp)
32
+ bucket.acl(bucket.acl) # Update its acl
33
+ assert Service.response.success?
34
+
35
+ bucket_policy = Bucket.acl(TEST_BUCKET)
36
+ assert_equal 1, bucket_policy.grants.size
37
+ assert !bucket_policy.grants.include?(:public_read_acp)
38
+
39
+ S3Object.store('testing-acls', 'the test data', TEST_BUCKET, :content_type => 'text/plain')
40
+ acl = S3Object.acl('testing-acls', TEST_BUCKET)
41
+
42
+ # Confirm object has the default policy
43
+
44
+ assert !acl.grants.empty?
45
+ assert_equal 1, acl.grants.size
46
+ grant = acl.grants.first
47
+
48
+ assert_equal 'FULL_CONTROL', grant.permission
49
+
50
+ grantee = grant.grantee
51
+
52
+ assert acl.owner.id
53
+ assert acl.owner.display_name
54
+ assert grantee.id
55
+ assert grantee.display_name
56
+
57
+ assert_equal acl.owner.id, grantee.id
58
+ assert_equal acl.owner.display_name, grantee.display_name
59
+
60
+ assert_equal Owner.current['id'], acl.owner.id
61
+
62
+ # Manually add read access to an Amazon customer by email address
63
+
64
+ new_grant = ACL::Grant.new
65
+ new_grant.permission = 'READ'
66
+ new_grant_grantee = ACL::Grantee.new
67
+ new_grant_grantee.email_address = 'marcel@vernix.org'
68
+ new_grant.grantee = new_grant_grantee
69
+ acl.grants << new_grant
70
+
71
+ assert_nothing_raised do
72
+ S3Object.acl('testing-acls', TEST_BUCKET, acl)
73
+ end
74
+
75
+ # Confirm the acl was updated successfully
76
+
77
+ assert Service.response.success?
78
+
79
+ acl = S3Object.acl('testing-acls', TEST_BUCKET)
80
+ assert !acl.grants.empty?
81
+ assert_equal 2, acl.grants.size
82
+ new_grant = acl.grants.last
83
+ assert_equal 'READ', new_grant.permission
84
+
85
+ # Confirm instance method has same result
86
+
87
+ assert_equal acl.grants, S3Object.find('testing-acls', TEST_BUCKET).acl.grants
88
+
89
+ # Get rid of the grant we just added
90
+
91
+ acl.grants.pop
92
+
93
+ # Confirm acl class method sees that the bucket option is being used to put a new acl
94
+
95
+ assert_nothing_raised do
96
+ TestS3Object.acl('testing-acls', acl)
97
+ end
98
+
99
+ assert Service.response.success?
100
+
101
+ acl = TestS3Object.acl('testing-acls')
102
+
103
+ # Confirm added grant was removed from the policy
104
+
105
+ assert !acl.grants.empty?
106
+ assert_equal 1, acl.grants.size
107
+ grant = acl.grants.first
108
+ assert_equal 'FULL_CONTROL', grant.permission
109
+
110
+ assert_nothing_raised do
111
+ S3Object.delete('testing-acls', TEST_BUCKET)
112
+ end
113
+
114
+ assert Service.response.success?
115
+ end
116
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class RemoteBittorrentTest < Test::Unit::TestCase
4
+ def setup
5
+ establish_real_connection
6
+ end
7
+
8
+ def teardown
9
+ disconnect!
10
+ end
11
+
12
+ def test_bittorrent
13
+ bt_test_key = 'testing-bittorrent'
14
+ S3Object.create(bt_test_key, 'foo', TEST_BUCKET)
15
+
16
+ # Confirm we can fetch a bittorrent file for this object
17
+
18
+ torrent_file = nil
19
+ assert_nothing_raised do
20
+ torrent_file = S3Object.torrent_for(bt_test_key, TEST_BUCKET)
21
+ end
22
+ assert torrent_file
23
+ assert torrent_file['tracker']
24
+
25
+ # Make object accessible to the public via a torrent
26
+
27
+ policy = S3Object.acl(bt_test_key, TEST_BUCKET)
28
+
29
+ assert !policy.grants.include?(:public_read)
30
+
31
+ assert_nothing_raised do
32
+ S3Object.grant_torrent_access_to(bt_test_key, TEST_BUCKET)
33
+ end
34
+
35
+ policy = S3Object.acl(bt_test_key, TEST_BUCKET)
36
+
37
+ assert policy.grants.include?(:public_read)
38
+
39
+ # Confirm instance method wraps class method
40
+
41
+ assert_equal torrent_file, S3Object.find(bt_test_key, TEST_BUCKET).torrent
42
+
43
+ S3Object.delete(bt_test_key, TEST_BUCKET)
44
+ end
45
+ end
@@ -0,0 +1,146 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class RemoteBucketTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ establish_real_connection
7
+ assert Bucket.find(TEST_BUCKET).delete_all
8
+ end
9
+
10
+ def teardown
11
+ disconnect!
12
+ end
13
+
14
+ def test_bucket
15
+ # Fetch the testing bucket
16
+
17
+ bucket = nil
18
+ assert_nothing_raised do
19
+ bucket = Bucket.find(TEST_BUCKET)
20
+ end
21
+
22
+ assert bucket
23
+
24
+ # Confirm we can fetch the bucket implicitly
25
+
26
+ bucket = nil
27
+ assert_nothing_raised do
28
+ bucket = TestBucket.find
29
+ end
30
+
31
+ assert bucket
32
+
33
+ # Confirm the bucket has the right name
34
+
35
+ assert_equal TEST_BUCKET, bucket.name
36
+
37
+ assert bucket.empty?
38
+ assert_equal 0, bucket.size
39
+
40
+ # Add some files to the bucket
41
+
42
+ assert_nothing_raised do
43
+ %w(a m z).each do |file_name|
44
+ S3Object.create(file_name, file_name, bucket.name, :content_type => 'text/plain')
45
+ end
46
+ end
47
+
48
+ # Confirm that we can reload the objects
49
+
50
+ assert_nothing_raised do
51
+ bucket.objects(:reload)
52
+ end
53
+
54
+ assert !bucket.empty?
55
+ assert_equal 3, bucket.size
56
+
57
+ assert_nothing_raised do
58
+ bucket.objects(:marker => 'm')
59
+ end
60
+
61
+ assert_equal 1, bucket.size
62
+ assert bucket['z']
63
+
64
+ assert_equal 1, Bucket.find(TEST_BUCKET, :max_keys => 1).size
65
+
66
+ assert_nothing_raised do
67
+ bucket.objects(:reload)
68
+ end
69
+
70
+ assert_equal 3, bucket.size
71
+
72
+ # Ensure the reloaded buckets have been repatriated
73
+
74
+ assert_equal bucket, bucket.objects.first.bucket
75
+
76
+ # Confirm that we can delete one of the objects and it will be removed
77
+
78
+ object_to_be_deleted = bucket.objects.last
79
+ assert_nothing_raised do
80
+ object_to_be_deleted.delete
81
+ end
82
+
83
+ assert !bucket.objects.include?(object_to_be_deleted)
84
+
85
+ # Confirm that we can add an object
86
+
87
+ object = bucket.new_object(:value => 'hello')
88
+
89
+ assert_raises(NoKeySpecified) do
90
+ object.store
91
+ end
92
+
93
+ object.key = 'abc'
94
+ assert_nothing_raised do
95
+ object.store
96
+ end
97
+
98
+ assert bucket.objects.include?(object)
99
+
100
+ # Confirm that the object is still there after reloading its objects
101
+
102
+ assert_nothing_raised do
103
+ bucket.objects(:reload)
104
+ end
105
+ assert bucket.objects.include?(object)
106
+
107
+ # Check that TestBucket has the same objects fetched implicitly
108
+
109
+ assert_equal bucket.objects, TestBucket.objects
110
+
111
+ # Empty out bucket
112
+
113
+ assert_nothing_raised do
114
+ bucket.delete_all
115
+ end
116
+
117
+ assert bucket.empty?
118
+
119
+ bucket = nil
120
+ assert_nothing_raised do
121
+ bucket = Bucket.find(TEST_BUCKET)
122
+ end
123
+
124
+ assert bucket.empty?
125
+ end
126
+
127
+ def test_bucket_name_is_switched_with_options_when_bucket_is_implicit_and_options_are_passed
128
+ Object.const_set(:ImplicitlyNamedBucket, Class.new(Bucket))
129
+ ImplicitlyNamedBucket.current_bucket = TEST_BUCKET
130
+ assert ImplicitlyNamedBucket.objects.empty?
131
+
132
+ %w(a b c).each {|key| S3Object.store(key, 'value does not matter', TEST_BUCKET)}
133
+
134
+ assert_equal 3, ImplicitlyNamedBucket.objects.size
135
+
136
+ objects = nil
137
+ assert_nothing_raised do
138
+ objects = ImplicitlyNamedBucket.objects(:max_keys => 1)
139
+ end
140
+
141
+ assert objects
142
+ assert_equal 1, objects.size
143
+ ensure
144
+ %w(a b c).each {|key| S3Object.delete(key, TEST_BUCKET)}
145
+ end
146
+ end
@@ -0,0 +1,82 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class RemoteLoggingTest < Test::Unit::TestCase
4
+ def setup
5
+ establish_real_connection
6
+ end
7
+
8
+ def teardown
9
+ disconnect!
10
+ end
11
+
12
+ def test_logging
13
+ Bucket.create(TEST_BUCKET) # Clear out any custom grants
14
+
15
+ # Confirm that logging is not enabled on the test bucket
16
+
17
+ assert !Bucket.logging_enabled_for?(TEST_BUCKET)
18
+ assert !Bucket.find(TEST_BUCKET).logging_enabled?
19
+
20
+ assert_equal [], Bucket.logs_for(TEST_BUCKET)
21
+
22
+ # Confirm the current bucket doesn't have logging grants
23
+
24
+ policy = Bucket.acl(TEST_BUCKET)
25
+ assert !policy.grants.include?(:logging_read_acp)
26
+ assert !policy.grants.include?(:logging_write)
27
+
28
+ # Confirm that we can enable logging
29
+
30
+ assert_nothing_raised do
31
+ Bucket.enable_logging_for TEST_BUCKET
32
+ end
33
+
34
+ # Confirm enabling logging worked
35
+
36
+ assert Service.response.success?
37
+
38
+ assert Bucket.logging_enabled_for?(TEST_BUCKET)
39
+ assert Bucket.find(TEST_BUCKET).logging_enabled?
40
+
41
+ # Confirm the appropriate grants were added
42
+
43
+ policy = Bucket.acl(TEST_BUCKET)
44
+ assert policy.grants.include?(:logging_read_acp)
45
+ assert policy.grants.include?(:logging_write)
46
+
47
+ # Confirm logging status used defaults
48
+
49
+ logging_status = Bucket.logging_status_for TEST_BUCKET
50
+ assert_equal TEST_BUCKET, logging_status.target_bucket
51
+ assert_equal 'log-', logging_status.target_prefix
52
+
53
+ # Confirm we can update the logging status
54
+
55
+ logging_status.target_prefix = 'access-log-'
56
+
57
+ assert_nothing_raised do
58
+ Bucket.logging_status_for TEST_BUCKET, logging_status
59
+ end
60
+
61
+ assert Service.response.success?
62
+
63
+ logging_status = Bucket.logging_status_for TEST_BUCKET
64
+ assert_equal 'access-log-', logging_status.target_prefix
65
+
66
+ # Confirm we can make a request for the bucket's logs
67
+
68
+ assert_nothing_raised do
69
+ Bucket.logs_for TEST_BUCKET
70
+ end
71
+
72
+ # Confirm we can disable logging
73
+
74
+ assert_nothing_raised do
75
+ Bucket.disable_logging_for(TEST_BUCKET)
76
+ end
77
+
78
+ assert Service.response.success?
79
+
80
+ assert !Bucket.logging_enabled_for?(TEST_BUCKET)
81
+ end
82
+ end