1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00

Merge pull request #133 from fcheung/fix_s3_signer

Fix S3 signature v4 signing
This commit is contained in:
Wesley Beary 2015-06-15 15:47:01 -05:00
commit ae2b2d7210
2 changed files with 21 additions and 12 deletions

View file

@ -79,18 +79,20 @@ DATA
protected protected
def canonical_path(path) def canonical_path(path)
#leading and trailing repeated slashes are collapsed, but not ones that appear elsewhere unless @service == 's3' #S3 implements signature v4 different - paths are not canonialized
path = path.gsub(%r{\A/+},'/').gsub(%r{/+\z},'/') #leading and trailing repeated slashes are collapsed, but not ones that appear elsewhere
components = path.split('/',-1) path = path.gsub(%r{\A/+},'/').gsub(%r{/+\z},'/')
path = components.inject([]) do |acc, component| components = path.split('/',-1)
case component path = components.inject([]) do |acc, component|
when '.' #canonicalize by removing . case component
when '..' then acc.pop#canonicalize by reducing .. when '.' #canonicalize by removing .
else when '..' then acc.pop#canonicalize by reducing ..
acc << component else
end acc << component
acc end
end.join('/') acc
end.join('/')
end
path.empty? ? '/' : path path.empty? ? '/' : path
end end

View file

@ -96,5 +96,12 @@ Shindo.tests('AWS | signaturev4', ['aws']) do
end end
end end
tests("s3 signer does not normalize path") do
signer=Fog::AWS::SignatureV4.new('AKIDEXAMPLE', 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY', 'us-east-1','s3')
returns(signer.sign({:query => {}, :headers => {'Host' => 'host.foo.com', 'Date' => 'Mon, 09 Sep 2011 23:36:00 GMT'}, :method => :get, :path => '//foo/../bar/./'}, @now)) do
'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/s3/aws4_request, SignedHeaders=date;host, Signature=72407ad06b8e5750360f42e8aad9f33a0be363bcfeecdcae0aea58c99709fb4a'
end
end
Fog::Time.now = ::Time.now Fog::Time.now = ::Time.now
end end