qoobaa-stree 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.rdoc +48 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/bin/stree +187 -0
- data/extra/stree_backend.rb +159 -0
- data/lib/stree/bucket.rb +192 -0
- data/lib/stree/connection.rb +199 -0
- data/lib/stree/exceptions.rb +108 -0
- data/lib/stree/object.rb +196 -0
- data/lib/stree/roxy/moxie.rb +58 -0
- data/lib/stree/roxy/proxy.rb +72 -0
- data/lib/stree/service.rb +117 -0
- data/lib/stree/signature.rb +157 -0
- data/lib/stree.rb +24 -0
- data/stree.gemspec +69 -0
- data/test/bucket_test.rb +231 -0
- data/test/connection_test.rb +164 -0
- data/test/object_test.rb +164 -0
- data/test/service_test.rb +128 -0
- data/test/signature_test.rb +143 -0
- data/test/test_helper.rb +11 -0
- metadata +92 -0
@@ -0,0 +1,164 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ConnectionTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@connection = Stree::Connection.new(
|
6
|
+
:access_key_id => "12345678901234567890",
|
7
|
+
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
8
|
+
)
|
9
|
+
@http_request = Net::HTTP.new("")
|
10
|
+
@response_ok = Net::HTTPOK.new("1.1", "200", "OK")
|
11
|
+
@response_not_found = Net::HTTPNotFound.new("1.1", "404", "Not Found")
|
12
|
+
stub(@connection).http { @http_request }
|
13
|
+
stub(@http_request).start { @response_ok }
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_handle_response_not_modify_response_when_ok
|
17
|
+
assert_nothing_raised do
|
18
|
+
response = @connection.request(
|
19
|
+
:get,
|
20
|
+
:host => "s3.amazonaws.com",
|
21
|
+
:path => "/"
|
22
|
+
)
|
23
|
+
assert_equal @response_ok, response
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_handle_response_throws_exception_when_not_ok
|
28
|
+
response_body = <<-EOFakeBody
|
29
|
+
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
30
|
+
<SomeResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">
|
31
|
+
<Code>NoSuchBucket</Code>
|
32
|
+
<Message>The specified bucket does not exist</Message>
|
33
|
+
</SomeResult>
|
34
|
+
EOFakeBody
|
35
|
+
stub(@http_request).start { @response_not_found }
|
36
|
+
stub(@response_not_found).body { response_body }
|
37
|
+
|
38
|
+
assert_raise Stree::Error::NoSuchBucket do
|
39
|
+
response = @connection.request(
|
40
|
+
:get,
|
41
|
+
:host => "data.example.com.s3.amazonaws.com",
|
42
|
+
:path => "/"
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_handle_response_throws_standard_exception_when_not_ok
|
48
|
+
stub(@http_request).start { @response_not_found }
|
49
|
+
stub(@response_not_found).body { nil }
|
50
|
+
assert_raise Stree::Error::ResponseError do
|
51
|
+
response = @connection.request(
|
52
|
+
:get,
|
53
|
+
:host => "data.example.com.s3.amazonaws.com",
|
54
|
+
:path => "/"
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
stub(@response_not_found).body { "" }
|
59
|
+
assert_raise Stree::Error::ResponseError do
|
60
|
+
response = @connection.request(
|
61
|
+
:get,
|
62
|
+
:host => "data.example.com.s3.amazonaws.com",
|
63
|
+
:path => "/"
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_parse_params_empty
|
69
|
+
expected = ""
|
70
|
+
actual = Stree::Connection.parse_params({})
|
71
|
+
assert_equal expected, actual
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_parse_params_only_interesting_params
|
75
|
+
expected = ""
|
76
|
+
actual = Stree::Connection.parse_params(:param1 => "1", :maxkeys => "2")
|
77
|
+
assert_equal expected, actual
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_parse_params_remove_underscore
|
81
|
+
expected = "max-keys=100"
|
82
|
+
actual = Stree::Connection.parse_params(:max_keys => 100)
|
83
|
+
assert_equal expected, actual
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_parse_params_with_and_without_values
|
87
|
+
expected = "max-keys=100&prefix"
|
88
|
+
actual = Stree::Connection.parse_params(:max_keys => 100, :prefix => nil)
|
89
|
+
assert_equal expected, actual
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_headers_headers_empty
|
93
|
+
expected = {}
|
94
|
+
actual = Stree::Connection.parse_headers({})
|
95
|
+
assert_equal expected, actual
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_parse_headers_only_interesting_headers
|
99
|
+
expected = {}
|
100
|
+
actual = Stree::Connection.parse_headers(
|
101
|
+
:accept => "text/*, text/html, text/html;level=1, */*",
|
102
|
+
:accept_charset => "iso-8859-2, unicode-1-1;q=0.8"
|
103
|
+
)
|
104
|
+
assert_equal expected, actual
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_parse_headers_remove_underscore
|
108
|
+
expected = {
|
109
|
+
"content-type" => nil,
|
110
|
+
"x-amz-acl" => nil,
|
111
|
+
"if-modified-since" => nil,
|
112
|
+
"if-unmodified-since" => nil,
|
113
|
+
"if-match" => nil,
|
114
|
+
"if-none-match" => nil,
|
115
|
+
"content-disposition" => nil,
|
116
|
+
"content-encoding" => nil
|
117
|
+
}
|
118
|
+
actual = Stree::Connection.parse_headers(
|
119
|
+
:content_type => nil,
|
120
|
+
:x_amz_acl => nil,
|
121
|
+
:if_modified_since => nil,
|
122
|
+
:if_unmodified_since => nil,
|
123
|
+
:if_match => nil,
|
124
|
+
:if_none_match => nil,
|
125
|
+
:content_disposition => nil,
|
126
|
+
:content_encoding => nil
|
127
|
+
)
|
128
|
+
assert_equal expected, actual
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_parse_headers_with_values
|
132
|
+
expected = {
|
133
|
+
"content-type" => "text/html",
|
134
|
+
"x-amz-acl" => "public-read",
|
135
|
+
"if-modified-since" => "today",
|
136
|
+
"if-unmodified-since" => "tomorrow",
|
137
|
+
"if-match" => "1234",
|
138
|
+
"if-none-match" => "1243",
|
139
|
+
"content-disposition" => "inline",
|
140
|
+
"content-encoding" => "gzip"
|
141
|
+
}
|
142
|
+
actual = Stree::Connection.parse_headers(
|
143
|
+
:content_type => "text/html",
|
144
|
+
:x_amz_acl => "public-read",
|
145
|
+
:if_modified_since => "today",
|
146
|
+
:if_unmodified_since => "tomorrow",
|
147
|
+
:if_match => "1234",
|
148
|
+
:if_none_match => "1243",
|
149
|
+
:content_disposition => "inline",
|
150
|
+
:content_encoding => "gzip"
|
151
|
+
)
|
152
|
+
assert_equal expected, actual
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_parse_headers_with_range
|
156
|
+
expected = {
|
157
|
+
"range" => "bytes=0-100"
|
158
|
+
}
|
159
|
+
actual = Stree::Connection.parse_headers(
|
160
|
+
:range => 0..100
|
161
|
+
)
|
162
|
+
assert_equal expected, actual
|
163
|
+
end
|
164
|
+
end
|
data/test/object_test.rb
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class ObjectTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@service = Stree::Service.new(
|
7
|
+
:access_key_id => "1234",
|
8
|
+
:secret_access_key => "1337"
|
9
|
+
)
|
10
|
+
@bucket_images = Stree::Bucket.new(@service, "images")
|
11
|
+
@object_lena = Stree::Object.new(@bucket_images, "Lena.png")
|
12
|
+
@object_lena.content = "test"
|
13
|
+
@object_carmen = Stree::Object.new(@bucket_images, "Carmen.png")
|
14
|
+
|
15
|
+
@response_binary = Net::HTTPOK.new("1.1", "200", "OK")
|
16
|
+
stub(@response_binary).body { "test".force_encoding(Encoding::BINARY) }
|
17
|
+
@response_binary["etag"] = ""
|
18
|
+
@response_binary["content-type"] = "image/png"
|
19
|
+
@response_binary["content-disposition"] = "inline"
|
20
|
+
@response_binary["content-encoding"] = nil
|
21
|
+
@response_binary["last-modified"] = Time.now.httpdate
|
22
|
+
@response_binary["content-length"] = 20
|
23
|
+
|
24
|
+
@xml_body = <<-EOXML
|
25
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
26
|
+
<CopyObjectResult> <LastModified>timestamp</LastModified> <ETag>"etag"</ETag> </CopyObjectResult>
|
27
|
+
EOXML
|
28
|
+
@response_xml = Net::HTTPOK.new("1.1", "200", "OK")
|
29
|
+
stub(@response_xml).body { @xml_body }
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_initilalize
|
33
|
+
assert_raise ArgumentError do Stree::Object.new(nil, "") end # should not allow empty key
|
34
|
+
assert_raise ArgumentError do Stree::Object.new(nil, "//") end # should not allow key with double slash
|
35
|
+
|
36
|
+
assert_nothing_raised do
|
37
|
+
Stree::Object.new(nil, "Lena.png")
|
38
|
+
Stree::Object.new(nil, "Lena playboy.png")
|
39
|
+
Stree::Object.new(nil, "Lena Söderberg.png")
|
40
|
+
Stree::Object.new(nil, "/images/pictures/test images/Lena not full.png")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_full_key
|
45
|
+
expected = "images/Lena.png"
|
46
|
+
actual = @object_lena.full_key
|
47
|
+
assert_equal expected, actual
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_url
|
51
|
+
bucket1 = Stree::Bucket.new(@service, "images")
|
52
|
+
|
53
|
+
object11 = Stree::Object.new(bucket1, "Lena.png")
|
54
|
+
expected = "http://images.s3.amazonaws.com/Lena.png"
|
55
|
+
actual = object11.url
|
56
|
+
assert_equal expected, actual
|
57
|
+
|
58
|
+
object12 = Stree::Object.new(bucket1, "Lena Söderberg.png")
|
59
|
+
expected = "http://images.s3.amazonaws.com/Lena%20S%C3%B6derberg.png"
|
60
|
+
actual = object12.url
|
61
|
+
assert_equal expected, actual
|
62
|
+
|
63
|
+
bucket2 = Stree::Bucket.new(@service, "images_new")
|
64
|
+
|
65
|
+
object21 = Stree::Object.new(bucket2, "Lena.png")
|
66
|
+
expected = "http://s3.amazonaws.com/images_new/Lena.png"
|
67
|
+
actual = object21.url
|
68
|
+
assert_equal expected, actual
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_cname_url
|
72
|
+
bucket1 = Stree::Bucket.new(@service, "images.example.com")
|
73
|
+
|
74
|
+
object11 = Stree::Object.new(bucket1, "Lena.png")
|
75
|
+
expected = "http://images.example.com/Lena.png"
|
76
|
+
actual = object11.cname_url
|
77
|
+
assert_equal expected, actual
|
78
|
+
|
79
|
+
object12 = Stree::Object.new(bucket1, "Lena Söderberg.png")
|
80
|
+
expected = "http://images.example.com/Lena%20S%C3%B6derberg.png"
|
81
|
+
actual = object12.cname_url
|
82
|
+
assert_equal expected, actual
|
83
|
+
|
84
|
+
bucket2 = Stree::Bucket.new(@service, "images_new")
|
85
|
+
|
86
|
+
object21 = Stree::Object.new(bucket2, "Lena.png")
|
87
|
+
expected = nil
|
88
|
+
actual = object21.cname_url
|
89
|
+
assert_equal expected, actual
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_destroy
|
93
|
+
mock(@object_lena).object_request(:delete) {}
|
94
|
+
assert @object_lena.destroy
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_save
|
98
|
+
mock(@object_lena).object_request(
|
99
|
+
:put, :body=>"test",
|
100
|
+
:headers=>{ :x_amz_acl=>"public-read", :content_type=>"application/octet-stream" }
|
101
|
+
) { @response_binary }
|
102
|
+
|
103
|
+
assert @object_lena.save
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_content_and_parse_headers
|
107
|
+
mock(@object_lena).object_request(:get) { @response_binary }
|
108
|
+
|
109
|
+
expected = /test/n
|
110
|
+
actual = @object_lena.content(true) # wtf? don't work with false, maybe is not fully cleaned
|
111
|
+
assert_match expected, actual
|
112
|
+
assert_equal "image/png", @object_lena.content_type
|
113
|
+
|
114
|
+
stub(@object_lena).object_request(:get) { flunk "should not use connection" }
|
115
|
+
|
116
|
+
assert @object_lena.content
|
117
|
+
|
118
|
+
mock(@object_lena).object_request(:get) { @response_binary }
|
119
|
+
assert @object_lena.content(true)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_retrieve
|
123
|
+
mock(@object_lena).object_request(:get, :headers=>{:range=>0..0}) { @response_binary }
|
124
|
+
assert @object_lena.retrieve
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_exists
|
128
|
+
mock(@object_lena).retrieve { true }
|
129
|
+
assert @object_lena.exists?
|
130
|
+
|
131
|
+
mock(@object_carmen).retrieve { raise Stree::Error::NoSuchKey.new(nil, nil) }
|
132
|
+
assert ! @object_carmen.exists?
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_acl_writer
|
136
|
+
expected = nil
|
137
|
+
actual = @object_lena.acl
|
138
|
+
assert_equal expected, actual
|
139
|
+
|
140
|
+
assert @object_lena.acl = :public_read
|
141
|
+
|
142
|
+
expected = "public-read"
|
143
|
+
actual = @object_lena.acl
|
144
|
+
assert_equal expected, actual
|
145
|
+
|
146
|
+
assert @object_lena.acl = :private
|
147
|
+
|
148
|
+
expected = "private"
|
149
|
+
actual = @object_lena.acl
|
150
|
+
assert_equal expected, actual
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_copy
|
154
|
+
mock(@bucket_images).bucket_request(
|
155
|
+
:put, :path=>"Lena.png",
|
156
|
+
:headers=>{:x_amz_acl=>"public-read", :content_type=>"application/octet-stream", :x_amz_copy_source=>"images/Lena.png", :x_amz_metadata_directive=>"REPLACE"}
|
157
|
+
) { @response_xml }
|
158
|
+
|
159
|
+
new_object = @object_lena.copy
|
160
|
+
|
161
|
+
assert_equal @object_lena, new_object
|
162
|
+
assert ! @object_lena.eql?(new_object)
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ServiceTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@service_empty_buckets_list = Stree::Service.new(
|
6
|
+
:access_key_id => "12345678901234567890",
|
7
|
+
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
8
|
+
)
|
9
|
+
@response_empty_buckets_list = Net::HTTPOK.new("1.1", "200", "OK")
|
10
|
+
stub(@service_empty_buckets_list).service_request { @response_empty_buckets_list }
|
11
|
+
stub(@response_empty_buckets_list).body { @buckets_empty_list_body }
|
12
|
+
|
13
|
+
@service_buckets_list = Stree::Service.new(
|
14
|
+
:access_key_id => "12345678901234567890",
|
15
|
+
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
16
|
+
)
|
17
|
+
@response_buckets_list = Net::HTTPOK.new("1.1", "200", "OK")
|
18
|
+
stub(@service_buckets_list).service_request { @response_buckets_list }
|
19
|
+
stub(@response_buckets_list).body { @buckets_list_body }
|
20
|
+
|
21
|
+
@service_bucket_exists = Stree::Service.new(
|
22
|
+
:access_key_id => "12345678901234567890",
|
23
|
+
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
24
|
+
)
|
25
|
+
@response_bucket_exists = Net::HTTPNotFound.new("1.1", "200", "OK")
|
26
|
+
stub(@service_bucket_exists).service_request { @response_bucket_exists }
|
27
|
+
stub(@response_bucket_exists).body { @bucket_exists }
|
28
|
+
|
29
|
+
@service_bucket_not_exists = Stree::Service.new(
|
30
|
+
:access_key_id => "12345678901234567890",
|
31
|
+
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
32
|
+
)
|
33
|
+
@response_bucket_not_exists = Net::HTTPNotFound.new("1.1", "404", "Not Found")
|
34
|
+
stub(@service_bucket_not_exists).service_request { raise Stree::Error::NoSuchBucket.new(404, @response_bucket_not_exists) }
|
35
|
+
stub(@response_bucket_not_exists).body { @bucket_not_exists }
|
36
|
+
|
37
|
+
@buckets_empty_list = []
|
38
|
+
@buckets_empty_list_body = <<-EOEmptyBuckets
|
39
|
+
<?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> </Buckets> </ListAllMyBucketsResult>
|
40
|
+
EOEmptyBuckets
|
41
|
+
|
42
|
+
@buckets_list = [
|
43
|
+
Stree::Bucket.new(@service_buckets_list, "data.example.com"),
|
44
|
+
Stree::Bucket.new(@service_buckets_list, "images")
|
45
|
+
]
|
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
|
+
end
|
58
|
+
|
59
|
+
def test_buckets_and_parse_buckets_empty
|
60
|
+
expected = @buckets_empty_list
|
61
|
+
actual = @service_empty_buckets_list.buckets
|
62
|
+
assert_equal expected.length, actual.length
|
63
|
+
assert_equal expected, actual
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_buckets_and_parse_buckets
|
67
|
+
expected = @buckets_list
|
68
|
+
# ugly hack
|
69
|
+
actual = @service_buckets_list.buckets(true).map { |obj| obj }
|
70
|
+
assert_equal expected, actual
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_buckets_reload
|
74
|
+
@service = @service_empty_buckets_list
|
75
|
+
|
76
|
+
expected = @buckets_empty_list
|
77
|
+
assert @service.buckets, "retrive buckets"
|
78
|
+
actual = @service.buckets
|
79
|
+
assert_equal expected.length, actual.length, "deliver from cache"
|
80
|
+
|
81
|
+
stub(@service).service_request { @response_buckets_list }
|
82
|
+
expected = @buckets_empty_list
|
83
|
+
actual = @service.buckets
|
84
|
+
assert_equal expected.length, actual.length, "deliver from cache"
|
85
|
+
|
86
|
+
expected = @buckets_list
|
87
|
+
actual = @service.buckets(true)
|
88
|
+
assert_equal expected.length, actual.length
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_buckets_build
|
92
|
+
stub(@service_empty_buckets_list).service_request { flunk "should not connect to server" }
|
93
|
+
|
94
|
+
expected = "bucket_name"
|
95
|
+
actual = @service_empty_buckets_list.buckets.build("bucket_name")
|
96
|
+
assert_kind_of Stree::Bucket, actual
|
97
|
+
assert_equal expected, actual.name
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_buckets_find_first
|
101
|
+
assert_nothing_raised do
|
102
|
+
actual = @service_buckets_list.buckets.find_first("data.example.com")
|
103
|
+
assert_equal "data.example.com", actual.name
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_buckets_find_first_fail
|
108
|
+
assert_raise Stree::Error::NoSuchBucket do
|
109
|
+
@service_bucket_not_exists.buckets.find_first("data2.example.com")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_buckets_find_all_on_empty_list
|
114
|
+
assert_nothing_raised do
|
115
|
+
expected = @buckets_empty_list
|
116
|
+
actual = @service_empty_buckets_list.buckets.find_all
|
117
|
+
assert_equal expected, actual
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_buckets_find_all
|
122
|
+
assert_nothing_raised do
|
123
|
+
expected = @buckets_list
|
124
|
+
actual = @service_buckets_list.buckets.find_all
|
125
|
+
assert_equal expected, actual
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SignatureTest < Test::Unit::TestCase
|
4
|
+
# from http://docs.amazonwebservices.com/AmazonS3/latest/RESTAuthentication.html
|
5
|
+
def test_signature_for_object_get
|
6
|
+
request = Net::HTTP::Get.new("/photos/puppy.jpg")
|
7
|
+
request["host"] = "johnsmith.s3.amazonaws.com"
|
8
|
+
request["date"] = "Tue, 27 Mar 2007 19:36:42 +0000"
|
9
|
+
|
10
|
+
actual = Stree::Signature.generate(
|
11
|
+
:host => request["host"],
|
12
|
+
:request => request,
|
13
|
+
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
14
|
+
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
15
|
+
)
|
16
|
+
expected = "AWS 0PN5J17HBGZHT7JJ3X82:xXjDGYUmKxnwqr5KXNPGldn5LbA="
|
17
|
+
assert_equal expected, actual
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_signature_for_object_put
|
21
|
+
request = Net::HTTP::Put.new("/photos/puppy.jpg");
|
22
|
+
request["content-type"] = "image/jpeg"
|
23
|
+
request["content-length"] = "94328"
|
24
|
+
request["host"] = "johnsmith.s3.amazonaws.com"
|
25
|
+
request["date"] = "Tue, 27 Mar 2007 21:15:45 +0000"
|
26
|
+
|
27
|
+
actual = Stree::Signature.generate(
|
28
|
+
:host => request["host"],
|
29
|
+
:request => request,
|
30
|
+
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
31
|
+
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
32
|
+
)
|
33
|
+
expected = "AWS 0PN5J17HBGZHT7JJ3X82:hcicpDDvL9SsO6AkvxqmIWkmOuQ="
|
34
|
+
assert_equal expected, actual
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_signature_for_list
|
38
|
+
request = Net::HTTP::Get.new("/?prefix=photos&max-keys=50&marker=puppy");
|
39
|
+
request["user-agent"] = "Mozilla/5.0"
|
40
|
+
request["host"] = "johnsmith.s3.amazonaws.com"
|
41
|
+
request["date"] = "Tue, 27 Mar 2007 19:42:41 +0000"
|
42
|
+
|
43
|
+
actual = Stree::Signature.generate(
|
44
|
+
:host => request["host"],
|
45
|
+
:request => request,
|
46
|
+
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
47
|
+
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
48
|
+
)
|
49
|
+
expected = "AWS 0PN5J17HBGZHT7JJ3X82:jsRt/rhG+Vtp88HrYL706QhE4w4="
|
50
|
+
assert_equal expected, actual
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_signature_for_fetch
|
54
|
+
request = Net::HTTP::Get.new("/?acl");
|
55
|
+
request["host"] = "johnsmith.s3.amazonaws.com"
|
56
|
+
request["date"] = "Tue, 27 Mar 2007 19:44:46 +0000"
|
57
|
+
|
58
|
+
actual = Stree::Signature.generate(
|
59
|
+
:host => request["host"],
|
60
|
+
:request => request,
|
61
|
+
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
62
|
+
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
63
|
+
)
|
64
|
+
expected = "AWS 0PN5J17HBGZHT7JJ3X82:thdUi9VAkzhkniLj96JIrOPGi0g="
|
65
|
+
assert_equal expected, actual
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_signature_for_delete
|
69
|
+
request = Net::HTTP::Delete.new("/johnsmith/photos/puppy.jpg");
|
70
|
+
request["user-agent"] = "dotnet"
|
71
|
+
request["host"] = "s3.amazonaws.com"
|
72
|
+
request["date"] = "Tue, 27 Mar 2007 21:20:27 +0000"
|
73
|
+
request["x-amz-date"] = "Tue, 27 Mar 2007 21:20:26 +0000"
|
74
|
+
|
75
|
+
actual = Stree::Signature.generate(
|
76
|
+
:host => request["host"],
|
77
|
+
:request => request,
|
78
|
+
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
79
|
+
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
80
|
+
)
|
81
|
+
expected = "AWS 0PN5J17HBGZHT7JJ3X82:k3nL7gH3+PadhTEVn5Ip83xlYzk="
|
82
|
+
assert_equal expected, actual
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_signature_for_upload
|
86
|
+
request = Net::HTTP::Put.new("/db-backup.dat.gz");
|
87
|
+
request["user-agent"] = "curl/7.15.5"
|
88
|
+
request["host"] = "static.johnsmith.net:8080"
|
89
|
+
request["date"] = "Tue, 27 Mar 2007 21:06:08 +0000"
|
90
|
+
request["x-amz-acl"] = "public-read"
|
91
|
+
request["content-type"] = "application/x-download"
|
92
|
+
request["content-MD5"] = "4gJE4saaMU4BqNR0kLY+lw=="
|
93
|
+
# TODO:
|
94
|
+
# was:
|
95
|
+
#request["x-amz-meta-reviewedby"] = "joe@johnsmith.net"
|
96
|
+
#request["x-amz-meta-reviewedby"] = "jane@johnsmith.net"
|
97
|
+
request["x-amz-meta-reviewedby"] = "joe@johnsmith.net,jane@johnsmith.net"
|
98
|
+
request["x-amz-meta-filechecksum"] = "0x02661779"
|
99
|
+
request["x-amz-meta-checksumalgorithm"] = "crc32"
|
100
|
+
request["content-disposition"] = "attachment; filename=database.dat"
|
101
|
+
request["content-encoding"] = "gzip"
|
102
|
+
request["content-length"] = "5913339"
|
103
|
+
|
104
|
+
actual = Stree::Signature.generate(
|
105
|
+
:host => "static.johnsmith.net",
|
106
|
+
:request => request,
|
107
|
+
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
108
|
+
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
109
|
+
)
|
110
|
+
expected = "AWS 0PN5J17HBGZHT7JJ3X82:C0FlOtU8Ylb9KDTpZqYkZPX91iI="
|
111
|
+
assert_equal expected, actual
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_signature_for_list_all_my_buckets
|
115
|
+
request = Net::HTTP::Get.new("/");
|
116
|
+
request["host"] = "s3.amazonaws.com"
|
117
|
+
request["date"] = "Wed, 28 Mar 2007 01:29:59 +0000"
|
118
|
+
|
119
|
+
actual = Stree::Signature.generate(
|
120
|
+
:host => request["host"],
|
121
|
+
:request => request,
|
122
|
+
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
123
|
+
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
124
|
+
)
|
125
|
+
expected = "AWS 0PN5J17HBGZHT7JJ3X82:Db+gepJSUbZKwpx1FR0DLtEYoZA="
|
126
|
+
assert_equal expected, actual
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_signature_for_unicode_keys
|
130
|
+
request = Net::HTTP::Get.new("/dictionary/fran%C3%A7ais/pr%c3%a9f%c3%a8re");
|
131
|
+
request["host"] = "s3.amazonaws.com"
|
132
|
+
request["date"] = "Wed, 28 Mar 2007 01:49:49 +0000"
|
133
|
+
|
134
|
+
actual = Stree::Signature.generate(
|
135
|
+
:host => request["host"],
|
136
|
+
:request => request,
|
137
|
+
:access_key_id => "0PN5J17HBGZHT7JJ3X82",
|
138
|
+
:secret_access_key => "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
139
|
+
)
|
140
|
+
expected = "AWS 0PN5J17HBGZHT7JJ3X82:dxhSBHoI6eVSPcXJqEghlUzZMnY="
|
141
|
+
assert_equal expected, actual
|
142
|
+
end
|
143
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rr'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
require 'stree'
|
8
|
+
|
9
|
+
class Test::Unit::TestCase
|
10
|
+
include RR::Adapters::TestUnit
|
11
|
+
end
|