From 39bfc836b8eb7482acf2784423414895b6d876c6 Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Sun, 30 Jul 2017 11:00:55 -0400 Subject: Configure per-service request headers for direct uploads (#83) * Configure per-service request headers for direct uploads * Fix header hashes --- test/controllers/direct_uploads_controller_test.rb | 39 +++++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'test/controllers/direct_uploads_controller_test.rb') diff --git a/test/controllers/direct_uploads_controller_test.rb b/test/controllers/direct_uploads_controller_test.rb index f15fcff314..7ffa77ea73 100644 --- a/test/controllers/direct_uploads_controller_test.rb +++ b/test/controllers/direct_uploads_controller_test.rb @@ -13,12 +13,19 @@ if SERVICE_CONFIGURATIONS[:s3] end test "creating new direct upload" do + checksum = Digest::MD5.base64digest("Hello") + post rails_direct_uploads_url, params: { blob: { - filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } } + filename: "hello.txt", byte_size: 6, checksum: checksum, content_type: "text/plain" } } response.parsed_body.tap do |details| - assert_match(/#{SERVICE_CONFIGURATIONS[:s3][:bucket]}\.s3.(\S+)?amazonaws\.com/, details["upload_to_url"]) - assert_equal "hello.txt", ActiveStorage::Blob.find_signed(details["signed_blob_id"]).filename.to_s + assert_equal ActiveStorage::Blob.find(details["id"]), ActiveStorage::Blob.find_signed(details["signed_id"]) + assert_equal "hello.txt", details["filename"] + assert_equal 6, details["byte_size"] + assert_equal checksum, details["checksum"] + assert_equal "text/plain", details["content_type"] + assert_match /#{SERVICE_CONFIGURATIONS[:s3][:bucket]}\.s3.(\S+)?amazonaws\.com/, details["direct_upload"]["url"] + assert_equal({ "Content-Type" => "text/plain", "Content-MD5" => checksum }, details["direct_upload"]["headers"]) end end end @@ -40,12 +47,19 @@ if SERVICE_CONFIGURATIONS[:gcs] end test "creating new direct upload" do + checksum = Digest::MD5.base64digest("Hello") + post rails_direct_uploads_url, params: { blob: { - filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } } + filename: "hello.txt", byte_size: 6, checksum: checksum, content_type: "text/plain" } } @response.parsed_body.tap do |details| - assert_match %r{storage\.googleapis\.com/#{@config[:bucket]}}, details["upload_to_url"] - assert_equal "hello.txt", ActiveStorage::Blob.find_signed(details["signed_blob_id"]).filename.to_s + assert_equal ActiveStorage::Blob.find(details["id"]), ActiveStorage::Blob.find_signed(details["signed_id"]) + assert_equal "hello.txt", details["filename"] + assert_equal 6, details["byte_size"] + assert_equal checksum, details["checksum"] + assert_equal "text/plain", details["content_type"] + assert_match %r{storage\.googleapis\.com/#{@config[:bucket]}}, details["direct_upload"]["url"] + assert_equal({ "Content-Type" => "text/plain", "Content-MD5" => checksum }, details["direct_upload"]["headers"]) end end end @@ -55,12 +69,19 @@ end class ActiveStorage::DiskDirectUploadsControllerTest < ActionDispatch::IntegrationTest test "creating new direct upload" do + checksum = Digest::MD5.base64digest("Hello") + post rails_direct_uploads_url, params: { blob: { - filename: "hello.txt", byte_size: 6, checksum: Digest::MD5.base64digest("Hello"), content_type: "text/plain" } } + filename: "hello.txt", byte_size: 6, checksum: checksum, content_type: "text/plain" } } @response.parsed_body.tap do |details| - assert_match /rails\/active_storage\/disk/, details["upload_to_url"] - assert_equal "hello.txt", ActiveStorage::Blob.find_signed(details["signed_blob_id"]).filename.to_s + assert_equal ActiveStorage::Blob.find(details["id"]), ActiveStorage::Blob.find_signed(details["signed_id"]) + assert_equal "hello.txt", details["filename"] + assert_equal 6, details["byte_size"] + assert_equal checksum, details["checksum"] + assert_equal "text/plain", details["content_type"] + assert_match /rails\/active_storage\/disk/, details["direct_upload"]["url"] + assert_equal({ "Content-Type" => "text/plain" }, details["direct_upload"]["headers"]) end end end -- cgit v1.2.3