diff options
-rw-r--r-- | lib/active_file/site/gcs_site.rb | 5 | ||||
-rw-r--r-- | test/site/gcs_site_test.rb | 10 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/active_file/site/gcs_site.rb b/lib/active_file/site/gcs_site.rb index c5f3d634cf..001339f2bd 100644 --- a/lib/active_file/site/gcs_site.rb +++ b/lib/active_file/site/gcs_site.rb @@ -27,6 +27,11 @@ class ActiveFile::Site::GCSSite < ActiveFile::Site end + def url(key, expires_in:, disposition:, filename:) + file_for(key).signed_url(expires: expires_in) + "&" + + { "response-content-disposition" => "#{disposition}; filename=\"#{filename}\"" }.to_query + end + def byte_size(key) file_for(key).size end diff --git a/test/site/gcs_site_test.rb b/test/site/gcs_site_test.rb index c5f32a0595..f6848b2fe9 100644 --- a/test/site/gcs_site_test.rb +++ b/test/site/gcs_site_test.rb @@ -2,9 +2,17 @@ require "site/shared_site_tests" if SITE_CONFIGURATIONS[:gcs] class ActiveFile::Site::GCSSiteTest < ActiveSupport::TestCase - SITE = ActiveFile::Site.configure(:GCS, SITE_CONFIGURATIONS[:gcs]) + SITE = ActiveFile::Site.configure(:GCS, SITE_CONFIGURATIONS[:gcs]) + SIGNER = Google::Cloud::Storage::File::Signer.from_bucket(SITE.bucket, ActiveFile::Site::SharedSiteTests::FIXTURE_KEY) include ActiveFile::Site::SharedSiteTests + + test "signed URL generation" do + travel_to Time.now do + assert_equal SIGNER.signed_url(expires: 120) + "&response-content-disposition=inline%3B+filename%3D%22test.txt%22", + @site.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: "test.txt") + end + end end else puts "Skipping GCS Site tests because no GCS configuration was supplied" |