FIX: Ensure lightbox image download has correct content disposition in S3 (#7845)

This commit is contained in:
Penar Musaraj
2019-07-04 11:32:51 -04:00
committed by GitHub
parent e9bb13c630
commit 03805e5a76
4 changed files with 40 additions and 5 deletions

View File

@ -395,4 +395,31 @@ describe FileStore::S3Store do
end
end
describe ".download_url" do
include_context "s3 helpers"
let(:s3_object) { stub }
it "returns correct short URL with dl=1 param" do
expect(store.download_url(upload)).to eq("#{upload.short_path}?dl=1")
end
end
describe ".url_for" do
include_context "s3 helpers"
let(:s3_object) { stub }
it "returns signed URL with content disposition when requesting to download image" do
s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
s3_bucket.expects(:object).with("original/1X/#{upload.sha1}.png").returns(s3_object)
opts = {
expires_in: S3Helper::DOWNLOAD_URL_EXPIRES_AFTER_SECONDS,
response_content_disposition: "attachment; filename=\"#{upload.original_filename}\""
}
s3_object.expects(:presigned_url).with(:get, opts)
expect(store.url_for(upload, force_download: true)).not_to eq(upload.url)
end
end
end