fix: return IllegalLocationConstraintException for a mismatched LocationConstraint
A region specific endpoint requires CreateBucket to name that same region in `LocationConstraint`. The gateway reported a mismatch as `InvalidLocationConstraint`, which AWS reserves for a constraint that is not a valid location at all, and accepted a request that omitted the constraint entirely. Keep `InvalidLocationConstraint` for the global `us-east-1` endpoint, which takes no constraint, and return `IllegalLocationConstraintException` when a region specific endpoint gets a constraint naming another region, or none. Fixes #2246
This commit is contained in:
1 parent
2a5705ab02
commit
2742fc2216
3 files changed
+110
-11
No files matched your search
@@ -726,6 +726,11 @@ func TestS3ApiController_CreateBucket(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
euLocConstBody, err := xml.Marshal(s3response.CreateBucketConfiguration{
|
||||
LocationConstraint: utils.GetStringPtr("eu-central-1"),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input testInput
|
||||
@@ -812,6 +817,59 @@ func TestS3ApiController_CreateBucket(t *testing.T) {
|
||||
err: s3err.GetInvalidLocationConstraintErr("us-west-1"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "illegal location constraint",
|
||||
input: testInput{
|
||||
locals: map[utils.ContextKey]any{
|
||||
utils.ContextKeyAccount: adminAcc,
|
||||
utils.ContextKeyRegion: "us-west-1",
|
||||
},
|
||||
body: euLocConstBody,
|
||||
},
|
||||
output: testOutput{
|
||||
response: &Response{
|
||||
MetaOpts: &MetaOptions{BucketOwner: adminAcc.Access},
|
||||
},
|
||||
err: s3err.GetIllegalLocationConstraintErr("eu-central-1"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "missing location constraint",
|
||||
input: testInput{
|
||||
locals: map[utils.ContextKey]any{
|
||||
utils.ContextKeyAccount: adminAcc,
|
||||
utils.ContextKeyRegion: "us-west-1",
|
||||
},
|
||||
},
|
||||
output: testOutput{
|
||||
response: &Response{
|
||||
MetaOpts: &MetaOptions{BucketOwner: adminAcc.Access},
|
||||
},
|
||||
err: s3err.GetIllegalLocationConstraintErr(""),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "matching location constraint",
|
||||
input: testInput{
|
||||
locals: map[utils.ContextKey]any{
|
||||
utils.ContextKeyAccount: adminAcc,
|
||||
utils.ContextKeyRegion: "us-west-1",
|
||||
},
|
||||
bucket: "my-bucket",
|
||||
body: invLocConstBody,
|
||||
},
|
||||
output: testOutput{
|
||||
response: &Response{
|
||||
MetaOpts: &MetaOptions{
|
||||
BucketOwner: adminAcc.Access,
|
||||
},
|
||||
Headers: map[string]*string{
|
||||
"Location": utils.GetStringPtr("/my-bucket"),
|
||||
"x-amz-bucket-arn": utils.GetStringPtr("arn:aws:s3:::my-bucket"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid ownership",
|
||||
input: testInput{
|
||||
|
||||
Reference in new issue
Block a user