fog-internet-archive 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +53 -0
  3. data/.travis.yml +16 -0
  4. data/Gemfile +3 -0
  5. data/README.md +6 -0
  6. data/Rakefile +19 -0
  7. data/fog-internet-archive.gemspec +32 -0
  8. data/lib/fog/bin/internet_archive.rb +32 -0
  9. data/lib/fog/internet_archive.rb +1 -0
  10. data/lib/fog/internet_archive/core.rb +291 -0
  11. data/lib/fog/internet_archive/models/storage/directories.rb +39 -0
  12. data/lib/fog/internet_archive/models/storage/directory.rb +105 -0
  13. data/lib/fog/internet_archive/models/storage/file.rb +254 -0
  14. data/lib/fog/internet_archive/models/storage/files.rb +119 -0
  15. data/lib/fog/internet_archive/models/storage/ia_attributes.rb +36 -0
  16. data/lib/fog/internet_archive/parsers/storage/access_control_list.rb +42 -0
  17. data/lib/fog/internet_archive/parsers/storage/complete_multipart_upload.rb +20 -0
  18. data/lib/fog/internet_archive/parsers/storage/copy_object.rb +18 -0
  19. data/lib/fog/internet_archive/parsers/storage/cors_configuration.rb +38 -0
  20. data/lib/fog/internet_archive/parsers/storage/delete_multiple_objects.rb +45 -0
  21. data/lib/fog/internet_archive/parsers/storage/get_bucket.rb +58 -0
  22. data/lib/fog/internet_archive/parsers/storage/get_bucket_lifecycle.rb +64 -0
  23. data/lib/fog/internet_archive/parsers/storage/get_bucket_location.rb +16 -0
  24. data/lib/fog/internet_archive/parsers/storage/get_bucket_logging.rb +36 -0
  25. data/lib/fog/internet_archive/parsers/storage/get_bucket_website.rb +22 -0
  26. data/lib/fog/internet_archive/parsers/storage/get_request_payment.rb +16 -0
  27. data/lib/fog/internet_archive/parsers/storage/get_service.rb +28 -0
  28. data/lib/fog/internet_archive/parsers/storage/initiate_multipart_upload.rb +20 -0
  29. data/lib/fog/internet_archive/parsers/storage/list_multipart_uploads.rb +52 -0
  30. data/lib/fog/internet_archive/parsers/storage/list_parts.rb +36 -0
  31. data/lib/fog/internet_archive/requests/storage/abort_multipart_upload.rb +27 -0
  32. data/lib/fog/internet_archive/requests/storage/acl_utils.rb +60 -0
  33. data/lib/fog/internet_archive/requests/storage/complete_multipart_upload.rb +46 -0
  34. data/lib/fog/internet_archive/requests/storage/copy_object.rb +77 -0
  35. data/lib/fog/internet_archive/requests/storage/cors_utils.rb +39 -0
  36. data/lib/fog/internet_archive/requests/storage/delete_bucket.rb +42 -0
  37. data/lib/fog/internet_archive/requests/storage/delete_bucket_cors.rb +26 -0
  38. data/lib/fog/internet_archive/requests/storage/delete_bucket_lifecycle.rb +26 -0
  39. data/lib/fog/internet_archive/requests/storage/delete_bucket_policy.rb +26 -0
  40. data/lib/fog/internet_archive/requests/storage/delete_bucket_website.rb +26 -0
  41. data/lib/fog/internet_archive/requests/storage/delete_multiple_objects.rb +88 -0
  42. data/lib/fog/internet_archive/requests/storage/delete_object.rb +46 -0
  43. data/lib/fog/internet_archive/requests/storage/get_bucket.rb +108 -0
  44. data/lib/fog/internet_archive/requests/storage/get_bucket_acl.rb +65 -0
  45. data/lib/fog/internet_archive/requests/storage/get_bucket_cors.rb +61 -0
  46. data/lib/fog/internet_archive/requests/storage/get_bucket_lifecycle.rb +35 -0
  47. data/lib/fog/internet_archive/requests/storage/get_bucket_location.rb +54 -0
  48. data/lib/fog/internet_archive/requests/storage/get_bucket_logging.rb +45 -0
  49. data/lib/fog/internet_archive/requests/storage/get_bucket_policy.rb +31 -0
  50. data/lib/fog/internet_archive/requests/storage/get_bucket_website.rb +38 -0
  51. data/lib/fog/internet_archive/requests/storage/get_object.rb +163 -0
  52. data/lib/fog/internet_archive/requests/storage/get_object_acl.rb +72 -0
  53. data/lib/fog/internet_archive/requests/storage/get_object_http_url.rb +48 -0
  54. data/lib/fog/internet_archive/requests/storage/get_object_https_url.rb +30 -0
  55. data/lib/fog/internet_archive/requests/storage/get_object_torrent.rb +45 -0
  56. data/lib/fog/internet_archive/requests/storage/get_object_url.rb +49 -0
  57. data/lib/fog/internet_archive/requests/storage/get_request_payment.rb +45 -0
  58. data/lib/fog/internet_archive/requests/storage/get_service.rb +50 -0
  59. data/lib/fog/internet_archive/requests/storage/head_object.rb +57 -0
  60. data/lib/fog/internet_archive/requests/storage/initiate_multipart_upload.rb +42 -0
  61. data/lib/fog/internet_archive/requests/storage/list_multipart_uploads.rb +52 -0
  62. data/lib/fog/internet_archive/requests/storage/list_parts.rb +53 -0
  63. data/lib/fog/internet_archive/requests/storage/post_object_hidden_fields.rb +36 -0
  64. data/lib/fog/internet_archive/requests/storage/put_bucket.rb +70 -0
  65. data/lib/fog/internet_archive/requests/storage/put_bucket_acl.rb +69 -0
  66. data/lib/fog/internet_archive/requests/storage/put_bucket_cors.rb +47 -0
  67. data/lib/fog/internet_archive/requests/storage/put_bucket_lifecycle.rb +76 -0
  68. data/lib/fog/internet_archive/requests/storage/put_bucket_logging.rb +79 -0
  69. data/lib/fog/internet_archive/requests/storage/put_bucket_policy.rb +25 -0
  70. data/lib/fog/internet_archive/requests/storage/put_bucket_website.rb +59 -0
  71. data/lib/fog/internet_archive/requests/storage/put_object.rb +94 -0
  72. data/lib/fog/internet_archive/requests/storage/put_object_acl.rb +73 -0
  73. data/lib/fog/internet_archive/requests/storage/put_object_url.rb +43 -0
  74. data/lib/fog/internet_archive/requests/storage/put_request_payment.rb +45 -0
  75. data/lib/fog/internet_archive/requests/storage/sync_clock.rb +24 -0
  76. data/lib/fog/internet_archive/requests/storage/upload_part.rb +39 -0
  77. data/lib/fog/internet_archive/signaturev4.rb +71 -0
  78. data/lib/fog/internet_archive/storage.rb +381 -0
  79. data/lib/fog/internet_archive/version.rb +5 -0
  80. data/tasks/bundler.rake +3 -0
  81. data/tasks/console.rake +17 -0
  82. data/tasks/lint.rake +3 -0
  83. data/tasks/test.rake +7 -0
  84. data/tests/helper.rb +36 -0
  85. data/tests/helpers/collection_helper.rb +88 -0
  86. data/tests/helpers/formats_helper.rb +98 -0
  87. data/tests/helpers/formats_helper_tests.rb +106 -0
  88. data/tests/helpers/mock_helper.rb +13 -0
  89. data/tests/helpers/model_helper.rb +29 -0
  90. data/tests/helpers/responds_to_helper.rb +11 -0
  91. data/tests/helpers/schema_validator_tests.rb +101 -0
  92. data/tests/helpers/succeeds_helper.rb +9 -0
  93. data/tests/internet_archive/models/storage/directory_tests.rb +42 -0
  94. data/tests/internet_archive/models/storage/file_tests.rb +61 -0
  95. data/tests/internet_archive/models/storage/files_tests.rb +60 -0
  96. data/tests/internet_archive/models/storage/url_tests.rb +28 -0
  97. data/tests/internet_archive/requests/storage/acl_utils_tests.rb +209 -0
  98. data/tests/internet_archive/requests/storage/bucket_tests.rb +324 -0
  99. data/tests/internet_archive/requests/storage/cors_utils_tests.rb +108 -0
  100. data/tests/internet_archive/requests/storage/multipart_upload_tests.rb +132 -0
  101. data/tests/internet_archive/requests/storage/object_tests.rb +166 -0
  102. data/tests/internet_archive/signaturev4_tests.rb +41 -0
  103. data/tests/internet_archive/signed_params_tests.rb +5 -0
  104. data/tests/lorem.txt +1 -0
  105. metadata +322 -0
@@ -0,0 +1,9 @@
1
+ module Shindo
2
+ class Tests
3
+ def succeeds
4
+ test("succeeds") do
5
+ !!instance_eval(&Proc.new)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,42 @@
1
+ Shindo.tests("Storage[:internet_archive] | directory", ["internetarchive"]) do
2
+
3
+ directory_attributes = {
4
+ :key => "fogdirectorytests-#{rand(65536)}",
5
+ :collections => ['test_collection']
6
+ }
7
+
8
+ tests('success') do
9
+ params = directory_attributes
10
+ mocks_implemented = Fog.mocking?
11
+
12
+ collection = Fog::Storage[:internetarchive].directories
13
+ @instance = collection.new(params)
14
+
15
+ tests("#save").succeeds do
16
+ pending if Fog.mocking? && !mocks_implemented
17
+ @instance.save
18
+ end
19
+
20
+ tests("#public_url").returns("http://archive.org/details/#{directory_attributes[:key]}") do
21
+ @instance.public_url
22
+ end
23
+
24
+ end
25
+
26
+ tests("#set_metadata_array_headers") do
27
+ params = directory_attributes
28
+
29
+ collection = Fog::Storage[:internetarchive].directories
30
+ @instance = collection.new(params)
31
+
32
+ @instance.collections = ['test_collection', 'opensource']
33
+ @options = {}
34
+ @instance.set_metadata_array_headers(:collections, @options)
35
+
36
+ tests("#set_metadata_array_headers should set options").returns(true) do
37
+ @options['x-archive-meta01-collection'] == 'opensource' &&
38
+ @options['x-archive-meta02-collection'] == 'test_collection'
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,61 @@
1
+ Shindo.tests("Storage[:internetarchive] | file", ["internetarchive"]) do
2
+
3
+ # Fog.mock!
4
+
5
+ require 'tempfile'
6
+
7
+ file_attributes = {
8
+ :key => 'fog_file_tests',
9
+ :body => lorem_file,
10
+ :public => true,
11
+ :auto_make_bucket => 1,
12
+ }
13
+
14
+ directory_attributes = {
15
+ # Add a random suffix to prevent collision
16
+ :key => "fogfilestests-#{rand(65536)}",
17
+ :collections => ['test_collection']
18
+ }
19
+
20
+ @directory = Fog::Storage[:internetarchive].directories.create(directory_attributes)
21
+
22
+ model_tests(@directory.files, file_attributes, Fog.mocking?) do
23
+
24
+ tests("#set_metadata_array_headers") do
25
+
26
+ @instance.collections = ['test_collection', 'opensource']
27
+ @options = {}
28
+ @instance.set_metadata_array_headers(:collections, @options)
29
+
30
+ tests("#set_metadata_array_headers should set options").returns(true) do
31
+ @options['x-archive-meta01-collection'] == 'opensource' &&
32
+ @options['x-archive-meta02-collection'] == 'test_collection'
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ model_tests(@directory.files, file_attributes, Fog.mocking?) do
39
+
40
+ tests("multipart upload") do
41
+ pending if Fog.mocking?
42
+
43
+ # A 6MB file
44
+ @large_file = Tempfile.new("fog-test-ia-s3-multipart")
45
+ 6.times { @large_file.write("x" * (1024**2)) }
46
+ @large_file.rewind
47
+
48
+ tests("#save(:multipart_chunk_size => 5242880)").succeeds do
49
+ @directory.files.create(:key => 'multipart-upload', :body => @large_file, :multipart_chunk_size => 5242880)
50
+ end
51
+
52
+ @large_file.close
53
+
54
+ end
55
+
56
+ end
57
+
58
+ # @directory.versions.each(&:destroy)
59
+ @directory.destroy
60
+
61
+ end
@@ -0,0 +1,60 @@
1
+ Shindo.tests("Storage[:internetarchive] | files", ["internetarchive"]) do
2
+
3
+ file_attributes = {
4
+ :key => 'fog_file_tests',
5
+ :body => lorem_file,
6
+ :public => true,
7
+ :auto_make_bucket => 1,
8
+ :collections => ['test_collection']
9
+ }
10
+
11
+ directory_attributes = {
12
+ :key => "fogfilestests-#{rand(65536)}"
13
+ }
14
+
15
+ @directory = Fog::Storage[:internetarchive].directories.create(directory_attributes)
16
+ # @directory.versioning = true
17
+
18
+ collection_tests(@directory.files, file_attributes, Fog.mocking?)
19
+
20
+ model_tests(@directory.files, file_attributes, Fog.mocking?) do
21
+
22
+ @instance
23
+ # v2 = @directory.connection.put_object(@directory.key, @instance.key, 'version 2 content').headers['x-amz-version-id']
24
+ # v3 = @directory.connection.delete_object(@directory.key, @instance.key).headers['x-amz-version-id']
25
+ # v4 = @directory.connection.put_object(@directory.key, @instance.key, 'version 3 content').headers['x-amz-version-id']
26
+
27
+ # tests("#get") do
28
+ # tests("#get without version fetches the latest version").returns(v4) do
29
+ # @directory.files.get(@instance.key).version
30
+ # end
31
+
32
+ # tests("#get with version fetches that exact version").returns(v2) do
33
+ # @directory.files.get(@instance.key, 'versionId' => v2).version
34
+ # end
35
+
36
+ # tests("#get with a deleted version returns nil").returns(nil) do
37
+ # @directory.files.get(@instance.key, 'versionId' => v3)
38
+ # end
39
+ # end
40
+
41
+ # tests("#head") do
42
+ # tests("#head without version fetches the latest version").returns(v4) do
43
+ # @directory.files.head(@instance.key).version
44
+ # end
45
+
46
+ # tests("#head with version fetches that exact version").returns(v2) do
47
+ # @directory.files.head(@instance.key, 'versionId' => v2).version
48
+ # end
49
+
50
+ # tests("#head with a deleted version returns nil").returns(nil) do
51
+ # @directory.files.head(@instance.key, 'versionId' => v3)
52
+ # end
53
+ # end
54
+
55
+ end
56
+
57
+ # @directory.versions.each(&:destroy)
58
+ # @directory.destroy
59
+
60
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ Shindo.tests('InternetArchive | url', ["internetarchive"]) do
4
+
5
+ @expires = Time.utc(2013,1,1).utc.to_i
6
+
7
+ @storage = Fog::Storage.new(
8
+ :provider => 'InternetArchive',
9
+ :ia_access_key_id => '123',
10
+ :ia_secret_access_key => 'abc',
11
+ :region => 'us-east-1'
12
+ )
13
+
14
+ @file = @storage.directories.new(:key => 'fognonbucket').files.new(:key => 'test.txt')
15
+
16
+ if Fog.mock?
17
+ signature = Fog::Storage::InternetArchive.new.signature(nil)
18
+ else
19
+ signature = 'tajHIhKHAdFYsigmzybCpaq8N0Q%3D'
20
+ end
21
+
22
+ tests('#url w/ response-cache-control').returns(
23
+ "http://fognonbucket.s3.us.archive.org/test.txt?response-cache-control=No-cache&AWSAccessKeyId=123&Signature=#{signature}&Expires=1356998400"
24
+ ) do
25
+ @file.url(@expires, :query => { 'response-cache-control' => 'No-cache' })
26
+ end
27
+
28
+ end
@@ -0,0 +1,209 @@
1
+ require 'fog/internet_archive/requests/storage/acl_utils'
2
+
3
+ Shindo.tests('Fog::Storage::InternetArchive | ACL utils', ["internetarchive"]) do
4
+ tests(".hash_to_acl") do
5
+ tests(".hash_to_acl({}) at xpath //AccessControlPolicy").returns("", "has an empty AccessControlPolicy") do
6
+ xml = Fog::Storage::InternetArchive.hash_to_acl({})
7
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy").first.content.chomp
8
+ end
9
+
10
+ tests(".hash_to_acl({}) at xpath //AccessControlPolicy/Owner").returns(nil, "does not have an Owner element") do
11
+ xml = Fog::Storage::InternetArchive.hash_to_acl({})
12
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/Owner").first
13
+ end
14
+
15
+ tests(".hash_to_acl('Owner' => {}) at xpath //AccessControlPolicy/Owner").returns(nil, "does not have an Owner element") do
16
+ xml = Fog::Storage::InternetArchive.hash_to_acl('Owner' => {})
17
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/Owner").first
18
+ end
19
+
20
+ tests(".hash_to_acl('Owner' => {'ID' => 'abcdef0123456789'}) at xpath //AccessControlPolicy/Owner/ID").returns("abcdef0123456789", "returns the Owner ID") do
21
+ xml = Fog::Storage::InternetArchive.hash_to_acl('Owner' => {'ID' => 'abcdef0123456789'})
22
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/Owner/ID").first.content
23
+ end
24
+
25
+ tests(".hash_to_acl('Owner' => {'DisplayName' => 'bob'}) at xpath //AccessControlPolicy/Owner/ID").returns(nil, "does not have an Owner ID element") do
26
+ xml = Fog::Storage::InternetArchive.hash_to_acl('Owner' => {'DisplayName' => 'bob'})
27
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/Owner/ID").first
28
+ end
29
+
30
+ tests(".hash_to_acl('Owner' => {'DisplayName' => 'bob'}) at xpath //AccessControlPolicy/Owner/DisplayName").returns("bob", "returns the Owner DisplayName") do
31
+ xml = Fog::Storage::InternetArchive.hash_to_acl('Owner' => {'DisplayName' => 'bob'})
32
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/Owner/DisplayName").first.content
33
+ end
34
+
35
+ tests(".hash_to_acl('Owner' => {'ID' => 'abcdef0123456789'}) at xpath //AccessControlPolicy/Owner/DisplayName").returns(nil, "does not have an Owner DisplayName element") do
36
+ xml = Fog::Storage::InternetArchive.hash_to_acl('Owner' => {'ID' => 'abcdef0123456789'})
37
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/Owner/DisplayName").first
38
+ end
39
+
40
+ tests(".hash_to_acl({}) at xpath //AccessControlPolicy/AccessControlList").returns(nil, "has no AccessControlList") do
41
+ xml = Fog::Storage::InternetArchive.hash_to_acl({})
42
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlPolicy").first
43
+ end
44
+
45
+ acl = {
46
+ 'AccessControlList' => [
47
+ {
48
+ 'Grantee' => {
49
+ 'ID' => 'abcdef0123456789',
50
+ 'DisplayName' => 'bob'
51
+ },
52
+ 'Permission' => 'READ'
53
+ }
54
+ ]
55
+ }
56
+
57
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Grantee").returns("CanonicalUser", "has an xsi:type of CanonicalUser") do
58
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
59
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Grantee").first.attributes["type"].value
60
+ end
61
+
62
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Grantee/ID").returns("abcdef0123456789", "returns the Grantee ID") do
63
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
64
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Grantee/ID").first.content
65
+ end
66
+
67
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Grantee/DisplayName").returns("bob", "returns the Grantee DisplayName") do
68
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
69
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Grantee/DisplayName").first.content
70
+ end
71
+
72
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Permission").returns("READ", "returns the Grantee Permission") do
73
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
74
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Permission").first.content
75
+ end
76
+
77
+ acl = {
78
+ 'AccessControlList' => [
79
+ {
80
+ 'Grantee' => {
81
+ 'EmailAddress' => 'user@example.com'
82
+ },
83
+ 'Permission' => 'FULL_CONTROL'
84
+ }
85
+ ]
86
+ }
87
+
88
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Grantee").returns("AmazonCustomerByEmail", "has an xsi:type of AmazonCustomerByEmail") do
89
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
90
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Grantee").first.attributes["type"].value
91
+ end
92
+
93
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Grantee/EmailAddress").returns("user@example.com", "returns the Grantee EmailAddress") do
94
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
95
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Grantee/EmailAddress").first.content
96
+ end
97
+
98
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Permission").returns("FULL_CONTROL", "returns the Grantee Permission") do
99
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
100
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Permission").first.content
101
+ end
102
+
103
+ acl = {
104
+ 'AccessControlList' => [
105
+ {
106
+ 'Grantee' => {
107
+ 'URI' => 'http://acs.amazonaws.com/groups/global/AllUsers'
108
+ },
109
+ 'Permission' => 'WRITE'
110
+ }
111
+ ]
112
+ }
113
+
114
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Grantee").returns("Group", "has an xsi:type of Group") do
115
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
116
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Grantee").first.attributes["type"].value
117
+ end
118
+
119
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Grantee/URI").returns("http://acs.amazonaws.com/groups/global/AllUsers", "returns the Grantee URI") do
120
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
121
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Grantee/URI").first.content
122
+ end
123
+
124
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Permission").returns("WRITE", "returns the Grantee Permission") do
125
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
126
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Permission").first.content
127
+ end
128
+
129
+ acl = {
130
+ 'AccessControlList' => [
131
+ {
132
+ 'Grantee' => {
133
+ 'ID' => 'abcdef0123456789',
134
+ 'DisplayName' => 'bob'
135
+ },
136
+ 'Permission' => 'READ'
137
+ },
138
+ {
139
+ 'Grantee' => {
140
+ 'EmailAddress' => 'user@example.com'
141
+ },
142
+ 'Permission' => 'FULL_CONTROL'
143
+ },
144
+ {
145
+ 'Grantee' => {
146
+ 'URI' => 'http://acs.amazonaws.com/groups/global/AllUsers'
147
+ },
148
+ 'Permission' => 'WRITE'
149
+ }
150
+ ]
151
+ }
152
+
153
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant").returns(3, "has three elements") do
154
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
155
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant").size
156
+ end
157
+
158
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Grantee/ID").returns("abcdef0123456789", "returns the first Grant's Grantee ID") do
159
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
160
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Grantee/ID").first.content
161
+ end
162
+
163
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Grantee/EmailAddress").returns("user@example.com", "returns the second Grant's Grantee EmailAddress") do
164
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
165
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Grantee/EmailAddress").first.content
166
+ end
167
+
168
+ tests(".hash_to_acl(#{acl.inspect}) at xpath //AccessControlPolicy/AccessControlList/Grant/Grantee/URI").returns("http://acs.amazonaws.com/groups/global/AllUsers", "returns the third Grant's Grantee URI") do
169
+ xml = Fog::Storage::InternetArchive.hash_to_acl(acl)
170
+ Nokogiri::XML(xml).xpath("//AccessControlPolicy/AccessControlList/Grant/Grantee/URI").first.content
171
+ end
172
+ end
173
+
174
+ tests(".acl_to_hash") do
175
+ acl_xml = <<-XML
176
+ <AccessControlPolicy>
177
+ <Owner>
178
+ <ID>2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0</ID>
179
+ <DisplayName>me</DisplayName>
180
+ </Owner>
181
+ <AccessControlList>
182
+ <Grant>
183
+ <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
184
+ <ID>2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0</ID>
185
+ <DisplayName>me</DisplayName>
186
+ </Grantee>
187
+ <Permission>FULL_CONTROL</Permission>
188
+ </Grant>
189
+ </AccessControlList>
190
+ </AccessControlPolicy>
191
+ XML
192
+
193
+ tests(".acl_to_hash(#{acl_xml.inspect})").returns({
194
+ "Owner" => {
195
+ "DisplayName" => "me",
196
+ "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"
197
+ },
198
+ "AccessControlList" => [{
199
+ "Grantee" => {
200
+ "DisplayName" => "me",
201
+ "ID" => "2744ccd10c7533bd736ad890f9dd5cab2adb27b07d500b9493f29cdc420cb2e0"
202
+ },
203
+ "Permission" => "FULL_CONTROL"
204
+ }]
205
+ }, 'returns hash of ACL XML') do
206
+ Fog::Storage::InternetArchive.acl_to_hash(acl_xml)
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,324 @@
1
+ Shindo.tests('Fog::Storage[:internetarchive] | bucket requests', ["internetarchive"]) do
2
+ @ia_bucket_name = 'fogbuckettests-' + Time.now.to_i.to_s(32)
3
+
4
+ tests('success') do
5
+
6
+ @bucket_format = {
7
+ 'CommonPrefixes' => [],
8
+ 'IsTruncated' => Fog::Boolean,
9
+ 'Marker' => NilClass,
10
+ 'MaxKeys' => Integer,
11
+ 'Name' => String,
12
+ 'Prefix' => NilClass,
13
+ 'Contents' => [{
14
+ 'ETag' => String,
15
+ 'Key' => String,
16
+ 'LastModified' => Time,
17
+ 'Owner' => {
18
+ 'DisplayName' => String,
19
+ 'ID' => String
20
+ },
21
+ 'Size' => Integer
22
+ }]
23
+ }
24
+ @bucket_lifecycle_format = {
25
+ 'Rules' => [{
26
+ 'ID' => String,
27
+ 'Prefix' => Fog::Nullable::String,
28
+ 'Enabled' => Fog::Boolean,
29
+ 'Expiration' => Fog::Nullable::Hash,
30
+ 'Transition' => Fog::Nullable::Hash
31
+ }]
32
+ }
33
+
34
+ @service_format = {
35
+ 'Buckets' => [{
36
+ 'CreationDate' => Time,
37
+ 'Name' => String,
38
+ }],
39
+ 'Owner' => {
40
+ 'DisplayName' => String,
41
+ 'ID' => String
42
+ }
43
+ }
44
+
45
+ tests("#put_bucket('#{@ia_bucket_name}')").succeeds do
46
+ Fog::Storage[:internetarchive].put_bucket(@ia_bucket_name)
47
+ @aws_owner = Fog::Storage[:internetarchive].get_bucket_acl(Fog::Storage[:internetarchive].directories.first.key).body['Owner']
48
+ end
49
+
50
+ tests("#get_service").formats(@service_format) do
51
+ Fog::Storage[:internetarchive].get_service.body
52
+ end
53
+
54
+ dirs = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name)
55
+ file = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'y', :key => 'x')
56
+
57
+ tests("#get_bucket('#{@ia_bucket_name}')").formats(@bucket_format) do
58
+ Fog::Storage[:internetarchive].get_bucket(@ia_bucket_name).body
59
+ end
60
+
61
+ file.destroy
62
+
63
+ file1 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'a', :key => 'a/a1/file1')
64
+ file2 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'ab', :key => 'a/file2')
65
+ file3 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'abc', :key => 'b/file3')
66
+ file4 = Fog::Storage[:internetarchive].directories.get(@ia_bucket_name).files.create(:body => 'abcd', :key => 'file4')
67
+
68
+ tests("#get_bucket('#{@ia_bucket_name}')") do
69
+ before do
70
+ @bucket = Fog::Storage[:internetarchive].get_bucket(@ia_bucket_name)
71
+ end
72
+
73
+ tests(".body['Contents'].map{|n| n['Key']}").returns(["a/a1/file1", "a/file2", "b/file3", "file4"]) do
74
+ @bucket.body['Contents'].map{|n| n['Key']}
75
+ end
76
+
77
+ tests(".body['Contents'].map{|n| n['Size']}").returns([1, 2, 3, 4]) do
78
+ @bucket.body['Contents'].map{|n| n['Size']}
79
+ end
80
+
81
+ tests(".body['CommonPrefixes']").returns([]) do
82
+ @bucket.body['CommonPrefixes']
83
+ end
84
+ end
85
+
86
+ tests("#get_bucket('#{@ia_bucket_name}', 'delimiter' => '/')") do
87
+ before do
88
+ @bucket = Fog::Storage[:internetarchive].get_bucket(@ia_bucket_name, 'delimiter' => '/')
89
+ end
90
+
91
+ tests(".body['Contents'].map{|n| n['Key']}").returns(['file4']) do
92
+ @bucket.body['Contents'].map{|n| n['Key']}
93
+ end
94
+
95
+ tests(".body['CommonPrefixes']").returns(['a/', 'b/']) do
96
+ @bucket.body['CommonPrefixes']
97
+ end
98
+ end
99
+
100
+ tests("#get_bucket('#{@ia_bucket_name}', 'delimiter' => '/', 'prefix' => 'a/')") do
101
+ before do
102
+ @bucket = Fog::Storage[:internetarchive].get_bucket(@ia_bucket_name, 'delimiter' => '/', 'prefix' => 'a/')
103
+ end
104
+
105
+ tests(".body['Contents'].map{|n| n['Key']}").returns(['a/file2']) do
106
+ @bucket.body['Contents'].map{|n| n['Key']}
107
+ end
108
+
109
+ tests(".body['CommonPrefixes']").returns(['a/a1/']) do
110
+ @bucket.body['CommonPrefixes']
111
+ end
112
+ end
113
+
114
+ file1.destroy; file2.destroy; file3.destroy; file4.destroy
115
+
116
+ tests("#get_bucket_location('#{@ia_bucket_name}')").formats('LocationConstraint' => NilClass) do
117
+ Fog::Storage[:internetarchive].get_bucket_location(@ia_bucket_name).body
118
+ end
119
+
120
+ tests("#get_request_payment('#{@ia_bucket_name}')").formats('Payer' => String) do
121
+ Fog::Storage[:internetarchive].get_request_payment(@ia_bucket_name).body
122
+ end
123
+
124
+ tests("#put_request_payment('#{@ia_bucket_name}', 'Requester')").succeeds do
125
+ Fog::Storage[:internetarchive].put_request_payment(@ia_bucket_name, 'Requester')
126
+ end
127
+
128
+ tests("#put_bucket_website('#{@ia_bucket_name}', 'index.html')").succeeds do
129
+ Fog::Storage[:internetarchive].put_bucket_website(@ia_bucket_name, 'index.html')
130
+ end
131
+
132
+ tests("#put_bucket_acl('#{@ia_bucket_name}', 'private')").succeeds do
133
+ Fog::Storage[:internetarchive].put_bucket_acl(@ia_bucket_name, 'private')
134
+ end
135
+
136
+ acl = {
137
+ 'Owner' => @aws_owner,
138
+ 'AccessControlList' => [
139
+ {
140
+ 'Grantee' => @aws_owner,
141
+ 'Permission' => "FULL_CONTROL"
142
+ }
143
+ ]
144
+ }
145
+ tests("#put_bucket_acl('#{@ia_bucket_name}', hash with id)").returns(acl) do
146
+ Fog::Storage[:internetarchive].put_bucket_acl(@ia_bucket_name, acl)
147
+ Fog::Storage[:internetarchive].get_bucket_acl(@ia_bucket_name).body
148
+ end
149
+
150
+ tests("#put_bucket_acl('#{@ia_bucket_name}', hash with email)").returns({
151
+ 'Owner' => @aws_owner,
152
+ 'AccessControlList' => [
153
+ {
154
+ 'Grantee' => { 'ID' => 'f62f0218873cfa5d56ae9429ae75a592fec4fd22a5f24a20b1038a7db9a8f150', 'DisplayName' => 'mtd' },
155
+ 'Permission' => "FULL_CONTROL"
156
+ }
157
+ ]
158
+ }) do
159
+ pending if Fog.mocking?
160
+ Fog::Storage[:internetarchive].put_bucket_acl(@ia_bucket_name, {
161
+ 'Owner' => @aws_owner,
162
+ 'AccessControlList' => [
163
+ {
164
+ 'Grantee' => { 'EmailAddress' => 'mtd@amazon.com' },
165
+ 'Permission' => "FULL_CONTROL"
166
+ }
167
+ ]
168
+ })
169
+ Fog::Storage[:internetarchive].get_bucket_acl(@ia_bucket_name).body
170
+ end
171
+
172
+ acl = {
173
+ 'Owner' => @aws_owner,
174
+ 'AccessControlList' => [
175
+ {
176
+ 'Grantee' => { 'URI' => 'http://acs.amazonaws.com/groups/global/AllUsers' },
177
+ 'Permission' => "FULL_CONTROL"
178
+ }
179
+ ]
180
+ }
181
+ tests("#put_bucket_acl('#{@ia_bucket_name}', hash with uri)").returns(acl) do
182
+ Fog::Storage[:internetarchive].put_bucket_acl(@ia_bucket_name, acl)
183
+ Fog::Storage[:internetarchive].get_bucket_acl(@ia_bucket_name).body
184
+ end
185
+
186
+ tests("#delete_bucket_website('#{@ia_bucket_name}')").succeeds do
187
+ pending if Fog.mocking?
188
+ Fog::Storage[:internetarchive].delete_bucket_website(@ia_bucket_name)
189
+ end
190
+
191
+ tests('bucket lifecycle') do
192
+ pending if Fog.mocking?
193
+
194
+ lifecycle = {'Rules' => [{'ID' => 'test rule', 'Prefix' => '/prefix', 'Enabled' => true, 'Days' => 42}]}
195
+ tests('non-existant bucket') do
196
+ tests('#put_bucket_lifecycle').returns([404, 'NoSuchBucket']) do
197
+ begin
198
+ Fog::Storage[:internetarchive].put_bucket_lifecycle('fognonbucket', lifecycle)
199
+ rescue Excon::Errors::NotFound => e
200
+ [e.response.status, e.response.body.match(%r{<Code>(.*)</Code>})[1]]
201
+ end
202
+ end
203
+ tests('#get_bucket_lifecycle').returns([404, 'NoSuchBucket']) do
204
+ begin
205
+ Fog::Storage[:internetarchive].get_bucket_lifecycle('fognonbucket')
206
+ rescue Excon::Errors::NotFound => e
207
+ [e.response.status, e.response.body.match(%r{<Code>(.*)</Code>})[1]]
208
+ end
209
+ end
210
+ tests('#delete_bucket_lifecycle').returns([404, 'NoSuchBucket']) do
211
+ begin
212
+ Fog::Storage[:internetarchive].delete_bucket_lifecycle('fognonbucket')
213
+ rescue Excon::Errors::NotFound => e
214
+ [e.response.status, e.response.body.match(%r{<Code>(.*)</Code>})[1]]
215
+ end
216
+ end
217
+ end
218
+ tests('no lifecycle') do
219
+ tests('#get_bucket_lifecycle').returns([404, 'NoSuchLifecycleConfiguration']) do
220
+ begin
221
+ Fog::Storage[:internetarchive].get_bucket_lifecycle(@ia_bucket_name)
222
+ rescue Excon::Errors::NotFound => e
223
+ [e.response.status, e.response.body.match(%r{<Code>(.*)</Code>})[1]]
224
+ end
225
+ end
226
+ tests('#delete_bucket_lifecycle').succeeds do
227
+ Fog::Storage[:internetarchive].delete_bucket_lifecycle(@ia_bucket_name)
228
+ end
229
+ end
230
+ tests('create').succeeds do
231
+ Fog::Storage[:internetarchive].put_bucket_lifecycle(@ia_bucket_name, lifecycle)
232
+ end
233
+ tests('read').formats(@bucket_lifecycle_format) do
234
+ Fog::Storage[:internetarchive].get_bucket_lifecycle(@ia_bucket_name).body
235
+ end
236
+ lifecycle = { 'Rules' => 5.upto(6).map { |i| {'ID' => "rule\##{i}", 'Prefix' => i.to_s, 'Enabled' => true, 'Days' => i} } }
237
+ lifecycle_return = { 'Rules' => 5.upto(6).map { |i| {'ID' => "rule\##{i}", 'Prefix' => i.to_s, 'Enabled' => true, 'Expiration' => {'Days' => i}} } }
238
+ tests('update').returns(lifecycle_return) do
239
+ Fog::Storage[:internetarchive].put_bucket_lifecycle(@ia_bucket_name, lifecycle)
240
+ Fog::Storage[:internetarchive].get_bucket_lifecycle(@ia_bucket_name).body
241
+ end
242
+ lifecycle = {'Rules' => [{'ID' => 'test rule', 'Prefix' => '/prefix', 'Enabled' => true, 'Expiration' => {'Date' => '2012-12-31T00:00:00.000Z'}}]}
243
+ tests('date').returns(lifecycle) do
244
+ Fog::Storage[:internetarchive].put_bucket_lifecycle(@ia_bucket_name, lifecycle)
245
+ Fog::Storage[:internetarchive].get_bucket_lifecycle(@ia_bucket_name).body
246
+ end
247
+ tests('delete').succeeds do
248
+ Fog::Storage[:internetarchive].delete_bucket_lifecycle(@ia_bucket_name)
249
+ end
250
+ tests('read').returns([404, 'NoSuchLifecycleConfiguration']) do
251
+ begin
252
+ Fog::Storage[:internetarchive].get_bucket_lifecycle(@ia_bucket_name)
253
+ rescue Excon::Errors::NotFound => e
254
+ [e.response.status, e.response.body.match(%r{<Code>(.*)</Code>})[1]]
255
+ end
256
+ end
257
+ end
258
+
259
+ tests("put_bucket_cors('#{@ia_bucket_name}', cors)").succeeds do
260
+ cors = {'CORSConfiguration' =>
261
+ [
262
+ {
263
+ 'AllowedOrigin' => 'http://localhost:3000',
264
+ 'AllowedMethod' => ['POST', 'GET'],
265
+ 'AllowedHeader' => '*',
266
+ 'MaxAgeSeconds' => 3000
267
+ }
268
+ ]
269
+ }
270
+ Fog::Storage[:internetarchive].put_bucket_cors(@ia_bucket_name, cors)
271
+ end
272
+
273
+ tests("#delete_bucket('#{@ia_bucket_name}')").succeeds do
274
+ Fog::Storage[:internetarchive].delete_bucket(@ia_bucket_name)
275
+ end
276
+
277
+ end
278
+
279
+ # tests('failure') do
280
+
281
+ # tests("#delete_bucket('fognonbucket')").raises(Excon::Errors::NotFound) do
282
+ # Fog::Storage[:internetarchive].delete_bucket('fognonbucket')
283
+ # end
284
+
285
+ # @fognonempty = "fognonempty-#{rand(65536)}"
286
+ # @bucket = Fog::Storage[:internetarchive].directories.create(:key => "fognonempty-#{rand(65536)}")
287
+ # @file = @bucket.files.create(:key => 'foo', :body => 'bar')
288
+
289
+ # tests("#delete_bucket('fognonempty')").raises(Excon::Errors::Conflict) do
290
+ # Fog::Storage[:internetarchive].delete_bucket('fognonempty')
291
+ # end
292
+
293
+ # @file.destroy
294
+ # @bucket.destroy
295
+
296
+ # tests("#get_bucket('fognonbucket')").raises(Excon::Errors::NotFound) do
297
+ # Fog::Storage[:internetarchive].get_bucket('fognonbucket')
298
+ # end
299
+
300
+ # tests("#get_bucket_location('fognonbucket')").raises(Excon::Errors::NotFound) do
301
+ # Fog::Storage[:internetarchive].get_bucket_location('fognonbucket')
302
+ # end
303
+
304
+ # tests("#get_request_payment('fognonbucket')").raises(Excon::Errors::NotFound) do
305
+ # Fog::Storage[:internetarchive].get_request_payment('fognonbucket')
306
+ # end
307
+
308
+ # tests("#put_request_payment('fognonbucket', 'Requester')").raises(Excon::Errors::NotFound) do
309
+ # Fog::Storage[:internetarchive].put_request_payment('fognonbucket', 'Requester')
310
+ # end
311
+
312
+ # tests("#put_bucket_acl('fognonbucket', 'invalid')").raises(Excon::Errors::BadRequest) do
313
+ # Fog::Storage[:internetarchive].put_bucket_acl('fognonbucket', 'invalid')
314
+ # end
315
+
316
+ # tests("#put_bucket_website('fognonbucket', 'index.html')").raises(Excon::Errors::NotFound) do
317
+ # Fog::Storage[:internetarchive].put_bucket_website('fognonbucket', 'index.html')
318
+ # end
319
+
320
+ # end
321
+
322
+ # don't keep the bucket around
323
+ # Fog::Storage[:internetarchive].delete_bucket(@ia_bucket_name) rescue nil
324
+ end