Skip to content

Commit

Permalink
Merge pull request #2356 from stanhu/sh-only-include-x-amz-acl-for-aws
Browse files Browse the repository at this point in the history
Only include `x-amz-acl` header for AWS
  • Loading branch information
mshibuya committed Dec 22, 2018
2 parents 6c7b126 + f8bcd47 commit 500401c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/carrierwave/storage/fog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def public_url
end
else
# AWS/Google optimized for speed over correctness
case @uploader.fog_credentials[:provider].to_s
case fog_provider
when 'AWS'
# check if some endpoint is set in fog_credentials
if @uploader.fog_credentials.has_key?(:endpoint)
Expand Down Expand Up @@ -466,7 +466,15 @@ def file
end

def acl_header
{'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private'}
if fog_provider == 'AWS'
{ 'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private' }
else
{}
end
end

def fog_provider
@uploader.fog_credentials[:provider].to_s
end

def read_source_file(file_body)
Expand Down
22 changes: 22 additions & 0 deletions spec/storage/fog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
end
end

context '#acl_header' do
let(:store_path) { 'uploads/test+.jpg' }

before do
allow(@uploader).to receive(:store_path).and_return(store_path)
end

it 'includes acl_header when necessary' do
if file.is_a?(CarrierWave::Storage::Fog::File)
if @provider == 'AWS'
expect(@storage.connection).to receive(:copy_object)
.with(anything, anything, anything, anything, { "x-amz-acl"=>"public-read" }).and_call_original
else
expect(@storage.connection).to receive(:copy_object)
.with(anything, anything, anything, anything, {}).and_call_original
end
end

@storage.store!(file)
end
end

describe '#store!' do
let(:store_path) { 'uploads/test+.jpg' }

Expand Down

0 comments on commit 500401c

Please sign in to comment.