mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add support for canonicalising AWS keys
We don’t just need to URL escape them, they need to be Unicode normalised too http://tools.ietf.org/html/rfc3987#section-5.3.2.2
This commit is contained in:
parent
95b353ff7f
commit
20a0f7dd3e
3 changed files with 11 additions and 0 deletions
|
@ -50,6 +50,7 @@ Gem::Specification.new do |s|
|
|||
s.add_dependency('net-ssh', '>=2.1.3')
|
||||
s.add_dependency('nokogiri', '~>1.5')
|
||||
s.add_dependency('ruby-hmac')
|
||||
s.add_dependency('unicode', "~> 0.4.4")
|
||||
|
||||
## List your development dependencies here. Development dependencies are
|
||||
## those that are only needed during development
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'fog/core'
|
||||
require 'fog/aws/credential_fetcher'
|
||||
require 'fog/aws/signaturev4'
|
||||
require 'unicode'
|
||||
module Fog
|
||||
module AWS
|
||||
extend Fog::Provider
|
||||
|
@ -84,6 +85,7 @@ module Fog
|
|||
end
|
||||
|
||||
def self.escape(string)
|
||||
string = Unicode::normalize_C(string)
|
||||
string.gsub(/([^a-zA-Z0-9_.\-~\/]+)/) {
|
||||
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
|
||||
}
|
||||
|
|
|
@ -6,4 +6,12 @@ Shindo.tests('AWS | signed_params', ['aws']) do
|
|||
tests('Keys can contain a hierarchical prefix which should not be escaped') do
|
||||
returns( Fog::AWS.escape( "key/with/prefix" ) ) { "key/with/prefix" }
|
||||
end
|
||||
|
||||
tests('Keys should be canonicalised using Unicode NFC') do
|
||||
returns( Fog::AWS.escape( "\u{00e9}" ) ) { "%C3%A9" }
|
||||
|
||||
tests('Characters with combining mark should be combined and then escaped') do
|
||||
returns( Fog::AWS.escape( "\u{0065}\u{0301}" ) ) { "%C3%A9" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue