Skip to content

Commit

Permalink
Merge pull request #876 from versity/fix/put-bucket-versioning-suspended
Browse files Browse the repository at this point in the history
fix: Removed ObjectLockConfigurationNotFoundError, when attempting to…
  • Loading branch information
benmcclelland authored Oct 7, 2024
2 parents da98874 + b5b592c commit d2b0d24
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
16 changes: 9 additions & 7 deletions backend/posix/posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,15 +466,17 @@ func (p *Posix) PutBucketVersioning(ctx context.Context, bucket string, status t
versioning = []byte{1}
case types.BucketVersioningStatusSuspended:
lockRaw, err := p.GetObjectLockConfiguration(ctx, bucket)
if err != nil {
if err != nil && !errors.Is(err, s3err.GetAPIError(s3err.ErrObjectLockConfigurationNotFound)) {
return err
}
lockStatus, err := auth.ParseBucketLockConfigurationOutput(lockRaw)
if err != nil {
return err
}
if lockStatus.ObjectLockEnabled == types.ObjectLockEnabledEnabled {
return s3err.GetAPIError(s3err.ErrSuspendedVersioningNotAllowed)
if err == nil {
lockStatus, err := auth.ParseBucketLockConfigurationOutput(lockRaw)
if err != nil {
return err
}
if lockStatus.ObjectLockEnabled == types.ObjectLockEnabledEnabled {
return s3err.GetAPIError(s3err.ErrSuspendedVersioningNotAllowed)
}
}

// '0' maps to 'Suspended'
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/group-tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ func TestVersioning(s *S3Conf) {
// PutBucketVersioning action
PutBucketVersioning_non_existing_bucket(s)
PutBucketVersioning_invalid_status(s)
PutBucketVersioning_success(s)
PutBucketVersioning_success_enabled(s)
PutBucketVersioning_success_suspended(s)
// GetBucketVersioning action
GetBucketVersioning_non_existing_bucket(s)
GetBucketVersioning_empty_response(s)
Expand Down Expand Up @@ -906,7 +907,8 @@ func GetIntTests() IntTests {
"AccessControl_copy_object_with_starting_slash_for_user": AccessControl_copy_object_with_starting_slash_for_user,
"PutBucketVersioning_non_existing_bucket": PutBucketVersioning_non_existing_bucket,
"PutBucketVersioning_invalid_status": PutBucketVersioning_invalid_status,
"PutBucketVersioning_success": PutBucketVersioning_success,
"PutBucketVersioning_success_enabled": PutBucketVersioning_success_enabled,
"PutBucketVersioning_success_suspended": PutBucketVersioning_success_suspended,
"GetBucketVersioning_non_existing_bucket": GetBucketVersioning_non_existing_bucket,
"GetBucketVersioning_empty_response": GetBucketVersioning_empty_response,
"GetBucketVersioning_success": GetBucketVersioning_success,
Expand Down
23 changes: 21 additions & 2 deletions tests/integration/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -10453,8 +10453,8 @@ func PutBucketVersioning_invalid_status(s *S3Conf) error {
})
}

func PutBucketVersioning_success(s *S3Conf) error {
testName := "PutBucketVersioning_success"
func PutBucketVersioning_success_enabled(s *S3Conf) error {
testName := "PutBucketVersioning_success_enabled"
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
_, err := s3client.PutBucketVersioning(ctx, &s3.PutBucketVersioningInput{
Expand All @@ -10472,6 +10472,25 @@ func PutBucketVersioning_success(s *S3Conf) error {
})
}

func PutBucketVersioning_success_suspended(s *S3Conf) error {
testName := "PutBucketVersioning_success_suspended"
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
_, err := s3client.PutBucketVersioning(ctx, &s3.PutBucketVersioningInput{
Bucket: &bucket,
VersioningConfiguration: &types.VersioningConfiguration{
Status: types.BucketVersioningStatusSuspended,
},
})
cancel()
if err != nil {
return err
}

return nil
})
}

func GetBucketVersioning_non_existing_bucket(s *S3Conf) error {
testName := "GetBucketVersioning_non_existing_bucket"
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
Expand Down

0 comments on commit d2b0d24

Please sign in to comment.