aws-s3-akhtaboot 0.6.2.1288082910
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +19 -0
- data/INSTALL +55 -0
- data/README +545 -0
- data/Rakefile +334 -0
- data/bin/s3sh +6 -0
- data/bin/setup.rb +10 -0
- data/lib/aws/s3.rb +60 -0
- data/lib/aws/s3/acl.rb +636 -0
- data/lib/aws/s3/authentication.rb +221 -0
- data/lib/aws/s3/base.rb +240 -0
- data/lib/aws/s3/bittorrent.rb +58 -0
- data/lib/aws/s3/bucket.rb +319 -0
- data/lib/aws/s3/connection.rb +278 -0
- data/lib/aws/s3/error.rb +69 -0
- data/lib/aws/s3/exceptions.rb +133 -0
- data/lib/aws/s3/extensions.rb +356 -0
- data/lib/aws/s3/logging.rb +314 -0
- data/lib/aws/s3/object.rb +612 -0
- data/lib/aws/s3/owner.rb +44 -0
- data/lib/aws/s3/parsing.rb +99 -0
- data/lib/aws/s3/response.rb +180 -0
- data/lib/aws/s3/service.rb +51 -0
- data/lib/aws/s3/version.rb +12 -0
- data/support/faster-xml-simple/lib/faster_xml_simple.rb +187 -0
- data/support/faster-xml-simple/test/regression_test.rb +47 -0
- data/support/faster-xml-simple/test/test_helper.rb +17 -0
- data/support/faster-xml-simple/test/xml_simple_comparison_test.rb +46 -0
- data/support/rdoc/code_info.rb +211 -0
- data/test/acl_test.rb +254 -0
- data/test/authentication_test.rb +114 -0
- data/test/base_test.rb +136 -0
- data/test/bucket_test.rb +74 -0
- data/test/connection_test.rb +215 -0
- data/test/error_test.rb +70 -0
- data/test/extensions_test.rb +340 -0
- data/test/fixtures.rb +89 -0
- data/test/fixtures/buckets.yml +133 -0
- data/test/fixtures/errors.yml +34 -0
- data/test/fixtures/headers.yml +3 -0
- data/test/fixtures/logging.yml +15 -0
- data/test/fixtures/loglines.yml +5 -0
- data/test/fixtures/logs.yml +7 -0
- data/test/fixtures/policies.yml +16 -0
- data/test/logging_test.rb +89 -0
- data/test/mocks/fake_response.rb +26 -0
- data/test/object_test.rb +205 -0
- data/test/parsing_test.rb +66 -0
- data/test/remote/acl_test.rb +117 -0
- data/test/remote/bittorrent_test.rb +45 -0
- data/test/remote/bucket_test.rb +146 -0
- data/test/remote/logging_test.rb +82 -0
- data/test/remote/object_test.rb +371 -0
- data/test/remote/test_file.data +0 -0
- data/test/remote/test_helper.rb +33 -0
- data/test/response_test.rb +68 -0
- data/test/service_test.rb +23 -0
- data/test/test_helper.rb +110 -0
- metadata +200 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class HeaderAuthenticationTest < Test::Unit::TestCase
|
4
|
+
def test_encoded_canonical
|
5
|
+
signature = Authentication::Signature.new(request, key_id, secret)
|
6
|
+
assert_equal AmazonDocExampleData::Example1.canonical_string, signature.send(:canonical_string)
|
7
|
+
assert_equal AmazonDocExampleData::Example1.signature, signature.send(:encoded_canonical)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_authorization_header
|
11
|
+
header = Authentication::Header.new(request, key_id, secret)
|
12
|
+
assert_equal AmazonDocExampleData::Example1.canonical_string, header.send(:canonical_string)
|
13
|
+
assert_equal AmazonDocExampleData::Example1.authorization_header, header
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def request; AmazonDocExampleData::Example1.request end
|
18
|
+
def key_id ; AmazonDocExampleData::Example1.access_key_id end
|
19
|
+
def secret ; AmazonDocExampleData::Example1.secret_access_key end
|
20
|
+
end
|
21
|
+
|
22
|
+
class QueryStringAuthenticationTest < Test::Unit::TestCase
|
23
|
+
def test_query_string
|
24
|
+
query_string = Authentication::QueryString.new(request, key_id, secret, :expires_in => 60)
|
25
|
+
assert_equal AmazonDocExampleData::Example3.canonical_string, query_string.send(:canonical_string)
|
26
|
+
assert_equal AmazonDocExampleData::Example3.query_string, query_string
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_query_string_with_explicit_expiry
|
30
|
+
query_string = Authentication::QueryString.new(request, key_id, secret, :expires => expires)
|
31
|
+
assert_equal expires, query_string.send(:canonical_string).instance_variable_get(:@options)[:expires]
|
32
|
+
assert_equal AmazonDocExampleData::Example3.query_string, query_string
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_expires_in_is_coerced_to_being_an_integer_in_case_it_is_a_special_integer_proxy
|
36
|
+
# References bug: http://rubyforge.org/tracker/index.php?func=detail&aid=17458&group_id=2409&atid=9356
|
37
|
+
integer_proxy = Class.new do
|
38
|
+
attr_reader :integer
|
39
|
+
def initialize(integer)
|
40
|
+
@integer = integer
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_int
|
44
|
+
integer
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
actual_integer = 25
|
49
|
+
query_string = Authentication::QueryString.new(request, key_id, secret, :expires_in => integer_proxy.new(actual_integer))
|
50
|
+
assert_equal actual_integer, query_string.send(:expires_in)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def request; AmazonDocExampleData::Example3.request end
|
55
|
+
def key_id ; AmazonDocExampleData::Example3.access_key_id end
|
56
|
+
def secret ; AmazonDocExampleData::Example3.secret_access_key end
|
57
|
+
def expires; AmazonDocExampleData::Example3.expires end
|
58
|
+
end
|
59
|
+
|
60
|
+
class CanonicalStringTest < Test::Unit::TestCase
|
61
|
+
def setup
|
62
|
+
@request = Net::HTTP::Post.new('/test')
|
63
|
+
@canonical_string = Authentication::CanonicalString.new(@request)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_path_does_not_include_query_string
|
67
|
+
request = Net::HTTP::Get.new('/test/query/string?foo=bar&baz=quux')
|
68
|
+
assert_equal '/test/query/string', Authentication::CanonicalString.new(request).send(:path)
|
69
|
+
|
70
|
+
# Make sure things still work when there is *no* query string
|
71
|
+
request = Net::HTTP::Get.new('/')
|
72
|
+
assert_equal '/', Authentication::CanonicalString.new(request).send(:path)
|
73
|
+
request = Net::HTTP::Get.new('/foo/bar')
|
74
|
+
assert_equal '/foo/bar', Authentication::CanonicalString.new(request).send(:path)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_path_includes_significant_query_strings
|
78
|
+
significant_query_strings = [
|
79
|
+
['/test/query/string?acl', '/test/query/string?acl'],
|
80
|
+
['/test/query/string?acl&foo=bar', '/test/query/string?acl'],
|
81
|
+
['/test/query/string?foo=bar&acl', '/test/query/string?acl'],
|
82
|
+
['/test/query/string?acl=foo', '/test/query/string?acl'],
|
83
|
+
['/test/query/string?torrent=foo', '/test/query/string?torrent'],
|
84
|
+
['/test/query/string?logging=foo', '/test/query/string?logging'],
|
85
|
+
['/test/query/string?bar=baz&acl=foo', '/test/query/string?acl']
|
86
|
+
]
|
87
|
+
|
88
|
+
significant_query_strings.each do |uncleaned_path, expected_cleaned_path|
|
89
|
+
assert_equal expected_cleaned_path, Authentication::CanonicalString.new(Net::HTTP::Get.new(uncleaned_path)).send(:path)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_default_headers_set
|
94
|
+
Authentication::CanonicalString.default_headers.each do |header|
|
95
|
+
assert @canonical_string.headers.include?(header)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_interesting_headers_are_copied_over
|
100
|
+
an_interesting_header = 'content-md5'
|
101
|
+
string_without_interesting_header = Authentication::CanonicalString.new(@request)
|
102
|
+
assert string_without_interesting_header.headers[an_interesting_header].empty?
|
103
|
+
|
104
|
+
# Add an interesting header
|
105
|
+
@request[an_interesting_header] = 'foo'
|
106
|
+
string_with_interesting_header = Authentication::CanonicalString.new(@request)
|
107
|
+
assert_equal 'foo', string_with_interesting_header.headers[an_interesting_header]
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_canonical_string
|
111
|
+
request = AmazonDocExampleData::Example1.request
|
112
|
+
assert_equal AmazonDocExampleData::Example1.canonical_string, Authentication::CanonicalString.new(request)
|
113
|
+
end
|
114
|
+
end
|
data/test/base_test.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class BaseTest < Test::Unit::TestCase
|
4
|
+
def test_connection_established
|
5
|
+
assert_raises(NoConnectionEstablished) do
|
6
|
+
Base.connection
|
7
|
+
end
|
8
|
+
|
9
|
+
Base.establish_connection!(:access_key_id => '123', :secret_access_key => 'abc')
|
10
|
+
assert_kind_of Connection, Base.connection
|
11
|
+
|
12
|
+
instance = Base.new
|
13
|
+
assert_equal instance.send(:connection), Base.connection
|
14
|
+
assert_equal instance.send(:http), Base.connection.http
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_respond_with
|
18
|
+
assert_equal Base::Response, Base.send(:response_class)
|
19
|
+
Base.send(:respond_with, Bucket::Response) do
|
20
|
+
assert_equal Bucket::Response, Base.send(:response_class)
|
21
|
+
end
|
22
|
+
assert_equal Base::Response, Base.send(:response_class)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_request_tries_again_when_encountering_an_internal_error
|
26
|
+
mock_connection_for(Bucket, :returns => [
|
27
|
+
# First request is an internal error
|
28
|
+
{:body => Fixtures::Errors.internal_error, :code => 500, :error => true},
|
29
|
+
# Second request is a success
|
30
|
+
{:body => Fixtures::Buckets.empty_bucket, :code => 200}
|
31
|
+
])
|
32
|
+
bucket = nil # Block scope hack
|
33
|
+
assert_nothing_raised do
|
34
|
+
bucket = Bucket.find('marcel')
|
35
|
+
end
|
36
|
+
# Don't call objects 'cause we don't want to make another request
|
37
|
+
assert bucket.object_cache.empty?
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_request_tries_up_to_three_times
|
41
|
+
mock_connection_for(Bucket, :returns => [
|
42
|
+
# First request is an internal error
|
43
|
+
{:body => Fixtures::Errors.internal_error, :code => 500, :error => true},
|
44
|
+
# Second request is also an internal error
|
45
|
+
{:body => Fixtures::Errors.internal_error, :code => 500, :error => true},
|
46
|
+
# Ditto third
|
47
|
+
{:body => Fixtures::Errors.internal_error, :code => 500, :error => true},
|
48
|
+
# Fourth works
|
49
|
+
{:body => Fixtures::Buckets.empty_bucket, :code => 200}
|
50
|
+
])
|
51
|
+
bucket = nil # Block scope hack
|
52
|
+
assert_nothing_raised do
|
53
|
+
bucket = Bucket.find('marcel')
|
54
|
+
end
|
55
|
+
# Don't call objects 'cause we don't want to make another request
|
56
|
+
assert bucket.object_cache.empty?
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_request_tries_again_three_times_and_gives_up
|
60
|
+
mock_connection_for(Bucket, :returns => [
|
61
|
+
# First request is an internal error
|
62
|
+
{:body => Fixtures::Errors.internal_error, :code => 500, :error => true},
|
63
|
+
# Second request is also an internal error
|
64
|
+
{:body => Fixtures::Errors.internal_error, :code => 500, :error => true},
|
65
|
+
# Ditto third
|
66
|
+
{:body => Fixtures::Errors.internal_error, :code => 500, :error => true},
|
67
|
+
# Ditto fourth
|
68
|
+
{:body => Fixtures::Errors.internal_error, :code => 500, :error => true},
|
69
|
+
])
|
70
|
+
assert_raises(InternalError) do
|
71
|
+
Bucket.find('marcel')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class MultiConnectionsTest < Test::Unit::TestCase
|
77
|
+
class ClassToTestSettingCurrentBucket < Base
|
78
|
+
set_current_bucket_to 'foo'
|
79
|
+
end
|
80
|
+
|
81
|
+
def setup
|
82
|
+
Base.send(:connections).clear
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_default_connection_options_are_used_for_subsequent_connections
|
86
|
+
assert !Base.connected?
|
87
|
+
|
88
|
+
assert_raises(MissingAccessKey) do
|
89
|
+
Base.establish_connection!
|
90
|
+
end
|
91
|
+
|
92
|
+
assert !Base.connected?
|
93
|
+
|
94
|
+
assert_raises(NoConnectionEstablished) do
|
95
|
+
Base.connection
|
96
|
+
end
|
97
|
+
|
98
|
+
assert_nothing_raised do
|
99
|
+
Base.establish_connection!(:access_key_id => '123', :secret_access_key => 'abc')
|
100
|
+
end
|
101
|
+
|
102
|
+
assert Base.connected?
|
103
|
+
|
104
|
+
assert_nothing_raised do
|
105
|
+
Base.connection
|
106
|
+
end
|
107
|
+
|
108
|
+
# All subclasses are currently using the default connection
|
109
|
+
assert_equal Base.connection, Bucket.connection
|
110
|
+
|
111
|
+
# No need to pass in the required options. The default connection will supply them
|
112
|
+
assert_nothing_raised do
|
113
|
+
Bucket.establish_connection!(:server => 'foo.s3.amazonaws.com')
|
114
|
+
end
|
115
|
+
|
116
|
+
assert Base.connection != Bucket.connection
|
117
|
+
assert_equal '123', Bucket.connection.access_key_id
|
118
|
+
assert_equal 'foo', Bucket.connection.subdomain
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_current_bucket
|
122
|
+
Base.establish_connection!(:access_key_id => '123', :secret_access_key => 'abc')
|
123
|
+
assert_raises(CurrentBucketNotSpecified) do
|
124
|
+
Base.current_bucket
|
125
|
+
end
|
126
|
+
|
127
|
+
S3Object.establish_connection!(:server => 'foo-bucket.s3.amazonaws.com')
|
128
|
+
assert_nothing_raised do
|
129
|
+
assert_equal 'foo-bucket', S3Object.current_bucket
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_setting_the_current_bucket
|
134
|
+
assert_equal 'foo', ClassToTestSettingCurrentBucket.current_bucket
|
135
|
+
end
|
136
|
+
end
|
data/test/bucket_test.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class BucketTest < Test::Unit::TestCase
|
4
|
+
def test_bucket_name_validation
|
5
|
+
valid_names = %w(123 joe step-one step_two step3 step_4 step-5 step.six)
|
6
|
+
invalid_names = ['12', 'jo', 'kevin spacey', 'larry@wall', '', 'a' * 256]
|
7
|
+
validate_name = Proc.new {|name| Bucket.send(:validate_name!, name)}
|
8
|
+
valid_names.each do |valid_name|
|
9
|
+
assert_nothing_raised { validate_name[valid_name] }
|
10
|
+
end
|
11
|
+
|
12
|
+
invalid_names.each do |invalid_name|
|
13
|
+
assert_raises(InvalidBucketName) { validate_name[invalid_name] }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_empty_bucket
|
18
|
+
mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.empty_bucket, :code => 200})
|
19
|
+
bucket = Bucket.find('marcel_molina')
|
20
|
+
assert bucket.empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_bucket_with_one_file
|
24
|
+
mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_one_key, :code => 200})
|
25
|
+
bucket = Bucket.find('marcel_molina')
|
26
|
+
assert !bucket.empty?
|
27
|
+
assert_equal 1, bucket.size
|
28
|
+
assert_equal %w(tongue_overload.jpg), bucket.objects.map {|object| object.key}
|
29
|
+
assert bucket['tongue_overload.jpg']
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_bucket_with_more_than_one_file
|
33
|
+
mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_more_than_one_key, :code => 200})
|
34
|
+
bucket = Bucket.find('marcel_molina')
|
35
|
+
assert !bucket.empty?
|
36
|
+
assert_equal 2, bucket.size
|
37
|
+
assert_equal %w(beluga_baby.jpg tongue_overload.jpg), bucket.objects.map {|object| object.key}.sort
|
38
|
+
assert bucket['tongue_overload.jpg']
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_bucket_path
|
42
|
+
assert_equal '/bucket_name?max-keys=2', Bucket.send(:path, 'bucket_name', :max_keys => 2)
|
43
|
+
assert_equal '/bucket_name', Bucket.send(:path, 'bucket_name', {})
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_should_not_be_truncated
|
47
|
+
mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.bucket_with_more_than_one_key, :code => 200})
|
48
|
+
bucket = Bucket.find('marcel_molina')
|
49
|
+
assert !bucket.is_truncated
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_be_truncated
|
53
|
+
mock_connection_for(Bucket, :returns => {:body => Fixtures::Buckets.truncated_bucket_with_more_than_one_key, :code => 200})
|
54
|
+
bucket = Bucket.find('marcel_molina')
|
55
|
+
assert bucket.is_truncated
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_bucket_name_should_have_leading_slash_prepended_only_once_when_forcing_a_delete
|
59
|
+
# References bug: http://rubyforge.org/tracker/index.php?func=detail&aid=19158&group_id=2409&atid=9356
|
60
|
+
bucket_name = 'foo'
|
61
|
+
expected_bucket_path = "/#{bucket_name}"
|
62
|
+
|
63
|
+
mock_bucket = flexmock('Mock bucket') do |mock|
|
64
|
+
mock.should_receive(:delete_all).once
|
65
|
+
end
|
66
|
+
mock_response = flexmock('Mock delete response') do |mock|
|
67
|
+
mock.should_receive(:success?).once
|
68
|
+
end
|
69
|
+
|
70
|
+
flexmock(Bucket).should_receive(:find).with(bucket_name).once.and_return(mock_bucket)
|
71
|
+
flexmock(Base).should_receive(:delete).with(expected_bucket_path).once.and_return(mock_response)
|
72
|
+
Bucket.delete(bucket_name, :force => true)
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ConnectionTest < Test::Unit::TestCase
|
4
|
+
attr_reader :keys
|
5
|
+
def setup
|
6
|
+
@keys = {:access_key_id => '123', :secret_access_key => 'abc'}.freeze
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_creating_a_connection
|
10
|
+
connection = Connection.new(keys)
|
11
|
+
assert_kind_of Net::HTTP, connection.http
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_use_ssl_option_is_set_in_connection
|
15
|
+
connection = Connection.new(keys.merge(:use_ssl => true))
|
16
|
+
assert connection.http.use_ssl?
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_setting_port_to_443_implies_use_ssl
|
20
|
+
connection = Connection.new(keys.merge(:port => 443))
|
21
|
+
assert connection.http.use_ssl?
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_protocol
|
25
|
+
connection = Connection.new(keys)
|
26
|
+
assert_equal 'http://', connection.protocol
|
27
|
+
connection = Connection.new(keys.merge(:use_ssl => true))
|
28
|
+
assert_equal 'https://', connection.protocol
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_url_for_honors_use_ssl_option_if_it_is_false_even_if_connection_has_use_ssl_option_set
|
32
|
+
# References bug: http://rubyforge.org/tracker/index.php?func=detail&aid=17628&group_id=2409&atid=9356
|
33
|
+
connection = Connection.new(keys.merge(:use_ssl => true))
|
34
|
+
assert_match %r(^http://), connection.url_for('/pathdoesnotmatter', :authenticated => false, :use_ssl => false)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_connection_is_not_persistent_by_default
|
38
|
+
connection = Connection.new(keys)
|
39
|
+
assert !connection.persistent?
|
40
|
+
|
41
|
+
connection = Connection.new(keys.merge(:persistent => true))
|
42
|
+
assert connection.persistent?
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_server_and_port_are_passed_onto_connection
|
46
|
+
connection = Connection.new(keys)
|
47
|
+
options = connection.instance_variable_get('@options')
|
48
|
+
assert_equal connection.http.address, options[:server]
|
49
|
+
assert_equal connection.http.port, options[:port]
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_not_including_required_access_keys_raises
|
53
|
+
assert_raises(MissingAccessKey) do
|
54
|
+
Connection.new
|
55
|
+
end
|
56
|
+
|
57
|
+
assert_raises(MissingAccessKey) do
|
58
|
+
Connection.new(:access_key_id => '123')
|
59
|
+
end
|
60
|
+
|
61
|
+
assert_nothing_raised do
|
62
|
+
Connection.new(keys)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_access_keys_extracted
|
67
|
+
connection = Connection.new(keys)
|
68
|
+
assert_equal '123', connection.access_key_id
|
69
|
+
assert_equal 'abc', connection.secret_access_key
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_request_method_class_lookup
|
73
|
+
connection = Connection.new(keys)
|
74
|
+
expectations = {
|
75
|
+
:get => Net::HTTP::Get, :post => Net::HTTP::Post,
|
76
|
+
:put => Net::HTTP::Put, :delete => Net::HTTP::Delete,
|
77
|
+
:head => Net::HTTP::Head
|
78
|
+
}
|
79
|
+
|
80
|
+
expectations.each do |verb, klass|
|
81
|
+
assert_equal klass, connection.send(:request_method, verb)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_url_for_uses_default_protocol_server_and_port
|
86
|
+
connection = Connection.new(:access_key_id => '123', :secret_access_key => 'abc', :port => 80)
|
87
|
+
assert_match %r(^http://s3\.amazonaws\.com/foo\?), connection.url_for('/foo')
|
88
|
+
|
89
|
+
connection = Connection.new(:access_key_id => '123', :secret_access_key => 'abc', :use_ssl => true, :port => 443)
|
90
|
+
assert_match %r(^https://s3\.amazonaws\.com/foo\?), connection.url_for('/foo')
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_url_for_remembers_custom_protocol_server_and_port
|
94
|
+
connection = Connection.new(:access_key_id => '123', :secret_access_key => 'abc', :server => 'example.org', :port => 555, :use_ssl => true)
|
95
|
+
assert_match %r(^https://example\.org:555/foo\?), connection.url_for('/foo')
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_url_for_with_and_without_authenticated_urls
|
99
|
+
connection = Connection.new(:access_key_id => '123', :secret_access_key => 'abc', :server => 'example.org')
|
100
|
+
authenticated = lambda {|url| url['?AWSAccessKeyId']}
|
101
|
+
assert authenticated[connection.url_for('/foo')]
|
102
|
+
assert authenticated[connection.url_for('/foo', :authenticated => true)]
|
103
|
+
assert !authenticated[connection.url_for('/foo', :authenticated => false)]
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_connecting_through_a_proxy
|
107
|
+
connection = nil
|
108
|
+
assert_nothing_raised do
|
109
|
+
connection = Connection.new(keys.merge(:proxy => sample_proxy_settings))
|
110
|
+
end
|
111
|
+
assert connection.http.proxy?
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_request_only_escapes_the_path_the_first_time_it_runs_and_not_subsequent_times
|
115
|
+
connection = Connection.new(@keys)
|
116
|
+
unescaped_path = 'path with spaces'
|
117
|
+
escaped_path = 'path%20with%20spaces'
|
118
|
+
|
119
|
+
flexmock(Connection).should_receive(:prepare_path).with(unescaped_path).once.and_return(escaped_path).ordered
|
120
|
+
flexmock(connection.http).should_receive(:request).and_raise(Errno::EPIPE).ordered
|
121
|
+
flexmock(connection.http).should_receive(:request).ordered
|
122
|
+
connection.request :put, unescaped_path
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_if_request_has_no_body_then_the_content_length_is_set_to_zero
|
126
|
+
# References bug: http://rubyforge.org/tracker/index.php?func=detail&aid=13052&group_id=2409&atid=9356
|
127
|
+
connection = Connection.new(@keys)
|
128
|
+
flexmock(Net::HTTP::Put).new_instances.should_receive(:content_length=).once.with(0).ordered
|
129
|
+
flexmock(connection.http).should_receive(:request).once.ordered
|
130
|
+
connection.request :put, 'path does not matter'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
class ConnectionOptionsTest < Test::Unit::TestCase
|
135
|
+
|
136
|
+
def setup
|
137
|
+
@options = generate_options(:server => 'example.org', :port => 555)
|
138
|
+
@default_options = generate_options
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_server_extracted
|
142
|
+
assert_key_transfered(:server, 'example.org', @options)
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_port_extracted
|
146
|
+
assert_key_transfered(:port, 555, @options)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_server_defaults_to_default_host
|
150
|
+
assert_equal DEFAULT_HOST, @default_options[:server]
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_port_defaults_to_80_if_use_ssl_is_false
|
154
|
+
assert_equal 80, @default_options[:port]
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_port_is_set_to_443_if_use_ssl_is_true
|
158
|
+
options = generate_options(:use_ssl => true)
|
159
|
+
assert_equal 443, options[:port]
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_explicit_port_trumps_use_ssl
|
163
|
+
options = generate_options(:port => 555, :use_ssl => true)
|
164
|
+
assert_equal 555, options[:port]
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_invalid_options_raise
|
168
|
+
assert_raises(InvalidConnectionOption) do
|
169
|
+
generate_options(:host => 'campfire.s3.amazonaws.com')
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_not_specifying_all_required_proxy_settings_raises
|
174
|
+
assert_raises(ArgumentError) do
|
175
|
+
generate_options(:proxy => {})
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_not_specifying_proxy_option_at_all_does_not_raise
|
180
|
+
assert_nothing_raised do
|
181
|
+
generate_options
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_specifying_all_required_proxy_settings
|
186
|
+
assert_nothing_raised do
|
187
|
+
generate_options(:proxy => sample_proxy_settings)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_only_host_setting_is_required
|
192
|
+
assert_nothing_raised do
|
193
|
+
generate_options(:proxy => {:host => 'http://google.com'})
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_proxy_settings_are_extracted
|
198
|
+
options = generate_options(:proxy => sample_proxy_settings)
|
199
|
+
assert_equal sample_proxy_settings.values.map {|value| value.to_s}.sort, options.proxy_settings.map {|value| value.to_s}.sort
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_recognizing_that_the_settings_want_to_connect_through_a_proxy
|
203
|
+
options = generate_options(:proxy => sample_proxy_settings)
|
204
|
+
assert options.connecting_through_proxy?
|
205
|
+
end
|
206
|
+
|
207
|
+
private
|
208
|
+
def assert_key_transfered(key, value, options)
|
209
|
+
assert_equal value, options[key]
|
210
|
+
end
|
211
|
+
|
212
|
+
def generate_options(options = {})
|
213
|
+
Connection::Options.new(options)
|
214
|
+
end
|
215
|
+
end
|