s3api: preserve lifecycle config responses for Terraform (#8805)
* s3api: preserve lifecycle configs for terraform * s3api: bound lifecycle config request bodies * s3api: make bucket config updates copy-on-write * s3api: tighten string slice cloning
This commit is contained in:
47
weed/s3api/s3api_bucket_config_update_test.go
Normal file
47
weed/s3api/s3api_bucket_config_update_test.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package s3api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUpdateBucketConfigDoesNotMutateCacheOnPersistFailure(t *testing.T) {
|
||||
const bucket = "cleanup-test-net"
|
||||
|
||||
s3a := newTestS3ApiServerWithMemoryIAM(t, nil)
|
||||
s3a.option = &S3ApiServerOption{
|
||||
BucketsPath: "/buckets",
|
||||
}
|
||||
s3a.bucketConfigCache = NewBucketConfigCache(time.Minute)
|
||||
s3a.bucketConfigCache.Set(bucket, &BucketConfig{
|
||||
Name: bucket,
|
||||
Versioning: "",
|
||||
Entry: &filer_pb.Entry{
|
||||
Name: bucket,
|
||||
IsDirectory: true,
|
||||
Extended: map[string][]byte{},
|
||||
},
|
||||
})
|
||||
|
||||
// This test server only has in-memory IAM state and no filer connection, so
|
||||
// updateBucketConfig is expected to fail during the persist step with an
|
||||
// internal error. The assertion below verifies that the cached config stays
|
||||
// unchanged when that write path fails.
|
||||
errCode := s3a.updateBucketConfig(bucket, func(config *BucketConfig) error {
|
||||
config.Versioning = s3_constants.VersioningEnabled
|
||||
return nil
|
||||
})
|
||||
|
||||
require.Equal(t, s3err.ErrInternalError, errCode)
|
||||
|
||||
config, found := s3a.bucketConfigCache.Get(bucket)
|
||||
require.True(t, found)
|
||||
assert.Empty(t, config.Versioning)
|
||||
assert.NotContains(t, config.Entry.Extended, s3_constants.ExtVersioningKey)
|
||||
}
|
||||
Reference in New Issue
Block a user