From a2e864fa13c7d3d56a95a2f46d525597f989f938 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Thu, 6 Jul 2017 15:31:31 -0400 Subject: Fix test * S3 fails fast if the Content-MD5 header on an upload request is an invalid checksum. Send a valid but incorrect checksum. * Rescue the service-specific exception and raise the generic one. --- lib/active_storage/service/s3_service.rb | 2 ++ test/service/shared_service_tests.rb | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/active_storage/service/s3_service.rb b/lib/active_storage/service/s3_service.rb index 413789e2b5..963a41af17 100644 --- a/lib/active_storage/service/s3_service.rb +++ b/lib/active_storage/service/s3_service.rb @@ -11,6 +11,8 @@ class ActiveStorage::Service::S3Service < ActiveStorage::Service def upload(key, io, checksum: nil) object_for(key).put(body: io, content_md5: checksum) + rescue Aws::S3::Errors::BadDigest + raise ActiveStorage::IntegrityError end def download(key) diff --git a/test/service/shared_service_tests.rb b/test/service/shared_service_tests.rb index b4c888e77c..dfa0d61656 100644 --- a/test/service/shared_service_tests.rb +++ b/test/service/shared_service_tests.rb @@ -3,7 +3,7 @@ require "active_support/core_ext/securerandom" require "yaml" SERVICE_CONFIGURATIONS = begin - YAML.load_file(File.expand_path("../configurations.yml", __FILE__)).deep_symbolize_keys + YAML.load_file(File.expand_path("../configurations.yml", __FILE__)).deep_symbolize_keys rescue Errno::ENOENT puts "Missing service configuration file in test/services/configurations.yml" end @@ -44,7 +44,7 @@ module ActiveStorage::Service::SharedServiceTests data = "Something else entirely!" assert_raises(ActiveStorage::IntegrityError) do - @service.upload(key, StringIO.new(data), checksum: "BAD_CHECKSUM") + @service.upload(key, StringIO.new(data), checksum: Digest::MD5.base64digest("bad data")) end ensure @service.delete key -- cgit v1.2.3