From 64aab24f57e4e1f7489e9faa37d6782818c164cc Mon Sep 17 00:00:00 2001 From: Stephan Kaag Date: Thu, 9 May 2019 11:29:39 +0200 Subject: [PATCH] Allow custom expires-at when building an authenticated-url --- lib/carrierwave/storage/fog.rb | 2 +- spec/storage/fog_helper.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index c5c078e53..b00e72a79 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -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 diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index 455698a6b..9cc6b6888 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -443,6 +443,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