From 09d9baa6d74b3b8fe02363eba207a84f18842b7a Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Wed, 11 Dec 2019 11:26:52 -0800 Subject: [PATCH] FIX: Update S3 stubs for more aws-sdk API changes (#8534) --- spec/components/cooked_post_processor_spec.rb | 9 +++------ spec/components/file_store/base_store_spec.rb | 2 +- spec/components/post_creator_spec.rb | 4 ++-- spec/components/s3_helper_spec.rb | 4 ++-- spec/models/optimized_image_spec.rb | 4 ++-- spec/models/post_spec.rb | 8 +++----- spec/models/topic_converter_spec.rb | 5 ++--- spec/models/upload_spec.rb | 5 ++--- spec/requests/uploads_controller_spec.rb | 2 +- 9 files changed, 18 insertions(+), 25 deletions(-) diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index ea0a7147f4d..b9627b6cdb1 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -11,7 +11,6 @@ def s3_setup SiteSetting.s3_access_key_id = "s3-access-key-id" SiteSetting.s3_secret_access_key = "s3-secret-access-key" SiteSetting.s3_cdn_url = "https://s3.cdn.com" - SiteSetting.s3_region = "us-east-1" SiteSetting.enable_s3_uploads = true SiteSetting.authorized_extensions = "png|jpg|gif|mov|ogg|" end @@ -505,18 +504,16 @@ describe CookedPostProcessor do context "s3_uploads" do before do - SiteSetting.s3_region = "us-east-1" s3_setup stored_path = Discourse.store.get_path_for_upload(upload) upload.update_column(:url, "#{SiteSetting.Upload.absolute_base_url}/#{stored_path}") - stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/") + stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/") stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/optimized/1X/#{upload.sha1}_2_#{optimized_size}.#{upload.extension}" + "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/optimized/1X/#{upload.sha1}_2_#{optimized_size}.#{upload.extension}" ) - - stub_request(:get, /#{SiteSetting.s3_upload_bucket}\.s3\.#{SiteSetting.s3_region}\.amazonaws\.com/) + stub_request(:get, /#{SiteSetting.s3_upload_bucket}\.s3\.amazonaws\.com/) OptimizedImage.expects(:resize).returns(true) FileStore::BaseStore.any_instance.expects(:get_depth_for).returns(0) diff --git a/spec/components/file_store/base_store_spec.rb b/spec/components/file_store/base_store_spec.rb index 7a32671077b..c58818a72f5 100644 --- a/spec/components/file_store/base_store_spec.rb +++ b/spec/components/file_store/base_store_spec.rb @@ -92,7 +92,7 @@ RSpec.describe FileStore::BaseStore do SiteSetting.login_required = true SiteSetting.secure_media = true - stub_request(:head, "https://s3-upload-bucket.s3.#{SiteSetting.s3_region}.amazonaws.com/") + stub_request(:head, "https://s3-upload-bucket.s3.amazonaws.com/") signed_url = Discourse.store.signed_url_for_path(upload_s3.url) stub_request(:get, signed_url).to_return(status: 200, body: "Hello world") diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index bef529fc30c..dfcf8e0c81e 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -1403,11 +1403,11 @@ describe PostCreator do SiteSetting.s3_region = "us-east-1" SiteSetting.secure_media = true - stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/") + stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/") stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/original/1X/#{image_upload.sha1}.#{image_upload.extension}?acl" + "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/original/1X/#{image_upload.sha1}.#{image_upload.extension}?acl" ) end diff --git a/spec/components/s3_helper_spec.rb b/spec/components/s3_helper_spec.rb index a8a45865cbb..9a8697b460d 100644 --- a/spec/components/s3_helper_spec.rb +++ b/spec/components/s3_helper_spec.rb @@ -41,10 +41,10 @@ describe "S3Helper" do stub_request(:get, "http://169.254.169.254/latest/meta-data/iam/security-credentials/"). to_return(status: 404, body: "", headers: {}) - stub_request(:get, "https://bob.s3.#{SiteSetting.s3_region}.amazonaws.com/?lifecycle"). + stub_request(:get, "https://bob.s3.amazonaws.com/?lifecycle"). to_return(status: 200, body: @lifecycle, headers: {}) - stub_request(:put, "https://bob.s3.#{SiteSetting.s3_region}.amazonaws.com/?lifecycle"). + stub_request(:put, "https://bob.s3.amazonaws.com/?lifecycle"). with do |req| hash = Hash.from_xml(req.body.to_s) diff --git a/spec/models/optimized_image_spec.rb b/spec/models/optimized_image_spec.rb index f12f006d1c4..45c295507a2 100644 --- a/spec/models/optimized_image_spec.rb +++ b/spec/models/optimized_image_spec.rb @@ -329,12 +329,12 @@ describe OptimizedImage do stub_request( :head, - "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/" + "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/" ) stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com#{optimized_path}" + "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com#{optimized_path}" ).to_return( status: 200, headers: { "ETag" => "someetag" } diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 239771f7116..9b45cd9bec5 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -1326,20 +1326,18 @@ describe Post do SiteSetting.s3_upload_bucket = "s3-upload-bucket" SiteSetting.s3_access_key_id = "some key" SiteSetting.s3_secret_access_key = "some secret key" - SiteSetting.s3_region = "us-east-1" SiteSetting.secure_media = true attachment_upload.update!(original_filename: "hello.csv") - stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/") + stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/") stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/original/1X/#{attachment_upload.sha1}.#{attachment_upload.extension}?acl" + "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/original/1X/#{attachment_upload.sha1}.#{attachment_upload.extension}?acl" ) - stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/original/1X/#{image_upload.sha1}.#{image_upload.extension}?acl" + "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/original/1X/#{image_upload.sha1}.#{image_upload.extension}?acl" ) end diff --git a/spec/models/topic_converter_spec.rb b/spec/models/topic_converter_spec.rb index 6259c13cfb1..b439bf6c805 100644 --- a/spec/models/topic_converter_spec.rb +++ b/spec/models/topic_converter_spec.rb @@ -112,14 +112,13 @@ describe TopicConverter do SiteSetting.s3_upload_bucket = "s3-upload-bucket" SiteSetting.s3_access_key_id = "some key" SiteSetting.s3_secret_access_key = "some secret key" - SiteSetting.s3_region = "us-east-1" SiteSetting.secure_media = true - stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/") + stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/") stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/original/1X/#{image_upload.sha1}.#{image_upload.extension}?acl" + "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/original/1X/#{image_upload.sha1}.#{image_upload.extension}?acl" ) end diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index e11f4b9102d..0293b66d561 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -348,14 +348,13 @@ describe Upload do SiteSetting.s3_upload_bucket = "s3-upload-bucket" SiteSetting.s3_access_key_id = "some key" SiteSetting.s3_secret_access_key = "some secrets3_region key" - SiteSetting.s3_region = "us-east-1" SiteSetting.secure_media = true - stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/") + stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/") stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/original/1X/#{upload.sha1}.#{upload.extension}?acl" + "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/original/1X/#{upload.sha1}.#{upload.extension}?acl" ) end diff --git a/spec/requests/uploads_controller_spec.rb b/spec/requests/uploads_controller_spec.rb index 512d419a22b..a8bc89cad79 100644 --- a/spec/requests/uploads_controller_spec.rb +++ b/spec/requests/uploads_controller_spec.rb @@ -406,7 +406,7 @@ describe UploadsController do it "should return signed url for legitimate request" do secure_url = upload.url.sub(SiteSetting.Upload.absolute_base_url, "/secure-media-uploads") sign_in(user) - stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/") + stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/") get secure_url