mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 09:57:25 +08:00
FIX: Use dualstack S3 endpoint for direct uploads (#29611)
When we added direct S3 uploads to Discourse, which use presigned URLs, we never took into account the dualstack endpoints for IPv6 on S3. This commit fixes the issue by using the dualstack endpoints for presigned URLs and requests, which are used in the get-presigned-put and batch-presign-urls endpoints used when directly uploading to S3. It also makes regular S3 requests for `put` and so on use dualstack URLs. It doesn't seem like there is a downside to doing this, but a bunch of specs needed to be updated to reflect this.
This commit is contained in:
@ -41,10 +41,10 @@ RSpec.describe "S3Helper" do
|
||||
|
||||
stub_request(
|
||||
:get,
|
||||
"https://bob.s3.#{SiteSetting.s3_region}.amazonaws.com/?lifecycle",
|
||||
"https://bob.s3.dualstack.#{SiteSetting.s3_region}.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.dualstack.#{SiteSetting.s3_region}.amazonaws.com/?lifecycle")
|
||||
.with do |req|
|
||||
hash = Hash.from_xml(req.body.to_s)
|
||||
rules = hash["LifecycleConfiguration"]["Rule"]
|
||||
@ -248,4 +248,42 @@ RSpec.describe "S3Helper" do
|
||||
s3_helper.delete_objects(%w[object/one.txt object/two.txt])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#presigned_url" do
|
||||
let(:s3_helper) { S3Helper.new("test-bucket", "", client: client) }
|
||||
|
||||
it "uses the S3 dualstack endpoint" do
|
||||
expect(s3_helper.presigned_url("test/key.jpeg", method: :get_object)).to include("dualstack")
|
||||
end
|
||||
|
||||
context "for a China S3 region" do
|
||||
before { SiteSetting.s3_region = "cn-northwest-1" }
|
||||
|
||||
it "does not use the S3 dualstack endpoint" do
|
||||
expect(s3_helper.presigned_url("test/key.jpeg", method: :get_object)).not_to include(
|
||||
"dualstack",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#presigned_request" do
|
||||
let(:s3_helper) { S3Helper.new("test-bucket", "", client: client) }
|
||||
|
||||
it "uses the S3 dualstack endpoint" do
|
||||
expect(s3_helper.presigned_request("test/key.jpeg", method: :get_object)[0]).to include(
|
||||
"dualstack",
|
||||
)
|
||||
end
|
||||
|
||||
context "for a China S3 region" do
|
||||
before { SiteSetting.s3_region = "cn-northwest-1" }
|
||||
|
||||
it "does not use the S3 dualstack endpoint" do
|
||||
expect(s3_helper.presigned_request("test/key.jpeg", method: :get_object)[0]).not_to include(
|
||||
"dualstack",
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user