Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
georgeclaghorn committed Jul 6, 2017
1 parent 2afe0a7 commit a2e864f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/active_storage/service/s3_service.rb
Expand Up @@ -11,6 +11,8 @@ def initialize(access_key_id:, secret_access_key:, region:, bucket:)

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)
Expand Down
4 changes: 2 additions & 2 deletions test/service/shared_service_tests.rb
Expand Up @@ -3,7 +3,7 @@
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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a2e864f

Please sign in to comment.