mirror of
https://github.com/versity/versitygw.git
synced 2026-05-23 20:31:27 +00:00
Fixes #2123 Fixes #2120 Fixes #2116 Fixes #2111 Fixes #2108 Fixes #2086 Fixes #2085 Fixes #2083 Fixes #2081 Fixes #2080 Fixes #2073 Fixes #2072 Fixes #2071 Fixes #2069 Fixes #2044 Fixes #2043 Fixes #2042 Fixes #2041 Fixes #2040 Fixes #2039 Fixes #2036 Fixes #2035 Fixes #2034 Fixes #2028 Fixes #2020 Fixes #1842 Fixes #1810 Fixes #1780 Fixes #1775 Fixes #1736 Fixes #1705 Fixes #1663 Fixes #1645 Fixes #1583 Fixes #1526 Fixes #1514 Fixes #1493 Fixes #1487 Fixes #959 Fixes #779 Closes #823 Closes #85 Refactor global S3 error handling around structured error types and centralized XML response generation. All S3 errors now share the common APIError base for the fields every error has: Code, HTTP status code, and Message. Non-traditional errors that need AWS-compatible XML fields now have dedicated typed errors in the s3err package. Each typed error implements the shared S3Error behavior so controllers and middleware can handle errors consistently while still emitting error-specific XML fields. Add a dedicated InvalidArgumentError type because InvalidArgument is used widely across request validation, auth, copy source handling, object lock validation, multipart validation, and header parsing. The new InvalidArgument path uses explicit InvalidArgErrorCode constants with predefined descriptions and ArgumentName values, keeping call sites readable while preserving the correct InvalidArgument XML shape and optional ArgumentValue. New structured errors added in s3err: - `AccessForbiddenError`: Method, ResourceType - `BadDigestError`: CalculatedDigest, ExpectedDigest - `BucketError`: BucketName - `ContentSHA256MismatchError`: ClientComputedContentSHA256, S3ComputedContentSHA256 - `EntityTooLargeError`: ProposedSize, MaxSizeAllowed - `EntityTooSmallError`: ProposedSize, MinSizeAllowed - `ExpiredPresignedURLError`: ServerTime, XAmzExpires, Expires - `InvalidAccessKeyIdError`: AWSAccessKeyId - `InvalidArgumentError`: Description, ArgumentName, ArgumentValue - `InvalidChunkSizeError`: Chunk, BadChunkSize - `InvalidDigestError`: ContentMD5 - `InvalidLocationConstraintError`: LocationConstraint - `InvalidPartError`: UploadId, PartNumber, ETag - `InvalidRangeError`: RangeRequested, ActualObjectSize - `InvalidTagError`: TagKey, TagValue - `KeyTooLongError`: Size, MaxSizeAllowed - `MetadataTooLargeError`: Size, MaxSizeAllowed - `MethodNotAllowedError`: Method, ResourceType, AllowedMethods - `NoSuchUploadError`: UploadId - `NoSuchVersionError`: Key, VersionId - `NotImplementedError`: Header, AdditionalMessage - `PreconditionFailedError`: Condition - `RequestTimeTooSkewedError`: RequestTime, ServerTime, MaxAllowedSkewMilliseconds - `SignatureDoesNotMatchError`: AWSAccessKeyId, StringToSign, SignatureProvided, StringToSignBytes, CanonicalRequest, CanonicalRequestBytes Fix CompleteMultipartUpload validation in the Azure backend so missing or empty `ETag` values return the appropriate S3 error instead of allowing a gateway panic. Fix presigned authentication expiration validation to compare server time in `UTC`, matching the `UTC` timestamp used by presigned URL signing. Add request ID and host ID support across S3 requests. Each request now receives AWS S3-like identifiers, returned in response headers as `x-amz-request-id` and `x-amz-id-2` and included in all XML error responses as RequestId and HostId. The generated ID structure is designed to resemble AWS S3 request IDs and host IDs. The request signature calculation/validation for streaming uploads was previously delayed until the request body was fully read, both for Authorization header authentication and presigned URLs. Now, the signature is validated immediately in the authorization middlewares without reading the request body, since the signature calculation itself does not depend on the request body. Instead, only the `x-amz-content-sha256` SHA-256 hash calculation is delayed.
664 lines
20 KiB
Go
664 lines
20 KiB
Go
// Copyright 2023 Versity Software
|
|
// This file is licensed under the Apache License, Version 2.0
|
|
// (the "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing,
|
|
// software distributed under the License is distributed on an
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
// KIND, either express or implied. See the License for the
|
|
// specific language governing permissions and limitations
|
|
// under the License.
|
|
|
|
package integration
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
|
"github.com/aws/aws-sdk-go-v2/service/s3/types"
|
|
"github.com/versity/versitygw/s3err"
|
|
)
|
|
|
|
func CreateBucket_invalid_bucket_name(s *S3Conf) error {
|
|
testName := "CreateBucket_invalid_bucket_name"
|
|
runF(testName)
|
|
err := setup(s, "aa")
|
|
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidBucketName)); err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
err = setup(s, ".gitignore")
|
|
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidBucketName)); err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
err = setup(s, "my-bucket.")
|
|
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidBucketName)); err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
err = setup(s, "bucket-%")
|
|
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidBucketName)); err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
passF(testName)
|
|
return nil
|
|
}
|
|
|
|
func CreateBucket_as_user(s *S3Conf) error {
|
|
testName := "CreateBucket_as_user"
|
|
runF(testName)
|
|
|
|
testuser := getUser("user")
|
|
cfg := *s
|
|
cfg.awsID = testuser.access
|
|
cfg.awsSecret = testuser.secret
|
|
err := createUsers(s, []user{testuser})
|
|
if err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
err = setup(&cfg, getBucketName())
|
|
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrAccessDenied)); err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
passF(testName)
|
|
return nil
|
|
}
|
|
|
|
func CreateBucket_existing_bucket(s *S3Conf) error {
|
|
testName := "CreateBucket_existing_bucket"
|
|
runF(testName)
|
|
bucket := getBucketName()
|
|
adminUser := getUser("admin")
|
|
if err := createUsers(s, []user{adminUser}); err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
adminCfg := *s
|
|
adminCfg.awsID = adminUser.access
|
|
adminCfg.awsSecret = adminUser.secret
|
|
|
|
err := setup(&adminCfg, bucket)
|
|
if err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
err = setup(s, bucket)
|
|
var bne *types.BucketAlreadyExists
|
|
if !errors.As(err, &bne) {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
err = teardown(s, bucket)
|
|
if err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
passF(testName)
|
|
return nil
|
|
}
|
|
|
|
func CreateBucket_owned_by_you(s *S3Conf) error {
|
|
testName := "CreateBucket_owned_by_you"
|
|
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
_, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: &bucket,
|
|
})
|
|
cancel()
|
|
var bErr *types.BucketAlreadyOwnedByYou
|
|
if !errors.As(err, &bErr) {
|
|
return fmt.Errorf("expected error to be %w, instead got %w", s3err.GetAPIError(s3err.ErrBucketAlreadyOwnedByYou), err)
|
|
}
|
|
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func CreateBucket_invalid_ownership(s *S3Conf) error {
|
|
testName := "CreateBucket_invalid_ownership"
|
|
runF(testName)
|
|
|
|
invalidOwnership := types.ObjectOwnership("invalid_ownership")
|
|
err := setup(s, getBucketName(), withOwnership(invalidOwnership))
|
|
if err := checkApiErr(err, s3err.GetInvalidArgObjectOwnership(string(invalidOwnership))); err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
passF(testName)
|
|
return nil
|
|
}
|
|
|
|
func CreateBucket_ownership_with_acl(s *S3Conf) error {
|
|
testName := "CreateBucket_ownership_with_acl"
|
|
|
|
runF(testName)
|
|
client := s.GetClient()
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
_, err := client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: getPtr(getBucketName()),
|
|
ObjectOwnership: types.ObjectOwnershipBucketOwnerEnforced,
|
|
ACL: types.BucketCannedACLPublicRead,
|
|
})
|
|
cancel()
|
|
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidBucketAclWithObjectOwnership)); err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
passF(testName)
|
|
return nil
|
|
}
|
|
|
|
func CreateBucket_default_acl(s *S3Conf) error {
|
|
testName := "CreateBucket_default_acl"
|
|
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
out, err := s3client.GetBucketAcl(ctx, &s3.GetBucketAclInput{Bucket: &bucket})
|
|
cancel()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if getString(out.Owner.ID) != s.awsID {
|
|
return fmt.Errorf("expected bucket owner to be %v, instead got %v",
|
|
s.awsID, getString(out.Owner.ID))
|
|
}
|
|
if len(out.Grants) != 1 {
|
|
return fmt.Errorf("expected grants length to be 1, instead got %v",
|
|
len(out.Grants))
|
|
}
|
|
grt := out.Grants[0]
|
|
if grt.Permission != types.PermissionFullControl {
|
|
return fmt.Errorf("expected the grantee to have full-control permission, instead got %v",
|
|
grt.Permission)
|
|
}
|
|
if getString(grt.Grantee.ID) != s.awsID {
|
|
return fmt.Errorf("expected the grantee id to be %v, instead got %v",
|
|
s.awsID, getString(grt.Grantee.ID))
|
|
}
|
|
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func CreateBucket_non_default_acl(s *S3Conf) error {
|
|
testName := "CreateBucket_non_default_acl"
|
|
runF(testName)
|
|
|
|
testuser1, testuser2, testuser3 := getUser("user"), getUser("user"), getUser("user")
|
|
err := createUsers(s, []user{testuser1, testuser2, testuser3})
|
|
if err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
grants := []types.Grant{
|
|
{
|
|
Grantee: &types.Grantee{
|
|
ID: &s.awsID,
|
|
Type: types.TypeCanonicalUser,
|
|
},
|
|
Permission: types.PermissionFullControl,
|
|
},
|
|
{
|
|
Grantee: &types.Grantee{
|
|
ID: &testuser1.access,
|
|
Type: types.TypeCanonicalUser,
|
|
},
|
|
Permission: types.PermissionFullControl,
|
|
},
|
|
{
|
|
Grantee: &types.Grantee{
|
|
ID: &testuser2.access,
|
|
Type: types.TypeCanonicalUser,
|
|
},
|
|
Permission: types.PermissionReadAcp,
|
|
},
|
|
{
|
|
Grantee: &types.Grantee{
|
|
ID: &testuser3.access,
|
|
Type: types.TypeCanonicalUser,
|
|
},
|
|
Permission: types.PermissionWrite,
|
|
},
|
|
}
|
|
|
|
bucket := getBucketName()
|
|
client := s.GetClient()
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
_, err = client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: &bucket,
|
|
GrantFullControl: &testuser1.access,
|
|
GrantReadACP: &testuser2.access,
|
|
GrantWrite: &testuser3.access,
|
|
ObjectOwnership: types.ObjectOwnershipBucketOwnerPreferred,
|
|
})
|
|
cancel()
|
|
if err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
|
|
out, err := client.GetBucketAcl(ctx, &s3.GetBucketAclInput{Bucket: &bucket})
|
|
cancel()
|
|
if err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
if !compareGrants(out.Grants, grants) {
|
|
failF("%v: expected bucket acl grants to be %v, instead got %v", testName, grants, out.Grants)
|
|
return fmt.Errorf("%v: expected bucket acl grants to be %v, instead got %v", testName, grants, out.Grants)
|
|
}
|
|
|
|
err = teardown(s, bucket)
|
|
if err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
passF(testName)
|
|
return nil
|
|
}
|
|
|
|
func CreateBucket_private_canned_acl(s *S3Conf) error {
|
|
testName := "CreateBucket_private_canned_acl"
|
|
return actionHandlerNoSetup(s, testName, func(s3client *s3.Client, bucket string) error {
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
_, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: &bucket,
|
|
ACL: types.BucketCannedACLPrivate,
|
|
})
|
|
cancel()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
|
|
res, err := s3client.GetBucketAcl(ctx, &s3.GetBucketAclInput{
|
|
Bucket: &bucket,
|
|
})
|
|
cancel()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if getString(res.Owner.ID) != s.awsID {
|
|
return fmt.Errorf("expected bucket owner to be %v, instead got %v",
|
|
s.awsID, getString(res.Owner.ID))
|
|
}
|
|
if len(res.Grants) != 1 {
|
|
return fmt.Errorf("expected grants length to be 1, instead got %v",
|
|
len(res.Grants))
|
|
}
|
|
grt := res.Grants[0]
|
|
if grt.Permission != types.PermissionFullControl {
|
|
return fmt.Errorf("expected the grantee to have full-control permission, instead got %v",
|
|
grt.Permission)
|
|
}
|
|
if getString(grt.Grantee.ID) != s.awsID {
|
|
return fmt.Errorf("expected the grantee id to be %v, instead got %v",
|
|
s.awsID, getString(grt.Grantee.ID))
|
|
}
|
|
|
|
ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
|
|
out, err := s3client.GetBucketOwnershipControls(ctx, &s3.GetBucketOwnershipControlsInput{
|
|
Bucket: &bucket,
|
|
})
|
|
cancel()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if out.OwnershipControls == nil {
|
|
return fmt.Errorf("unexpected nil OwnershipControls")
|
|
}
|
|
if len(out.OwnershipControls.Rules) != 1 {
|
|
return fmt.Errorf("expected the OwnershipControls rules length to be 1, instead got %v", len(out.OwnershipControls.Rules))
|
|
}
|
|
if out.OwnershipControls.Rules[0].ObjectOwnership != types.ObjectOwnershipBucketOwnerPreferred {
|
|
return fmt.Errorf("expected the ObjectOwnership to be %s, instead got %s", types.ObjectOwnershipBucketOwnerPreferred, out.OwnershipControls.Rules[0].ObjectOwnership)
|
|
}
|
|
|
|
return teardown(s, bucket)
|
|
})
|
|
}
|
|
|
|
func CreateBucket_private_canned_acl_bucket_owner_enforced_ownership(s *S3Conf) error {
|
|
testName := "CreateBucket_private_canned_acl_bucket_owner_enforced_ownership"
|
|
return actionHandlerNoSetup(s, testName, func(s3client *s3.Client, bucket string) error {
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
_, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: &bucket,
|
|
ACL: types.BucketCannedACLPrivate,
|
|
ObjectOwnership: types.ObjectOwnershipBucketOwnerEnforced,
|
|
})
|
|
cancel()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
|
|
res, err := s3client.GetBucketAcl(ctx, &s3.GetBucketAclInput{
|
|
Bucket: &bucket,
|
|
})
|
|
cancel()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if getString(res.Owner.ID) != s.awsID {
|
|
return fmt.Errorf("expected bucket owner to be %v, instead got %v",
|
|
s.awsID, getString(res.Owner.ID))
|
|
}
|
|
if len(res.Grants) != 1 {
|
|
return fmt.Errorf("expected grants length to be 1, instead got %v",
|
|
len(res.Grants))
|
|
}
|
|
grt := res.Grants[0]
|
|
if grt.Permission != types.PermissionFullControl {
|
|
return fmt.Errorf("expected the grantee to have full-control permission, instead got %v",
|
|
grt.Permission)
|
|
}
|
|
if getString(grt.Grantee.ID) != s.awsID {
|
|
return fmt.Errorf("expected the grantee id to be %v, instead got %v",
|
|
s.awsID, getString(grt.Grantee.ID))
|
|
}
|
|
|
|
ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
|
|
out, err := s3client.GetBucketOwnershipControls(ctx, &s3.GetBucketOwnershipControlsInput{
|
|
Bucket: &bucket,
|
|
})
|
|
cancel()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if out.OwnershipControls == nil {
|
|
return fmt.Errorf("unexpected nil OwnershipControls")
|
|
}
|
|
if len(out.OwnershipControls.Rules) != 1 {
|
|
return fmt.Errorf("expected the OwnershipControls rules length to be 1, instead got %v", len(out.OwnershipControls.Rules))
|
|
}
|
|
if out.OwnershipControls.Rules[0].ObjectOwnership != types.ObjectOwnershipBucketOwnerEnforced {
|
|
return fmt.Errorf("expected the ObjectOwnership to be %s, instead got %s", types.ObjectOwnershipBucketOwnerEnforced, out.OwnershipControls.Rules[0].ObjectOwnership)
|
|
}
|
|
|
|
return teardown(s, bucket)
|
|
})
|
|
}
|
|
|
|
func CreateBucket_default_object_lock(s *S3Conf) error {
|
|
testName := "CreateBucket_default_object_lock"
|
|
runF(testName)
|
|
|
|
bucket := getBucketName()
|
|
lockEnabled := true
|
|
|
|
client := s.GetClient()
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
_, err := client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: &bucket,
|
|
ObjectLockEnabledForBucket: &lockEnabled,
|
|
})
|
|
cancel()
|
|
if err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
|
|
resp, err := client.GetObjectLockConfiguration(ctx, &s3.GetObjectLockConfigurationInput{
|
|
Bucket: &bucket,
|
|
})
|
|
cancel()
|
|
if err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
if resp.ObjectLockConfiguration.ObjectLockEnabled != types.ObjectLockEnabledEnabled {
|
|
failF("%v: expected object lock to be enabled", testName)
|
|
return fmt.Errorf("%v: expected object lock to be enabled", testName)
|
|
}
|
|
|
|
err = teardown(s, bucket)
|
|
if err != nil {
|
|
failF("%v: %v", testName, err)
|
|
return fmt.Errorf("%v: %w", testName, err)
|
|
}
|
|
|
|
passF(testName)
|
|
return nil
|
|
}
|
|
|
|
func CreateBucket_invalid_location_constraint(s *S3Conf) error {
|
|
testName := "CreateBucket_invalid_location_constraint"
|
|
return actionHandlerNoSetup(s, testName, func(s3client *s3.Client, bucket string) error {
|
|
var region types.BucketLocationConstraint
|
|
if types.BucketLocationConstraint(s.awsID) == types.BucketLocationConstraintUsWest1 {
|
|
region = types.BucketLocationConstraintUsWest2
|
|
} else {
|
|
region = types.BucketLocationConstraintUsWest1
|
|
}
|
|
|
|
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))
|
|
}
|
|
|
|
for _, lConstraint := range []types.BucketLocationConstraint{region, "us-east-1"} {
|
|
err := createBucket(lConstraint)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func CreateBucket_long_tags(s *S3Conf) error {
|
|
testName := "CreateBucket_long_tags"
|
|
return actionHandlerNoSetup(s, testName, func(s3client *s3.Client, bucket string) error {
|
|
tagging := []types.Tag{{Key: getPtr(genRandString(200)), Value: getPtr("val")}}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
_, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: &bucket,
|
|
CreateBucketConfiguration: &types.CreateBucketConfiguration{
|
|
Tags: tagging,
|
|
},
|
|
})
|
|
cancel()
|
|
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidTagKey)); err != nil {
|
|
return err
|
|
}
|
|
|
|
tagging = []types.Tag{{Key: getPtr("key"), Value: getPtr(genRandString(300))}}
|
|
|
|
ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
|
|
_, err = s3client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: &bucket,
|
|
CreateBucketConfiguration: &types.CreateBucketConfiguration{
|
|
Tags: tagging,
|
|
},
|
|
})
|
|
cancel()
|
|
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidTagValue)); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func CreateBucket_invalid_tags(s *S3Conf) error {
|
|
testName := "CreateBucket_invalid_tags"
|
|
return actionHandlerNoSetup(s, testName, func(s3client *s3.Client, bucket string) error {
|
|
for i, test := range []struct {
|
|
tags []types.Tag
|
|
err s3err.APIError
|
|
}{
|
|
// invalid tag key tests
|
|
{[]types.Tag{{Key: getPtr("user!name"), Value: getPtr("value")}}, s3err.GetAPIError(s3err.ErrInvalidTagKey)},
|
|
{[]types.Tag{{Key: getPtr("foo#bar"), Value: getPtr("value")}}, s3err.GetAPIError(s3err.ErrInvalidTagKey)},
|
|
{[]types.Tag{
|
|
{Key: getPtr("validkey"), Value: getPtr("validvalue")},
|
|
{Key: getPtr("data%20"), Value: getPtr("value")},
|
|
}, s3err.GetAPIError(s3err.ErrInvalidTagKey)},
|
|
{[]types.Tag{
|
|
{Key: getPtr("abcd"), Value: getPtr("xyz123")},
|
|
{Key: getPtr("a*b"), Value: getPtr("value")},
|
|
}, s3err.GetAPIError(s3err.ErrInvalidTagKey)},
|
|
// invalid tag value tests
|
|
{[]types.Tag{
|
|
{Key: getPtr("hello"), Value: getPtr("world")},
|
|
{Key: getPtr("key"), Value: getPtr("name?test")},
|
|
}, s3err.GetAPIError(s3err.ErrInvalidTagValue)},
|
|
{[]types.Tag{
|
|
{Key: getPtr("foo"), Value: getPtr("bar")},
|
|
{Key: getPtr("key"), Value: getPtr("`path")},
|
|
}, s3err.GetAPIError(s3err.ErrInvalidTagValue)},
|
|
{[]types.Tag{{Key: getPtr("valid"), Value: getPtr("comma,separated")}}, s3err.GetAPIError(s3err.ErrInvalidTagValue)},
|
|
{[]types.Tag{{Key: getPtr("valid"), Value: getPtr("semicolon;test")}}, s3err.GetAPIError(s3err.ErrInvalidTagValue)},
|
|
{[]types.Tag{{Key: getPtr("valid"), Value: getPtr("(parentheses)")}}, s3err.GetAPIError(s3err.ErrInvalidTagValue)},
|
|
} {
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
_, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: &bucket,
|
|
CreateBucketConfiguration: &types.CreateBucketConfiguration{
|
|
Tags: test.tags,
|
|
},
|
|
})
|
|
cancel()
|
|
if err == nil {
|
|
return fmt.Errorf("test %v failed: expected err %w, instead got nil", i+1, test.err)
|
|
}
|
|
|
|
if err := checkApiErr(err, test.err); err != nil {
|
|
return fmt.Errorf("test %v failed: %w", i+1, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func CreateBucket_duplicate_keys(s *S3Conf) error {
|
|
testName := "CreateBucket_duplicate_keys"
|
|
return actionHandlerNoSetup(s, testName, func(s3client *s3.Client, bucket string) error {
|
|
tagging := []types.Tag{
|
|
{Key: getPtr("key"), Value: getPtr("value")},
|
|
{Key: getPtr("key"), Value: getPtr("value-1")},
|
|
{Key: getPtr("key-1"), Value: getPtr("value-2")},
|
|
{Key: getPtr("key-2"), Value: getPtr("value-3")},
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
_, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: &bucket,
|
|
CreateBucketConfiguration: &types.CreateBucketConfiguration{
|
|
Tags: tagging,
|
|
},
|
|
})
|
|
cancel()
|
|
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrDuplicateTagKey)); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func CreateBucket_tag_count_limit(s *S3Conf) error {
|
|
testName := "CreateBucket_tag_count_limit"
|
|
return actionHandlerNoSetup(s, testName, func(s3client *s3.Client, bucket string) error {
|
|
tagSet := []types.Tag{}
|
|
|
|
for i := range 51 {
|
|
tagSet = append(tagSet, types.Tag{
|
|
Key: getPtr(fmt.Sprintf("key-%v", i)),
|
|
Value: getPtr(genRandString(10)),
|
|
})
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
_, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: &bucket,
|
|
CreateBucketConfiguration: &types.CreateBucketConfiguration{
|
|
Tags: tagSet,
|
|
},
|
|
})
|
|
cancel()
|
|
return checkApiErr(err, s3err.GetAPIError(s3err.ErrBucketTaggingLimited))
|
|
})
|
|
}
|
|
|
|
func CreateBucket_invalid_canned_acl(s *S3Conf) error {
|
|
testName := "CreateBucket_invalid_canned_acl"
|
|
return actionHandlerNoSetup(s, testName, func(s3client *s3.Client, bucket string) error {
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
_, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: &bucket,
|
|
ACL: types.BucketCannedACL("invalid_acl"),
|
|
})
|
|
cancel()
|
|
return checkSdkApiErr(err, "InvalidArgument")
|
|
})
|
|
}
|
|
|
|
func CreateBucket_success(s *S3Conf) error {
|
|
testName := "CreateBucket_success"
|
|
return actionHandlerNoSetup(s, testName, func(s3client *s3.Client, bucket string) error {
|
|
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
|
res, err := s3client.CreateBucket(ctx, &s3.CreateBucketInput{
|
|
Bucket: &bucket,
|
|
})
|
|
cancel()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
expectedLocation := "/" + bucket
|
|
if getString(res.Location) != expectedLocation {
|
|
return fmt.Errorf("expected the bucket Location to be %s, instead got %s", expectedLocation, getString(res.Location))
|
|
}
|
|
expectedArn := "arn:aws:s3:::" + bucket
|
|
if getString(res.BucketArn) != expectedArn {
|
|
return fmt.Errorf("expected the bucket arn to be %s, instead got %s", expectedArn, getString(res.BucketArn))
|
|
}
|
|
|
|
return teardown(s, bucket)
|
|
})
|
|
}
|