mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Rackspace Storage: fix expiring URLs that contain a hyphen
* props to Nathan Wenneker for pointing out the issue * added specs to ensure objects with a variety of characters are signed correctly
This commit is contained in:
parent
5a58840cf4
commit
15596e486d
2 changed files with 27 additions and 6 deletions
|
@ -24,13 +24,14 @@ module Fog
|
|||
|
||||
method = 'GET'
|
||||
expires = expires.to_i
|
||||
object_path = "#{@path}/#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object,"/")}"
|
||||
string_to_sign = "#{method}\n#{expires}\n#{object_path}"
|
||||
object_path_escaped = "#{@path}/#{Fog::Rackspace.escape(container)}/#{Fog::Rackspace.escape(object,"/")}"
|
||||
object_path_unescaped = "#{@path}/#{Fog::Rackspace.escape(container)}/#{object}"
|
||||
string_to_sign = "#{method}\n#{expires}\n#{object_path_unescaped}"
|
||||
|
||||
hmac = Fog::HMAC.new('sha1', @rackspace_temp_url_key)
|
||||
sig = sig_to_hex(hmac.sign(string_to_sign))
|
||||
|
||||
"https://#{@host}#{object_path}?temp_url_sig=#{sig}&temp_url_expires=#{expires}"
|
||||
"https://#{@host}#{object_path_escaped}?temp_url_sig=#{sig}&temp_url_expires=#{expires}"
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -35,11 +35,31 @@ Shindo.tests('Fog::Storage[:rackspace] | object requests', [:rackspace]) do
|
|||
Fog::Storage[:rackspace].delete_object('fogobjecttests', 'fog_object')
|
||||
end
|
||||
|
||||
# an object key with no special characters
|
||||
tests("#get_object_https_url('fogobjecttests', 'fog_object','expiration timestamp')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
expires_at = Time.now + 60
|
||||
object_url = Fog::Storage[:rackspace].get_object_https_url('fogobjecttests', 'fog_object', expires_at)
|
||||
object_url =~ /https:\/\/.*clouddrive.com\/[^\/]+\/[^\/]+\/fogobjecttests\/fog_object\?temp_url_sig=[0-9a-f]{40}&temp_url_expires=#{expires_at.to_i}/
|
||||
expires_at = 1344149532 # 2012-08-05 16:52:12 +1000
|
||||
storage = Fog::Storage::Rackspace.new(:rackspace_temp_url_key => "super_secret")
|
||||
object_url = storage.get_object_https_url('fogobjecttests', 'fog_object', expires_at)
|
||||
object_url =~ /https:\/\/.*clouddrive.com\/[^\/]+\/[^\/]+\/fogobjecttests\/fog_object\?temp_url_sig=8abd27f8345b6f3c5fceb9ef71d8ac59ffb15500&temp_url_expires=1344149532/
|
||||
end
|
||||
|
||||
# an object key nested under a /
|
||||
tests("#get_object_https_url('fogobjecttests', 'fog/object','expiration timestamp')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
expires_at = 1344149532 # 2012-08-05 16:52:12 +1000
|
||||
storage = Fog::Storage::Rackspace.new(:rackspace_temp_url_key => "super_secret")
|
||||
object_url = storage.get_object_https_url('fogobjecttests', 'fog/object', expires_at)
|
||||
object_url =~ /https:\/\/.*clouddrive.com\/[^\/]+\/[^\/]+\/fogobjecttests\/fog\/object\?temp_url_sig=1dc1de4544f75cf9eba85bde500059472c94adcd&temp_url_expires=1344149532/
|
||||
end
|
||||
|
||||
# an object key containing a -
|
||||
tests("#get_object_https_url('fogobjecttests', 'fog-object','expiration timestamp')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
expires_at = 1344149532 # 2012-08-05 16:52:12 +1000
|
||||
storage = Fog::Storage::Rackspace.new(:rackspace_temp_url_key => "super_secret")
|
||||
object_url = storage.get_object_https_url('fogobjecttests', 'fog-object', expires_at)
|
||||
object_url =~ /https:\/\/.*clouddrive.com\/[^\/]+\/[^\/]+\/fogobjecttests\/fog%2Dobject\?temp_url_sig=f664ec159300d91b2cb735249c630645b55b87a1&temp_url_expires=1344149532/
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue