s3 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/s3.rb +1 -0
- data/lib/s3/bucket.rb +26 -21
- data/lib/s3/connection.rb +49 -43
- data/lib/s3/exceptions.rb +12 -10
- data/lib/s3/object.rb +36 -19
- data/lib/s3/service.rb +28 -23
- data/lib/s3/signature.rb +47 -21
- data/test/bucket_test.rb +57 -55
- data/test/connection_test.rb +20 -19
- data/test/object_test.rb +23 -24
- data/test/service_test.rb +30 -29
- data/test/signature_test.rb +8 -8
- data/test/test_helper.rb +4 -8
- metadata +9 -9
data/test/object_test.rb
CHANGED
@@ -13,7 +13,7 @@ class ObjectTest < Test::Unit::TestCase
|
|
13
13
|
@object_carmen = S3::Object.send(:new, @bucket_images, :key => "Carmen.png")
|
14
14
|
|
15
15
|
@response_binary = Net::HTTPOK.new("1.1", "200", "OK")
|
16
|
-
|
16
|
+
@response_binary.stubs(:body).returns("test".force_encoding(Encoding::BINARY))
|
17
17
|
@response_binary["etag"] = ""
|
18
18
|
@response_binary["content-type"] = "image/png"
|
19
19
|
@response_binary["content-disposition"] = "inline"
|
@@ -26,10 +26,10 @@ class ObjectTest < Test::Unit::TestCase
|
|
26
26
|
<CopyObjectResult> <LastModified>timestamp</LastModified> <ETag>"etag"</ETag> </CopyObjectResult>
|
27
27
|
EOXML
|
28
28
|
@response_xml = Net::HTTPOK.new("1.1", "200", "OK")
|
29
|
-
|
29
|
+
@response_xml.stubs(:body).returns(@xml_body)
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
test "initializing" do
|
33
33
|
assert_raise ArgumentError do S3::Object.send(:new, nil, :key => "") end # should not allow empty key
|
34
34
|
assert_raise ArgumentError do S3::Object.send(:new, nil, :key => "//") end # should not allow key with double slash
|
35
35
|
|
@@ -41,13 +41,13 @@ class ObjectTest < Test::Unit::TestCase
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
test "full key" do
|
45
45
|
expected = "images/Lena.png"
|
46
46
|
actual = @object_lena.full_key
|
47
47
|
assert_equal expected, actual
|
48
48
|
end
|
49
49
|
|
50
|
-
|
50
|
+
test "url" do
|
51
51
|
bucket1 = S3::Bucket.send(:new, @service, "images")
|
52
52
|
|
53
53
|
object11 = S3::Object.send(:new, bucket1, :key => "Lena.png")
|
@@ -68,7 +68,7 @@ class ObjectTest < Test::Unit::TestCase
|
|
68
68
|
assert_equal expected, actual
|
69
69
|
end
|
70
70
|
|
71
|
-
|
71
|
+
test "cname url" do
|
72
72
|
bucket1 = S3::Bucket.send(:new, @service, "images.example.com")
|
73
73
|
|
74
74
|
object11 = S3::Object.send(:new, bucket1, :key => "Lena.png")
|
@@ -89,45 +89,44 @@ class ObjectTest < Test::Unit::TestCase
|
|
89
89
|
assert_equal expected, actual
|
90
90
|
end
|
91
91
|
|
92
|
-
|
93
|
-
|
92
|
+
test "destroy" do
|
93
|
+
@object_lena.expects(:object_request).with(:delete)
|
94
94
|
assert @object_lena.destroy
|
95
95
|
end
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
|
97
|
+
test "save" do
|
98
|
+
@object_lena.expects(:object_request).with(:put, :body=>"test", :headers=>{ :x_amz_acl=>"public-read", :content_type=>"application/octet-stream" }).returns(@response_binary)
|
100
99
|
assert @object_lena.save
|
101
100
|
end
|
102
101
|
|
103
|
-
|
104
|
-
|
102
|
+
test "content and parse headers" do
|
103
|
+
@object_lena.expects(:object_request).with(:get, {}).returns(@response_binary)
|
105
104
|
|
106
105
|
expected = /test/n
|
107
|
-
actual = @object_lena.content(true)
|
106
|
+
actual = @object_lena.content(true)
|
108
107
|
assert_match expected, actual
|
109
108
|
assert_equal "image/png", @object_lena.content_type
|
110
109
|
|
111
|
-
stub(@object_lena).object_request(:get) { flunk "should not use connection" }
|
112
|
-
|
113
110
|
assert @object_lena.content
|
111
|
+
|
112
|
+
@object_lena.expects(:object_request).with(:get, {}).returns(@response_binary)
|
114
113
|
assert @object_lena.content(true)
|
115
114
|
end
|
116
115
|
|
117
|
-
|
118
|
-
|
116
|
+
test "retrieve" do
|
117
|
+
@object_lena.expects(:object_request).with(:get, :headers=>{:range=>0..0}).returns(@response_binary)
|
119
118
|
assert @object_lena.retrieve
|
120
119
|
end
|
121
120
|
|
122
|
-
|
123
|
-
|
121
|
+
test "exists" do
|
122
|
+
@object_lena.expects(:retrieve).returns(true)
|
124
123
|
assert @object_lena.exists?
|
125
124
|
|
126
|
-
|
125
|
+
@object_carmen.expects(:retrieve).raises(S3::Error::NoSuchKey.new(nil, nil))
|
127
126
|
assert ! @object_carmen.exists?
|
128
127
|
end
|
129
128
|
|
130
|
-
|
129
|
+
test "ACL writer" do
|
131
130
|
expected = nil
|
132
131
|
actual = @object_lena.acl
|
133
132
|
assert_equal expected, actual
|
@@ -145,8 +144,8 @@ class ObjectTest < Test::Unit::TestCase
|
|
145
144
|
assert_equal expected, actual
|
146
145
|
end
|
147
146
|
|
148
|
-
|
149
|
-
|
147
|
+
test "copy" do
|
148
|
+
@bucket_images.expects(:bucket_request).with(:put, :path => "Lena-copy.png", :headers => { :x_amz_acl => "public-read", :content_type => "application/octet-stream", :x_amz_copy_source => "images/Lena.png", :x_amz_metadata_directive => "REPLACE" }).returns(@response_xml)
|
150
149
|
|
151
150
|
new_object = @object_lena.copy(:key => "Lena-copy.png")
|
152
151
|
|
data/test/service_test.rb
CHANGED
@@ -2,37 +2,49 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class ServiceTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
+
@buckets_list_body = <<-EOBuckets
|
6
|
+
<?xml version="1.0" encoding="UTF-8"?>\n<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Owner> <ID>123u1odhkhfoadf</ID> <DisplayName>JohnDoe</DisplayName> </Owner> <Buckets> <Bucket> <Name>data.example.com</Name> <CreationDate>2009-07-02T11:56:58.000Z</CreationDate> </Bucket> <Bucket> <Name>images</Name> <CreationDate>2009-06-05T12:26:33.000Z</CreationDate> </Bucket> </Buckets> </ListAllMyBucketsResult>
|
7
|
+
EOBuckets
|
8
|
+
|
9
|
+
@bucket_not_exists = <<-EOBucketNoexists
|
10
|
+
<?xml version="1.0" encoding="UTF-8"?>\n<Error> <Code>NoSuchBucket</Code> <Message>The specified bucket does not exists</Message> <BucketName>data2.example.com</BucketName> <RequestId>8D7519AAE74E9E99</RequestId> <HostId>DvKnnNSMnPHd1oXukyRaFNv8Lg/bpwhuUtY8Kj7eDLbaIrIT8JebSnHwi89AK1P+</HostId> </Error>
|
11
|
+
EOBucketNoexists
|
12
|
+
|
13
|
+
@bucket_exists = <<-EOBucketexists
|
14
|
+
<?xml version="1.0" encoding="UTF-8"?>\n<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Name>data.synergypeople.net</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> </ListBucketResult>
|
15
|
+
EOBucketexists
|
16
|
+
|
5
17
|
@service_empty_buckets_list = S3::Service.new(
|
6
18
|
:access_key_id => "12345678901234567890",
|
7
19
|
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
8
20
|
)
|
9
21
|
@response_empty_buckets_list = Net::HTTPOK.new("1.1", "200", "OK")
|
10
|
-
|
11
|
-
|
22
|
+
@service_empty_buckets_list.stubs(:service_request).returns(@response_empty_buckets_list)
|
23
|
+
@response_empty_buckets_list.stubs(:body).returns(@buckets_empty_list_body)
|
12
24
|
|
13
25
|
@service_buckets_list = S3::Service.new(
|
14
26
|
:access_key_id => "12345678901234567890",
|
15
27
|
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
16
28
|
)
|
17
29
|
@response_buckets_list = Net::HTTPOK.new("1.1", "200", "OK")
|
18
|
-
|
19
|
-
|
30
|
+
@service_buckets_list.stubs(:service_request).returns(@response_buckets_list)
|
31
|
+
@response_buckets_list.stubs(:body).returns(@buckets_list_body)
|
20
32
|
|
21
33
|
@service_bucket_exists = S3::Service.new(
|
22
34
|
:access_key_id => "12345678901234567890",
|
23
35
|
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
24
36
|
)
|
25
37
|
@response_bucket_exists = Net::HTTPNotFound.new("1.1", "200", "OK")
|
26
|
-
|
27
|
-
|
38
|
+
@service_bucket_exists.stubs(:service_request).returns(@response_bucket_exists)
|
39
|
+
@response_bucket_exists.stubs(:body).returns(@bucket_exists)
|
28
40
|
|
29
41
|
@service_bucket_not_exists = S3::Service.new(
|
30
42
|
:access_key_id => "12345678901234567890",
|
31
43
|
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
32
44
|
)
|
33
45
|
@response_bucket_not_exists = Net::HTTPNotFound.new("1.1", "404", "Not Found")
|
34
|
-
|
35
|
-
|
46
|
+
@service_bucket_not_exists.stubs(:service_request).raises(S3::Error::NoSuchBucket.new(404, @response_bucket_not_exists))
|
47
|
+
@response_bucket_not_exists.stubs(:body).returns(@bucket_not_exists)
|
36
48
|
|
37
49
|
@buckets_empty_list = []
|
38
50
|
@buckets_empty_list_body = <<-EOEmptyBuckets
|
@@ -43,34 +55,23 @@ class ServiceTest < Test::Unit::TestCase
|
|
43
55
|
S3::Bucket.send(:new, @service_buckets_list, "data.example.com"),
|
44
56
|
S3::Bucket.send(:new, @service_buckets_list, "images")
|
45
57
|
]
|
46
|
-
@buckets_list_body = <<-EOBuckets
|
47
|
-
<?xml version="1.0" encoding="UTF-8"?>\n<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Owner> <ID>123u1odhkhfoadf</ID> <DisplayName>JohnDoe</DisplayName> </Owner> <Buckets> <Bucket> <Name>data.example.com</Name> <CreationDate>2009-07-02T11:56:58.000Z</CreationDate> </Bucket> <Bucket> <Name>images</Name> <CreationDate>2009-06-05T12:26:33.000Z</CreationDate> </Bucket> </Buckets> </ListAllMyBucketsResult>
|
48
|
-
EOBuckets
|
49
|
-
|
50
|
-
@bucket_not_exists = <<-EOBucketNoexists
|
51
|
-
<?xml version="1.0" encoding="UTF-8"?>\n<Error> <Code>NoSuchBucket</Code> <Message>The specified bucket does not exists</Message> <BucketName>data2.example.com</BucketName> <RequestId>8D7519AAE74E9E99</RequestId> <HostId>DvKnnNSMnPHd1oXukyRaFNv8Lg/bpwhuUtY8Kj7eDLbaIrIT8JebSnHwi89AK1P+</HostId> </Error>
|
52
|
-
EOBucketNoexists
|
53
|
-
|
54
|
-
@bucket_exists = <<-EOBucketexists
|
55
|
-
<?xml version="1.0" encoding="UTF-8"?>\n<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Name>data.synergypeople.net</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> </ListBucketResult>
|
56
|
-
EOBucketexists
|
57
58
|
end
|
58
59
|
|
59
|
-
|
60
|
+
test "buckets and parse buckets empty" do
|
60
61
|
expected = @buckets_empty_list
|
61
62
|
actual = @service_empty_buckets_list.buckets
|
62
63
|
assert_equal expected.length, actual.length
|
63
64
|
assert_equal expected, actual
|
64
65
|
end
|
65
66
|
|
66
|
-
|
67
|
+
test "buckets and parse buckets" do
|
67
68
|
expected = @buckets_list
|
68
69
|
# ugly hack
|
69
70
|
actual = @service_buckets_list.buckets(true).map { |obj| obj }
|
70
71
|
assert_equal expected, actual
|
71
72
|
end
|
72
73
|
|
73
|
-
|
74
|
+
test "buckets reload" do
|
74
75
|
@service = @service_empty_buckets_list
|
75
76
|
|
76
77
|
expected = @buckets_empty_list
|
@@ -78,7 +79,7 @@ class ServiceTest < Test::Unit::TestCase
|
|
78
79
|
actual = @service.buckets
|
79
80
|
assert_equal expected.length, actual.length, "deliver from cache"
|
80
81
|
|
81
|
-
|
82
|
+
@service.stubs(:service_request).returns(@response_buckets_list)
|
82
83
|
expected = @buckets_empty_list
|
83
84
|
actual = @service.buckets
|
84
85
|
assert_equal expected.length, actual.length, "deliver from cache"
|
@@ -88,8 +89,8 @@ class ServiceTest < Test::Unit::TestCase
|
|
88
89
|
assert_equal expected.length, actual.length
|
89
90
|
end
|
90
91
|
|
91
|
-
|
92
|
-
|
92
|
+
test "buckets build" do
|
93
|
+
@service_empty_buckets_list.stubs(:service_request)
|
93
94
|
|
94
95
|
expected = "bucket_name"
|
95
96
|
actual = @service_empty_buckets_list.buckets.build("bucket_name")
|
@@ -97,20 +98,20 @@ class ServiceTest < Test::Unit::TestCase
|
|
97
98
|
assert_equal expected, actual.name
|
98
99
|
end
|
99
100
|
|
100
|
-
|
101
|
+
test "buckets find first" do
|
101
102
|
assert_nothing_raised do
|
102
103
|
actual = @service_buckets_list.buckets.find_first("data.example.com")
|
103
104
|
assert_equal "data.example.com", actual.name
|
104
105
|
end
|
105
106
|
end
|
106
107
|
|
107
|
-
|
108
|
+
test "buckets find first fail" do
|
108
109
|
assert_raise S3::Error::NoSuchBucket do
|
109
110
|
@service_bucket_not_exists.buckets.find_first("data2.example.com")
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
113
|
-
|
114
|
+
test "buckets find all on empty list" do
|
114
115
|
assert_nothing_raised do
|
115
116
|
expected = @buckets_empty_list
|
116
117
|
actual = @service_empty_buckets_list.buckets.find_all
|
@@ -118,7 +119,7 @@ class ServiceTest < Test::Unit::TestCase
|
|
118
119
|
end
|
119
120
|
end
|
120
121
|
|
121
|
-
|
122
|
+
test "buckets find all" do
|
122
123
|
assert_nothing_raised do
|
123
124
|
expected = @buckets_list
|
124
125
|
actual = @service_buckets_list.buckets.find_all
|
data/test/signature_test.rb
CHANGED
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class SignatureTest < Test::Unit::TestCase
|
4
4
|
# from http://docs.amazonwebservices.com/AmazonS3/latest/RESTAuthentication.html
|
5
|
-
|
5
|
+
test "signature for object get" do
|
6
6
|
request = Net::HTTP::Get.new("/photos/puppy.jpg")
|
7
7
|
request["host"] = "johnsmith.s3.amazonaws.com"
|
8
8
|
request["date"] = "Tue, 27 Mar 2007 19:36:42 +0000"
|
@@ -17,7 +17,7 @@ class SignatureTest < Test::Unit::TestCase
|
|
17
17
|
assert_equal expected, actual
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
test "signature for object put" do
|
21
21
|
request = Net::HTTP::Put.new("/photos/puppy.jpg");
|
22
22
|
request["content-type"] = "image/jpeg"
|
23
23
|
request["content-length"] = "94328"
|
@@ -34,7 +34,7 @@ class SignatureTest < Test::Unit::TestCase
|
|
34
34
|
assert_equal expected, actual
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
test "signature for list" do
|
38
38
|
request = Net::HTTP::Get.new("/?prefix=photos&max-keys=50&marker=puppy");
|
39
39
|
request["user-agent"] = "Mozilla/5.0"
|
40
40
|
request["host"] = "johnsmith.s3.amazonaws.com"
|
@@ -50,7 +50,7 @@ class SignatureTest < Test::Unit::TestCase
|
|
50
50
|
assert_equal expected, actual
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
test "signature for fetch" do
|
54
54
|
request = Net::HTTP::Get.new("/?acl");
|
55
55
|
request["host"] = "johnsmith.s3.amazonaws.com"
|
56
56
|
request["date"] = "Tue, 27 Mar 2007 19:44:46 +0000"
|
@@ -65,7 +65,7 @@ class SignatureTest < Test::Unit::TestCase
|
|
65
65
|
assert_equal expected, actual
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
test "signature for delete" do
|
69
69
|
request = Net::HTTP::Delete.new("/johnsmith/photos/puppy.jpg");
|
70
70
|
request["user-agent"] = "dotnet"
|
71
71
|
request["host"] = "s3.amazonaws.com"
|
@@ -82,7 +82,7 @@ class SignatureTest < Test::Unit::TestCase
|
|
82
82
|
assert_equal expected, actual
|
83
83
|
end
|
84
84
|
|
85
|
-
|
85
|
+
test "signature for upload" do
|
86
86
|
request = Net::HTTP::Put.new("/db-backup.dat.gz");
|
87
87
|
request["user-agent"] = "curl/7.15.5"
|
88
88
|
request["host"] = "static.johnsmith.net:8080"
|
@@ -111,7 +111,7 @@ class SignatureTest < Test::Unit::TestCase
|
|
111
111
|
assert_equal expected, actual
|
112
112
|
end
|
113
113
|
|
114
|
-
|
114
|
+
test "signature for list all my buckets" do
|
115
115
|
request = Net::HTTP::Get.new("/");
|
116
116
|
request["host"] = "s3.amazonaws.com"
|
117
117
|
request["date"] = "Wed, 28 Mar 2007 01:29:59 +0000"
|
@@ -126,7 +126,7 @@ class SignatureTest < Test::Unit::TestCase
|
|
126
126
|
assert_equal expected, actual
|
127
127
|
end
|
128
128
|
|
129
|
-
|
129
|
+
test "signature for unicode keys" do
|
130
130
|
request = Net::HTTP::Get.new("/dictionary/fran%C3%A7ais/pr%c3%a9f%c3%a8re");
|
131
131
|
request["host"] = "s3.amazonaws.com"
|
132
132
|
request["date"] = "Wed, 28 Mar 2007 01:49:49 +0000"
|
data/test/test_helper.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "test/unit"
|
3
|
+
require "mocha"
|
4
4
|
|
5
5
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
6
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
-
require
|
8
|
-
|
9
|
-
class Test::Unit::TestCase
|
10
|
-
include RR::Adapters::TestUnit
|
11
|
-
end
|
7
|
+
require "s3"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jakub Ku\xC5\xBAma"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-
|
13
|
+
date: 2010-02-07 00:00:00 +01:00
|
14
14
|
default_executable: s3
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -34,16 +34,16 @@ dependencies:
|
|
34
34
|
version: "2.0"
|
35
35
|
version:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: mocha
|
38
38
|
type: :development
|
39
39
|
version_requirement:
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- - "
|
42
|
+
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: 0
|
44
|
+
version: "0"
|
45
45
|
version:
|
46
|
-
description:
|
46
|
+
description: "S3 library provides access to Amazon's Simple Storage Service. It supports both: European and US buckets through REST API."
|
47
47
|
email: qoobaa@gmail.com
|
48
48
|
executables:
|
49
49
|
- s3
|
@@ -107,9 +107,9 @@ signing_key:
|
|
107
107
|
specification_version: 3
|
108
108
|
summary: Library for accessing S3 objects and buckets, with command line tool
|
109
109
|
test_files:
|
110
|
-
- test/bucket_test.rb
|
111
110
|
- test/object_test.rb
|
112
|
-
- test/signature_test.rb
|
113
|
-
- test/service_test.rb
|
114
111
|
- test/test_helper.rb
|
112
|
+
- test/bucket_test.rb
|
115
113
|
- test/connection_test.rb
|
114
|
+
- test/service_test.rb
|
115
|
+
- test/signature_test.rb
|