Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom expires-at when building an authenticated-url #2397

Merged
merged 1 commit into from May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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
Expand Down