From cc496de10e988ac2b941c49d1f57847a85e557b0 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Fri, 8 Feb 2019 14:31:19 +0530 Subject: [PATCH] FIX: Remove double quotes from etag value in API response https://github.com/aws/aws-sdk-ruby/issues/1134 --- lib/s3_helper.rb | 2 +- spec/components/file_store/s3_store_spec.rb | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/s3_helper.rb b/lib/s3_helper.rb index 3e7b6c81d6d..34b0d8c247d 100644 --- a/lib/s3_helper.rb +++ b/lib/s3_helper.rb @@ -43,7 +43,7 @@ class S3Helper end end - return path, etag + return path, etag.gsub('"', '') end def remove(s3_filename, copy_to_tombstone = false) diff --git a/spec/components/file_store/s3_store_spec.rb b/spec/components/file_store/s3_store_spec.rb index e18a09231ec..5364eb4dff2 100644 --- a/spec/components/file_store/s3_store_spec.rb +++ b/spec/components/file_store/s3_store_spec.rb @@ -38,18 +38,20 @@ describe FileStore::S3Store do context 'uploading to s3' do include_context "s3 helpers" + let(:s3_object) { stub } let(:etag) { "etag" } + before do + s3_object.stubs(:put).returns(Aws::S3::Types::PutObjectOutput.new(etag: "\"#{etag}\"")) + end + describe "#store_upload" do it "returns an absolute schemaless url" do store.expects(:get_depth_for).with(upload.id).returns(0) s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once - s3_object = stub s3_bucket.expects(:object).with("original/1X/#{upload.sha1}.png").returns(s3_object) - s3_object.stubs(:put).returns(Aws::S3::Types::PutObjectOutput.new(etag: etag)) - expect(store.store_upload(uploaded_file, upload)).to eq( "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/original/1X/#{upload.sha1}.png" ) @@ -64,12 +66,9 @@ describe FileStore::S3Store do it "returns an absolute schemaless url" do store.expects(:get_depth_for).with(upload.id).returns(0) s3_helper.expects(:s3_bucket).returns(s3_bucket) - s3_object = stub s3_bucket.expects(:object).with("discourse-uploads/original/1X/#{upload.sha1}.png").returns(s3_object) - s3_object.stubs(:put).returns(Aws::S3::Types::PutObjectOutput.new(etag: etag)) - expect(store.store_upload(uploaded_file, upload)).to eq( "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/discourse-uploads/original/1X/#{upload.sha1}.png" ) @@ -82,13 +81,10 @@ describe FileStore::S3Store do it "returns an absolute schemaless url" do store.expects(:get_depth_for).with(optimized_image.upload.id).returns(0) s3_helper.expects(:s3_bucket).returns(s3_bucket) - s3_object = stub path = "optimized/1X/#{optimized_image.upload.sha1}_#{OptimizedImage::VERSION}_100x200.png" s3_bucket.expects(:object).with(path).returns(s3_object) - s3_object.stubs(:put).returns(Aws::S3::Types::PutObjectOutput.new(etag: etag)) - expect(store.store_optimized_image(optimized_image_file, optimized_image)).to eq( "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/#{path}" ) @@ -103,13 +99,10 @@ describe FileStore::S3Store do it "returns an absolute schemaless url" do store.expects(:get_depth_for).with(optimized_image.upload.id).returns(0) s3_helper.expects(:s3_bucket).returns(s3_bucket) - s3_object = stub path = "discourse-uploads/optimized/1X/#{optimized_image.upload.sha1}_#{OptimizedImage::VERSION}_100x200.png" s3_bucket.expects(:object).with(path).returns(s3_object) - s3_object.stubs(:put).returns(Aws::S3::Types::PutObjectOutput.new(etag: etag)) - expect(store.store_optimized_image(optimized_image_file, optimized_image)).to eq( "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/#{path}" )