зеркало из https://github.com/github/aws-s3.git
#url_for supports :query for custom query params
AWS::S3::S3Object#url(:query => {}) AWS::S3::S3Object.url_for(name, bucket, :query => {}) AWS::S3::S3Object.path!(bucket, name, :query => {})
This commit is contained in:
Родитель
c6b35e9300
Коммит
7a18d8b81e
|
@ -297,7 +297,11 @@ module AWS
|
|||
options.replace(bucket)
|
||||
bucket = nil
|
||||
end
|
||||
'/' << File.join(bucket_name(bucket), name)
|
||||
path = '/' << File.join(bucket_name(bucket), name)
|
||||
if (query = options[:query]).respond_to?(:to_query_string)
|
||||
path << query.to_query_string
|
||||
end
|
||||
path
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -102,6 +102,12 @@ class ConnectionTest < Test::Unit::TestCase
|
|||
assert authenticated[connection.url_for('/foo', :authenticated => true)]
|
||||
assert !authenticated[connection.url_for('/foo', :authenticated => false)]
|
||||
end
|
||||
|
||||
def test_url_for_with_canonical_query_params
|
||||
connection = Connection.new(:access_key_id => '123', :secret_access_key => 'abc', :server => 'example.org')
|
||||
dispositioned = lambda {|url| url['?response-content-disposition=a']}
|
||||
assert dispositioned[connection.url_for("/foo?response-content-disposition=a")]
|
||||
end
|
||||
|
||||
def test_connecting_through_a_proxy
|
||||
connection = nil
|
||||
|
|
|
@ -5,7 +5,7 @@ class ObjectTest < Test::Unit::TestCase
|
|||
bucket = Bucket.new(Parsing::XmlParser.new(Fixtures::Buckets.bucket_with_one_key))
|
||||
@object = bucket.objects.first
|
||||
end
|
||||
|
||||
|
||||
def test_header_settings_reader_and_writer
|
||||
headers = {'content-type' => 'text/plain'}
|
||||
mock_connection_for(S3Object, :returns => {:headers => headers})
|
||||
|
@ -57,6 +57,31 @@ class ObjectTest < Test::Unit::TestCase
|
|||
def test_object_has_owner
|
||||
assert_kind_of Owner, @object.owner
|
||||
end
|
||||
|
||||
def test_url_is_authenticated
|
||||
conn = Connection.new :access_key_id => '123', :secret_access_key => 'abc'
|
||||
|
||||
begin
|
||||
AWS::S3::Base.connections['AWS::S3::Base'] = conn
|
||||
authenticated = lambda {|url| url['?AWSAccessKeyId']}
|
||||
assert authenticated[@object.url]
|
||||
ensure
|
||||
AWS::S3::Base.connections.clear
|
||||
end
|
||||
end
|
||||
|
||||
def test_url_with_custom_query
|
||||
conn = Connection.new :access_key_id => '123', :secret_access_key => 'abc'
|
||||
|
||||
begin
|
||||
AWS::S3::Base.connections['AWS::S3::Base'] = conn
|
||||
assert_match 'response-content-disposition=attachment;%20filename%3Dfoo.txt',
|
||||
@object.url(:query => {
|
||||
'response-content-disposition' => 'attachment; filename=foo.txt'})
|
||||
ensure
|
||||
AWS::S3::Base.connections.clear
|
||||
end
|
||||
end
|
||||
|
||||
def test_owner_attributes_are_accessible
|
||||
owner = @object.owner
|
||||
|
@ -217,4 +242,4 @@ class ValueTest < Test::Unit::TestCase
|
|||
def test_response_is_accessible_from_value_object
|
||||
assert_equal @response, @value.response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче