зеркало из https://github.com/github/aws-s3.git
Normalize the :expires_in option to always be an integer even if the actual object passed in is a proxy to an integer, such as is the case with 2.hours from ActiveSupport which is actually an instance of ActiveSupport::Duration.
This commit is contained in:
Родитель
68cd7562a2
Коммит
0bc5391734
|
@ -1,5 +1,7 @@
|
|||
trunk:
|
||||
|
||||
- Bug #17458 fixed. Normalize the :expires_in option to always be an integer even if the actual object passed in is a proxy to an integer, such as is the case with 2.hours from ActiveSupport which is actually an instance of ActiveSupport::Duration. Reported by [Steve Kickert steve@riverocktech.com]
|
||||
|
||||
- Bug #19158 fixed. Don't prepend leading slash onto bucket name when deleting a bucket with the :force => true option.
|
||||
|
||||
- Bug #17628 fixed. Don't ignore :use_ssl => false in url_for when the connection is established over ssl. Reported by [Tom Fixed (tkat11)]
|
||||
|
|
|
@ -50,7 +50,7 @@ module AWS
|
|||
# parameterize these computations and arrange them in a string form appropriate to how they are used, in one case a http request
|
||||
# header value, and in the other case key/value query string parameter pairs.
|
||||
class Signature < String #:nodoc:
|
||||
attr_reader :request, :access_key_id, :secret_access_key
|
||||
attr_reader :request, :access_key_id, :secret_access_key, :options
|
||||
|
||||
def initialize(request, access_key_id, secret_access_key, options = {})
|
||||
super()
|
||||
|
@ -99,10 +99,9 @@ module AWS
|
|||
# More details about the various authentication schemes can be found in the docs for its containing module, Authentication.
|
||||
class QueryString < Signature #:nodoc:
|
||||
constant :DEFAULT_EXPIRY, 300 # 5 minutes
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
@options[:url_encode] = true
|
||||
options[:url_encode] = true
|
||||
self << build
|
||||
end
|
||||
|
||||
|
@ -115,8 +114,12 @@ module AWS
|
|||
# the +:expires_in+ option
|
||||
# 3) The current time in seconds since the epoch plus the default number of seconds (60 seconds)
|
||||
def expires
|
||||
return @options[:expires] if @options[:expires]
|
||||
date.to_i + (@options[:expires_in] || DEFAULT_EXPIRY)
|
||||
return options[:expires] if options[:expires]
|
||||
date.to_i + expires_in
|
||||
end
|
||||
|
||||
def expires_in
|
||||
options.has_key?(:expires_in) ? Integer(options[:expires_in]) : DEFAULT_EXPIRY
|
||||
end
|
||||
|
||||
# Keep in alphabetical order
|
||||
|
|
|
@ -30,7 +30,25 @@ class QueryStringAuthenticationTest < Test::Unit::TestCase
|
|||
query_string = Authentication::QueryString.new(request, key_id, secret, :expires => expires)
|
||||
assert_equal expires, query_string.send(:canonical_string).instance_variable_get(:@options)[:expires]
|
||||
assert_equal AmazonDocExampleData::Example3.query_string, query_string
|
||||
end
|
||||
end
|
||||
|
||||
def test_expires_in_is_coerced_to_being_an_integer_in_case_it_is_a_special_integer_proxy
|
||||
# References bug: http://rubyforge.org/tracker/index.php?func=detail&aid=17458&group_id=2409&atid=9356
|
||||
integer_proxy = Class.new do
|
||||
attr_reader :integer
|
||||
def initialize(integer)
|
||||
@integer = integer
|
||||
end
|
||||
|
||||
def to_int
|
||||
integer
|
||||
end
|
||||
end
|
||||
|
||||
actual_integer = 25
|
||||
query_string = Authentication::QueryString.new(request, key_id, secret, :expires_in => integer_proxy.new(actual_integer))
|
||||
assert_equal actual_integer, query_string.send(:expires_in)
|
||||
end
|
||||
|
||||
private
|
||||
def request; AmazonDocExampleData::Example3.request end
|
||||
|
|
Загрузка…
Ссылка в новой задаче