fix: reject a ListBuckets bucket-region other than the gateway region

S3 never lists an empty result for another region: a valid region
other than the endpoint's own gets 400 InvalidArgument, "Requests with
bucket-region specified must be made to the corresponding regional
endpoint", with no ArgumentValue. The gateway is a single regional
endpoint, so it now does the same instead of clearing the listing.

Match the region case-insensitively like S3, and check an empty
bucket-region= too by looking for the query argument itself, since an
empty value is not a valid AWS region either.
This commit is contained in:
dualfroz committed 2026-10-05 20:42:30 +02:00
1 parent 5d293b1316
commit e1d2284906
7 files changed
+104 -56

No files matched your search

+34 -13
View File
@@ -119,25 +119,46 @@ func TestS3ApiController_ListBuckets(t *testing.T) {
name: "bucket region of another region",
input: testInput{
locals: defaultLocals,
beRes: s3response.ListAllMyBucketsResult{
Owner: validRes.Owner,
Buckets: validRes.Buckets,
Prefix: "te",
// a continuation token from the backend must not
// leak into the empty listing
ContinuationToken: "test",
},
beRes: validRes,
queries: map[string]string{
"bucket-region": "us-west-2",
"prefix": "te",
},
},
output: testOutput{
response: &Response{
Data: s3response.ListAllMyBucketsResult{
Owner: validRes.Owner,
Prefix: "te",
},
MetaOpts: &MetaOptions{},
},
err: s3err.GetInvalidArgumentErr(s3err.InvalidArgBucketRegionEndpoint, ""),
},
},
{
name: "empty bucket region",
input: testInput{
locals: defaultLocals,
beRes: validRes,
queries: map[string]string{
"bucket-region": "",
},
},
output: testOutput{
response: &Response{
MetaOpts: &MetaOptions{},
},
err: s3err.GetInvalidArgBucketRegion(""),
},
},
{
name: "bucket region of the gateway region in uppercase",
input: testInput{
locals: defaultLocals,
beRes: validRes,
queries: map[string]string{
"bucket-region": "US-EAST-1",
},
},
output: testOutput{
response: &Response{
Data: validRes,
},
},
},