diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-20 12:12:58 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-20 12:12:58 -0500 |
commit | c2a61cc9220aaec0a1aeac7452da2ca80250e92b (patch) | |
tree | ceb34b5ea9b8e35c9c32da9d79f4797a89bcd9db /test/service | |
parent | 1966c188cfb06b39a47082e2f6c6e33a43668ae5 (diff) | |
parent | 32331b19e1da8bdab3c9f6d1666ac2d3108e5042 (diff) | |
download | rails-c2a61cc9220aaec0a1aeac7452da2ca80250e92b.tar.gz rails-c2a61cc9220aaec0a1aeac7452da2ca80250e92b.tar.bz2 rails-c2a61cc9220aaec0a1aeac7452da2ca80250e92b.zip |
Merge branch 'master' into variants
Diffstat (limited to 'test/service')
-rw-r--r-- | test/service/configurator_test.rb | 1 | ||||
-rw-r--r-- | test/service/disk_service_test.rb | 2 | ||||
-rw-r--r-- | test/service/gcs_service_test.rb | 22 | ||||
-rw-r--r-- | test/service/mirror_service_test.rb | 4 | ||||
-rw-r--r-- | test/service/s3_service_test.rb | 43 |
5 files changed, 49 insertions, 23 deletions
diff --git a/test/service/configurator_test.rb b/test/service/configurator_test.rb index f8e4dccc9c..c69b8d5087 100644 --- a/test/service/configurator_test.rb +++ b/test/service/configurator_test.rb @@ -12,4 +12,3 @@ class ActiveStorage::Service::ConfiguratorTest < ActiveSupport::TestCase end end end - diff --git a/test/service/disk_service_test.rb b/test/service/disk_service_test.rb index f7752b25ef..e9a96003f1 100644 --- a/test/service/disk_service_test.rb +++ b/test/service/disk_service_test.rb @@ -7,6 +7,6 @@ class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase test "url generation" do assert_match /rails\/active_storage\/disk\/.*\/avatar\.png\?disposition=inline/, - @service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: "avatar.png") + @service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: "avatar.png") end end diff --git a/test/service/gcs_service_test.rb b/test/service/gcs_service_test.rb index 7d4700498b..4cde4b9289 100644 --- a/test/service/gcs_service_test.rb +++ b/test/service/gcs_service_test.rb @@ -1,4 +1,5 @@ require "service/shared_service_tests" +require "httparty" if SERVICE_CONFIGURATIONS[:gcs] class ActiveStorage::Service::GCSServiceTest < ActiveSupport::TestCase @@ -6,8 +7,27 @@ if SERVICE_CONFIGURATIONS[:gcs] include ActiveStorage::Service::SharedServiceTests + test "direct upload" do + begin + key = SecureRandom.base58(24) + data = "Something else entirely!" + direct_upload_url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size) + + HTTParty.put( + direct_upload_url, + body: data, + headers: { "Content-Type" => "text/plain" }, + debug_output: STDOUT + ) + + assert_equal data, @service.download(key) + ensure + @service.delete key + end + end + test "signed URL generation" do - travel_to Time.now do + freeze_time do url = SERVICE.bucket.signed_url(FIXTURE_KEY, expires: 120) + "&response-content-disposition=inline%3B+filename%3D%22test.txt%22" diff --git a/test/service/mirror_service_test.rb b/test/service/mirror_service_test.rb index 8bda01f169..fd3d8125d6 100644 --- a/test/service/mirror_service_test.rb +++ b/test/service/mirror_service_test.rb @@ -8,7 +8,7 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase end.to_h config = mirror_config.merge \ - mirror: { service: "Mirror", primary: 'primary', mirrors: mirror_config.keys }, + mirror: { service: "Mirror", primary: "primary", mirrors: mirror_config.keys }, primary: { service: "Disk", root: Dir.mktmpdir("active_storage_tests_primary") } SERVICE = ActiveStorage::Service.configure :mirror, config @@ -45,7 +45,7 @@ class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase end test "URL generation in primary service" do - travel_to Time.now do + freeze_time do assert_equal SERVICE.primary.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: "test.txt"), @service.url(FIXTURE_KEY, expires_in: 2.minutes, disposition: :inline, filename: "test.txt") end diff --git a/test/service/s3_service_test.rb b/test/service/s3_service_test.rb index 167aa78a17..049511497b 100644 --- a/test/service/s3_service_test.rb +++ b/test/service/s3_service_test.rb @@ -1,6 +1,5 @@ require "service/shared_service_tests" require "httparty" -require "uri" if SERVICE_CONFIGURATIONS[:s3] class ActiveStorage::Service::S3ServiceTest < ActiveSupport::TestCase @@ -9,37 +8,45 @@ if SERVICE_CONFIGURATIONS[:s3] include ActiveStorage::Service::SharedServiceTests test "direct upload" do - # FIXME: This test is failing because of a mismatched request signature, but it works in the browser. - skip - begin key = SecureRandom.base58(24) data = "Something else entirely!" - direct_upload_url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size) - - url = URI.parse(direct_upload_url).to_s.split("?").first - query = CGI::parse(URI.parse(direct_upload_url).query).collect { |(k, v)| [ k, v.first ] }.to_h + url = @service.url_for_direct_upload(key, expires_in: 5.minutes, content_type: "text/plain", content_length: data.size) - HTTParty.post( + HTTParty.put( url, - query: query, body: data, - headers: { - "Content-Type": "text/plain", - "Origin": "http://localhost:3000" - }, + headers: { "Content-Type" => "text/plain" }, debug_output: STDOUT ) - + assert_equal data, @service.download(key) ensure @service.delete key end end - + test "signed URL generation" do - assert_match /rails-activestorage\.s3\.amazonaws\.com.*response-content-disposition=inline.*avatar\.png/, - @service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: "avatar.png") + assert_match /#{SERVICE_CONFIGURATIONS[:s3][:bucket]}\.s3.(\S+)?amazonaws.com.*response-content-disposition=inline.*avatar\.png/, + @service.url(FIXTURE_KEY, expires_in: 5.minutes, disposition: :inline, filename: "avatar.png") + end + + test "uploading with server-side encryption" do + config = {} + config[:s3] = SERVICE_CONFIGURATIONS[:s3].merge \ + upload: { server_side_encryption: "AES256" } + + sse_service = ActiveStorage::Service.configure(:s3, config) + + begin + key = SecureRandom.base58(24) + data = "Something else entirely!" + sse_service.upload(key, StringIO.new(data), checksum: Digest::MD5.base64digest(data)) + + assert_equal "AES256", sse_service.bucket.object(key).server_side_encryption + ensure + sse_service.delete key + end end end else |