diff --git a/s3api/controllers/bucket-put.go b/s3api/controllers/bucket-put.go index ff4c9bf..292ce36 100644 --- a/s3api/controllers/bucket-put.go +++ b/s3api/controllers/bucket-put.go @@ -562,10 +562,10 @@ func (c S3ApiController) CreateBucket(ctx *fiber.Ctx) (*Response, error) { }, s3err.GetAPIError(s3err.ErrMalformedXML) } - if body.LocationConstraint != "" { + if body.LocationConstraint != nil { region := utils.ContextKeyRegion.Get(ctx).(string) - if body.LocationConstraint != region { - debuglogger.Logf("invalid location constraint: %s", body.LocationConstraint) + if *body.LocationConstraint != region || *body.LocationConstraint == "us-east-1" { + debuglogger.Logf("invalid location constraint: %s", *body.LocationConstraint) return &Response{ MetaOpts: &MetaOptions{ BucketOwner: acct.Access, diff --git a/s3api/controllers/bucket-put_test.go b/s3api/controllers/bucket-put_test.go index 3440cde..00def05 100644 --- a/s3api/controllers/bucket-put_test.go +++ b/s3api/controllers/bucket-put_test.go @@ -700,7 +700,7 @@ func TestS3ApiController_CreateBucket(t *testing.T) { } invLocConstBody, err := xml.Marshal(s3response.CreateBucketConfiguration{ - LocationConstraint: "us-west-1", + LocationConstraint: utils.GetStringPtr("us-west-1"), }) assert.NoError(t, err) diff --git a/s3response/s3response.go b/s3response/s3response.go index 1ead5ab..6760a61 100644 --- a/s3response/s3response.go +++ b/s3response/s3response.go @@ -730,6 +730,6 @@ type LocationConstraint struct { } type CreateBucketConfiguration struct { - LocationConstraint string + LocationConstraint *string TagSet []types.Tag `xml:"Tags>Tag"` } diff --git a/tests/integration/CreateBucket.go b/tests/integration/CreateBucket.go index af95dd7..0e91f53 100644 --- a/tests/integration/CreateBucket.go +++ b/tests/integration/CreateBucket.go @@ -342,16 +342,27 @@ func CreateBucket_invalid_location_constraint(s *S3Conf) error { region = types.BucketLocationConstraintUsWest1 } - ctx, cancel := context.WithTimeout(context.Background(), shortTimeout) - _, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{ - Bucket: &bucket, - CreateBucketConfiguration: &types.CreateBucketConfiguration{ - LocationConstraint: region, - }, - }) - cancel() + createBucket := func(region types.BucketLocationConstraint) error { + ctx, cancel := context.WithTimeout(context.Background(), shortTimeout) + _, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{ + Bucket: &bucket, + CreateBucketConfiguration: &types.CreateBucketConfiguration{ + LocationConstraint: region, + }, + }) + cancel() - return checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidLocationConstraint)) + return checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidLocationConstraint)) + } + + for _, lConstraint := range []types.BucketLocationConstraint{region, "us-east-1"} { + err := createBucket(lConstraint) + if err != nil { + return err + } + } + + return nil }) }