mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #3344 from janraasch/feature/fail-on-non-us_ascii-user-meta-data
[aws|put_object] guard against non-us_ascii x-amz-meta-* values
This commit is contained in:
commit
d4868d6fde
2 changed files with 29 additions and 1 deletions
|
@ -17,7 +17,7 @@ module Fog
|
|||
# @option options Expires [String] Cache expiry
|
||||
# @option options x-amz-acl [String] Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
||||
# @option options x-amz-storage-class [String] Default is 'STANDARD', set to 'REDUCED_REDUNDANCY' for non-critical, reproducable data
|
||||
# @option options x-amz-meta-#{name} Headers to be returned with object, note total size of request without body must be less than 8 KB.
|
||||
# @option options x-amz-meta-#{name} Headers to be returned with object, note total size of request without body must be less than 8 KB. Each name, value pair must conform to US-ASCII.
|
||||
#
|
||||
# @return [Excon::Response] response:
|
||||
# * headers [Hash]:
|
||||
|
@ -25,9 +25,21 @@ module Fog
|
|||
#
|
||||
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPUT.html
|
||||
|
||||
def self.conforming_to_us_ascii!(keys, hash)
|
||||
return if RUBY_VERSION =~ /^1\.8\./
|
||||
keys.each do |k|
|
||||
v = hash[k]
|
||||
if !v.encode(::Encoding::US_ASCII, :undef => :replace).eql?(v)
|
||||
raise Excon::Errors::BadRequest.new("invalid #{k} header: value must be us-ascii")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def put_object(bucket_name, object_name, data, options = {})
|
||||
data = Fog::Storage.parse_data(data)
|
||||
headers = data[:headers].merge!(options)
|
||||
self.class.conforming_to_us_ascii! headers.keys.grep(/^x-amz-meta-/), headers
|
||||
|
||||
request({
|
||||
:body => data[:body],
|
||||
:expects => 200,
|
||||
|
@ -48,6 +60,8 @@ module Fog
|
|||
define_mock_acl(bucket_name, object_name, options)
|
||||
|
||||
data = parse_mock_data(data)
|
||||
headers = data[:headers].merge!(options)
|
||||
Fog::Storage::AWS::Real.conforming_to_us_ascii! headers.keys.grep(/^x-amz-meta-/), headers
|
||||
bucket = verify_mock_bucket_exists(bucket_name)
|
||||
|
||||
options['Content-Type'] ||= data[:headers]['Content-Type']
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# encoding: utf-8
|
||||
|
||||
Shindo.tests('AWS::Storage | object requests', ['aws']) do
|
||||
@directory = Fog::Storage[:aws].directories.create(:key => 'fogobjecttests-' + Time.now.to_i.to_s(32))
|
||||
@aws_owner = Fog::Storage[:aws].get_bucket_acl(@directory.key).body['Owner']
|
||||
|
@ -16,6 +18,12 @@ Shindo.tests('AWS::Storage | object requests', ['aws']) do
|
|||
Fog::Storage[:aws].put_object(@directory.identity, 'fog_object', lorem_file)
|
||||
end
|
||||
|
||||
if RUBY_VERSION =~ /^1\.8\./
|
||||
tests("#put_object('#{@directory.identity}', 'fog_object', lorem_file, {'x-amz-meta-json' => 'ä'}").succeeds do
|
||||
Fog::Storage[:aws].put_object(@directory.identity, 'fog_object', lorem_file, {'x-amz-meta-json' => 'ä'})
|
||||
end
|
||||
end
|
||||
|
||||
tests("#copy_object('#{@directory.identity}', 'fog_object', '#{@directory.identity}', 'fog_other_object')").succeeds do
|
||||
Fog::Storage[:aws].copy_object(@directory.identity, 'fog_object', @directory.identity, 'fog_other_object')
|
||||
end
|
||||
|
@ -124,6 +132,12 @@ Shindo.tests('AWS::Storage | object requests', ['aws']) do
|
|||
Fog::Storage[:aws].put_object(fognonbucket, 'fog_non_object', lorem_file)
|
||||
end
|
||||
|
||||
unless RUBY_VERSION =~ /^1\.8\./
|
||||
tests("#put_object('#{@directory.identity}', 'fog_object', lorem_file, {'x-amz-meta-json' => 'ä'}").raises(Excon::Errors::BadRequest) do
|
||||
Fog::Storage[:aws].put_object(@directory.identity, 'fog_object', lorem_file, {'x-amz-meta-json' => 'ä'})
|
||||
end
|
||||
end
|
||||
|
||||
tests("#copy_object('#{fognonbucket}', 'fog_object', '#{@directory.identity}', 'fog_other_object')").raises(Excon::Errors::NotFound) do
|
||||
Fog::Storage[:aws].copy_object(fognonbucket, 'fog_object', @directory.identity, 'fog_other_object')
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue