Skip to content

Commit

Permalink
Merge pull request #2397 from bettyblocks/master
Browse files Browse the repository at this point in the history
Allow custom expires-at when building an authenticated-url
  • Loading branch information
mshibuya committed May 14, 2019
2 parents 85d2111 + 64aab24 commit 12d48d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/carrierwave/storage/fog.rb
Expand Up @@ -190,7 +190,7 @@ def authenticated_url(options = {})
# avoid a get by using local references
local_directory = connection.directories.new(:key => @uploader.fog_directory)
local_file = local_directory.files.new(:key => path)
expire_at = ::Fog::Time.now + @uploader.fog_authenticated_url_expiration
expire_at = options[:expire_at] || ::Fog::Time.now + @uploader.fog_authenticated_url_expiration
case @uploader.fog_credentials[:provider]
when 'AWS', 'Google'
# Older versions of fog-google do not support options as a parameter
Expand Down
11 changes: 11 additions & 0 deletions spec/storage/fog_helper.rb
Expand Up @@ -447,6 +447,17 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
end
end

it "should have an custom authenticated_url" do
if ['AWS', 'Rackspace', 'Google', 'OpenStack', 'AzureRM'].include?(@provider)
timestamp = ::Fog::Time.now + 999
if @provider == "AWS"
expect(@fog_file.authenticated_url({expire_at: timestamp })).to include("Expires=999&")
elsif @provider == "Google"
expect(@fog_file.authenticated_url({expire_at: timestamp })).to include("Expires=#{timestamp.to_i}")
end
end
end

it 'should generate correct filename' do
expect(@fog_file.filename).to eq('private.txt')
end
Expand Down

0 comments on commit 12d48d7

Please sign in to comment.