diff --git a/Gemfile.lock b/Gemfile.lock index e3154ffd59f..b386d23ea99 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,10 +45,10 @@ GEM rake (>= 10.4, < 14.0) ast (2.4.0) aws-eventstream (1.0.3) - aws-partitions (1.154.0) - aws-sdk-core (3.48.6) + aws-partitions (1.251.0) + aws-sdk-core (3.84.0) aws-eventstream (~> 1.0, >= 1.0.2) - aws-partitions (~> 1.0) + aws-partitions (~> 1, >= 1.239.0) aws-sigv4 (~> 1.1) jmespath (~> 1.0) aws-sdk-kms (1.17.0) @@ -58,8 +58,8 @@ GEM aws-sdk-core (~> 3, >= 3.48.2) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.0) - aws-sdk-sns (1.13.0) - aws-sdk-core (~> 3, >= 3.48.2) + aws-sdk-sns (1.21.0) + aws-sdk-core (~> 3, >= 3.71.0) aws-sigv4 (~> 1.1) aws-sigv4 (1.1.0) aws-eventstream (~> 1.0, >= 1.0.2) diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index f29701635b3..ea0a7147f4d 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -11,6 +11,7 @@ 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 @@ -504,11 +505,18 @@ 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(:any, /some-bucket-on-s3\.s3\.amazonaws\.com/) + stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.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}" + ) + + stub_request(:get, /#{SiteSetting.s3_upload_bucket}\.s3\.#{SiteSetting.s3_region}\.amazonaws\.com/) OptimizedImage.expects(:resize).returns(true) FileStore::BaseStore.any_instance.expects(:get_depth_for).returns(0) @@ -519,8 +527,10 @@ describe CookedPostProcessor do upload.update_column(:secure, true) end + let(:optimized_size) { "600x500" } + let(:post) do - Fabricate(:post, raw: "![large.png|600x500](#{upload.short_url})") + Fabricate(:post, raw: "![large.png|#{optimized_size}](#{upload.short_url})") end it "handles secure images with the correct lightbox link href" do diff --git a/spec/components/file_store/base_store_spec.rb b/spec/components/file_store/base_store_spec.rb index 13d0c36f8a5..7a32671077b 100644 --- a/spec/components/file_store/base_store_spec.rb +++ b/spec/components/file_store/base_store_spec.rb @@ -53,6 +53,7 @@ RSpec.describe FileStore::BaseStore 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" stub_request(:get, upload_s3.url).to_return(status: 200, body: "Hello world") end @@ -91,7 +92,7 @@ RSpec.describe FileStore::BaseStore do SiteSetting.login_required = true SiteSetting.secure_media = true - stub_request(:head, "https://s3-upload-bucket.s3.amazonaws.com/") + stub_request(:head, "https://s3-upload-bucket.s3.#{SiteSetting.s3_region}.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 547b38736d0..bef529fc30c 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -1400,13 +1400,14 @@ describe PostCreator 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.amazonaws.com/") + stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/") stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/original/1X/#{image_upload.sha1}.#{image_upload.extension}?acl" + "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.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 789c61a071e..a8a45865cbb 100644 --- a/spec/components/s3_helper_spec.rb +++ b/spec/components/s3_helper_spec.rb @@ -10,6 +10,7 @@ describe "S3Helper" do SiteSetting.enable_s3_uploads = true SiteSetting.s3_access_key_id = "abc" SiteSetting.s3_secret_access_key = "def" + SiteSetting.s3_region = "us-east-1" @lifecycle = <<~XML @@ -40,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.amazonaws.com/?lifecycle"). + stub_request(:get, "https://bob.s3.#{SiteSetting.s3_region}.amazonaws.com/?lifecycle"). to_return(status: 200, body: @lifecycle, headers: {}) - stub_request(:put, "https://bob.s3.amazonaws.com/?lifecycle"). + stub_request(:put, "https://bob.s3.#{SiteSetting.s3_region}.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 19ce996ef7b..f12f006d1c4 100644 --- a/spec/models/optimized_image_spec.rb +++ b/spec/models/optimized_image_spec.rb @@ -299,6 +299,7 @@ describe OptimizedImage 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" tempfile = Tempfile.new(["discourse-external", ".png"]) @@ -328,12 +329,12 @@ describe OptimizedImage do stub_request( :head, - "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/" + "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/" ) stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com#{optimized_path}" + "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.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 72bf2cd0634..239771f7116 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -1326,19 +1326,20 @@ 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.amazonaws.com/") + stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/") stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/original/1X/#{attachment_upload.sha1}.#{attachment_upload.extension}?acl" + "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/original/1X/#{attachment_upload.sha1}.#{attachment_upload.extension}?acl" ) stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/original/1X/#{image_upload.sha1}.#{image_upload.extension}?acl" + "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.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 b439bf6c805..6259c13cfb1 100644 --- a/spec/models/topic_converter_spec.rb +++ b/spec/models/topic_converter_spec.rb @@ -112,13 +112,14 @@ 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.amazonaws.com/") + stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/") stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/original/1X/#{image_upload.sha1}.#{image_upload.extension}?acl" + "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.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 5d7cca2598a..e11f4b9102d 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -347,14 +347,15 @@ describe Upload do SiteSetting.enable_s3_uploads = true SiteSetting.s3_upload_bucket = "s3-upload-bucket" SiteSetting.s3_access_key_id = "some key" - SiteSetting.s3_secret_access_key = "some secret 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.amazonaws.com/") + stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/") stub_request( :put, - "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/original/1X/#{upload.sha1}.#{upload.extension}?acl" + "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.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 b70651d297a..b2d877d9f35 100644 --- a/spec/requests/uploads_controller_spec.rb +++ b/spec/requests/uploads_controller_spec.rb @@ -381,6 +381,7 @@ describe UploadsController do SiteSetting.s3_upload_bucket = "s3-upload-bucket" SiteSetting.s3_access_key_id = "fakeid7974664" SiteSetting.s3_secret_access_key = "fakesecretid7974664" + SiteSetting.s3_region = "us-east-1" SiteSetting.secure_media = true end @@ -393,7 +394,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://s3-upload-bucket.s3.amazonaws.com/") + stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/") get secure_url