2024-08-12 11:22:56 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2024-10-15 11:18:38 +00:00
|
|
|
"bytes"
|
2024-08-12 11:22:56 +00:00
|
|
|
"crypto/md5"
|
|
|
|
"crypto/rand"
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/xml"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
2024-09-27 09:18:41 +00:00
|
|
|
apierr "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
|
2024-08-12 11:22:56 +00:00
|
|
|
"github.com/mr-tron/base58"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPutBucketLifecycleConfiguration(t *testing.T) {
|
|
|
|
hc := prepareHandlerContextWithMinCache(t)
|
|
|
|
|
|
|
|
bktName := "bucket-lifecycle"
|
|
|
|
createBucket(hc, bktName)
|
|
|
|
|
|
|
|
for _, tc := range []struct {
|
2024-11-08 08:45:10 +00:00
|
|
|
name string
|
|
|
|
body *data.LifecycleConfiguration
|
|
|
|
errorCode apierr.ErrorCode
|
2024-08-12 11:22:56 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "correct configuration",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
2024-11-08 08:45:10 +00:00
|
|
|
ID: "rule-1",
|
2024-08-12 11:22:56 +00:00
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(21),
|
|
|
|
Date: time.Now().Format("2006-01-02T15:04:05.000Z"),
|
|
|
|
},
|
|
|
|
Filter: &data.LifecycleRuleFilter{
|
|
|
|
And: &data.LifecycleRuleAndOperator{
|
|
|
|
Prefix: "prefix/",
|
|
|
|
Tags: []data.Tag{{Key: "key", Value: "value"}, {Key: "tag", Value: ""}},
|
|
|
|
ObjectSizeGreaterThan: ptr(uint64(100)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-11-08 08:45:10 +00:00
|
|
|
ID: "rule-2",
|
2024-08-12 11:22:56 +00:00
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
AbortIncompleteMultipartUpload: &data.AbortIncompleteMultipartUpload{
|
|
|
|
DaysAfterInitiation: ptr(14),
|
|
|
|
},
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
ExpiredObjectDeleteMarker: ptr(true),
|
|
|
|
},
|
|
|
|
Filter: &data.LifecycleRuleFilter{
|
|
|
|
ObjectSizeLessThan: ptr(uint64(100)),
|
|
|
|
},
|
|
|
|
NonCurrentVersionExpiration: &data.NonCurrentVersionExpiration{
|
|
|
|
NewerNonCurrentVersions: ptr(1),
|
|
|
|
NonCurrentDays: ptr(21),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "too many rules",
|
|
|
|
body: func() *data.LifecycleConfiguration {
|
|
|
|
lifecycle := new(data.LifecycleConfiguration)
|
|
|
|
for i := 0; i <= maxRules; i++ {
|
|
|
|
lifecycle.Rules = append(lifecycle.Rules, data.LifecycleRule{
|
|
|
|
ID: "Rule" + strconv.Itoa(i),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return lifecycle
|
|
|
|
}(),
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidRequest,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "duplicate rule ID",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
ID: "Rule",
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(21),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "Rule",
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(21),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidArgument,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "too long rule ID",
|
|
|
|
body: func() *data.LifecycleConfiguration {
|
|
|
|
id := make([]byte, maxRuleIDLen+1)
|
|
|
|
_, err := io.ReadFull(rand.Reader, id)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
ID: base58.Encode(id)[:maxRuleIDLen+1],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}(),
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidArgument,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid status",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: "invalid",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrMalformedXML,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no actions",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Filter: &data.LifecycleRuleFilter{
|
|
|
|
Prefix: "prefix/",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidRequest,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid days after initiation",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
AbortIncompleteMultipartUpload: &data.AbortIncompleteMultipartUpload{
|
|
|
|
DaysAfterInitiation: ptr(0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidArgument,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid expired object delete marker declaration",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(21),
|
|
|
|
ExpiredObjectDeleteMarker: ptr(false),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrMalformedXML,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid expiration days",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidArgument,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid expiration date",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Date: "invalid",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidArgument,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "newer noncurrent versions is too small",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
NonCurrentVersionExpiration: &data.NonCurrentVersionExpiration{
|
2024-11-08 08:45:10 +00:00
|
|
|
NonCurrentDays: ptr(1),
|
2024-08-12 11:22:56 +00:00
|
|
|
NewerNonCurrentVersions: ptr(0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidArgument,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "newer noncurrent versions is too large",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
NonCurrentVersionExpiration: &data.NonCurrentVersionExpiration{
|
2024-11-08 08:45:10 +00:00
|
|
|
NonCurrentDays: ptr(1),
|
2024-08-12 11:22:56 +00:00
|
|
|
NewerNonCurrentVersions: ptr(101),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidArgument,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid noncurrent days",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
NonCurrentVersionExpiration: &data.NonCurrentVersionExpiration{
|
|
|
|
NonCurrentDays: ptr(0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidArgument,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "more than one filter field",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(21),
|
|
|
|
},
|
|
|
|
Filter: &data.LifecycleRuleFilter{
|
|
|
|
Prefix: "prefix/",
|
|
|
|
ObjectSizeGreaterThan: ptr(uint64(100)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrMalformedXML,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid tag in filter",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(21),
|
|
|
|
},
|
|
|
|
Filter: &data.LifecycleRuleFilter{
|
|
|
|
Tag: &data.Tag{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidTagKey,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "abort incomplete multipart upload with tag",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
AbortIncompleteMultipartUpload: &data.AbortIncompleteMultipartUpload{
|
|
|
|
DaysAfterInitiation: ptr(14),
|
|
|
|
},
|
|
|
|
Filter: &data.LifecycleRuleFilter{
|
|
|
|
Tag: &data.Tag{Key: "key", Value: "value"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidRequest,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "expired object delete marker with tag",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
ExpiredObjectDeleteMarker: ptr(true),
|
|
|
|
},
|
|
|
|
Filter: &data.LifecycleRuleFilter{
|
|
|
|
And: &data.LifecycleRuleAndOperator{
|
|
|
|
Tags: []data.Tag{{Key: "key", Value: "value"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidRequest,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid size range",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(21),
|
|
|
|
},
|
|
|
|
Filter: &data.LifecycleRuleFilter{
|
|
|
|
And: &data.LifecycleRuleAndOperator{
|
|
|
|
ObjectSizeGreaterThan: ptr(uint64(100)),
|
|
|
|
ObjectSizeLessThan: ptr(uint64(100)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-11-08 08:45:10 +00:00
|
|
|
errorCode: apierr.ErrInvalidRequest,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "two prefixes",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(21),
|
|
|
|
},
|
|
|
|
Filter: &data.LifecycleRuleFilter{
|
|
|
|
Prefix: "prefix-1/",
|
|
|
|
},
|
|
|
|
Prefix: "prefix-2/",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
errorCode: apierr.ErrMalformedXML,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "newer noncurrent versions without noncurrent days",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
NonCurrentVersionExpiration: &data.NonCurrentVersionExpiration{
|
|
|
|
NewerNonCurrentVersions: ptr(10),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
errorCode: apierr.ErrMalformedXML,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid maximum object size in filter",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(21),
|
|
|
|
},
|
|
|
|
Filter: &data.LifecycleRuleFilter{
|
|
|
|
ObjectSizeLessThan: ptr(uint64(0)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
errorCode: apierr.ErrInvalidRequest,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid maximum object size in filter and",
|
|
|
|
body: &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(21),
|
|
|
|
},
|
|
|
|
Filter: &data.LifecycleRuleFilter{
|
|
|
|
And: &data.LifecycleRuleAndOperator{
|
|
|
|
Prefix: "prefix/",
|
|
|
|
ObjectSizeLessThan: ptr(uint64(0)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
errorCode: apierr.ErrInvalidRequest,
|
2024-08-12 11:22:56 +00:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2024-11-08 08:45:10 +00:00
|
|
|
if tc.errorCode > 0 {
|
|
|
|
putBucketLifecycleConfigurationErr(hc, bktName, tc.body, apierr.GetAPIError(tc.errorCode))
|
2024-08-12 11:22:56 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
putBucketLifecycleConfiguration(hc, bktName, tc.body)
|
|
|
|
|
|
|
|
cfg := getBucketLifecycleConfiguration(hc, bktName)
|
2024-11-08 08:45:10 +00:00
|
|
|
require.Equal(t, tc.body.Rules, cfg.Rules)
|
2024-08-12 11:22:56 +00:00
|
|
|
|
|
|
|
deleteBucketLifecycleConfiguration(hc, bktName)
|
2024-09-27 09:18:41 +00:00
|
|
|
getBucketLifecycleConfigurationErr(hc, bktName, apierr.GetAPIError(apierr.ErrNoSuchLifecycleConfiguration))
|
2024-08-12 11:22:56 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-08 08:47:10 +00:00
|
|
|
func TestPutBucketLifecycleIDGeneration(t *testing.T) {
|
|
|
|
hc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName := "bucket-lifecycle-id"
|
|
|
|
createBucket(hc, bktName)
|
|
|
|
|
|
|
|
lifecycle := &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(21),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
AbortIncompleteMultipartUpload: &data.AbortIncompleteMultipartUpload{
|
|
|
|
DaysAfterInitiation: ptr(14),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
putBucketLifecycleConfiguration(hc, bktName, lifecycle)
|
|
|
|
cfg := getBucketLifecycleConfiguration(hc, bktName)
|
|
|
|
require.Len(t, cfg.Rules, 2)
|
|
|
|
require.NotEmpty(t, cfg.Rules[0].ID)
|
|
|
|
require.NotEmpty(t, cfg.Rules[1].ID)
|
|
|
|
}
|
|
|
|
|
2024-08-12 11:22:56 +00:00
|
|
|
func TestPutBucketLifecycleInvalidMD5(t *testing.T) {
|
|
|
|
hc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName := "bucket-lifecycle-md5"
|
|
|
|
createBucket(hc, bktName)
|
|
|
|
|
|
|
|
lifecycle := &data.LifecycleConfiguration{
|
|
|
|
Rules: []data.LifecycleRule{
|
|
|
|
{
|
|
|
|
Status: data.LifecycleStatusEnabled,
|
|
|
|
Expiration: &data.LifecycleExpiration{
|
|
|
|
Days: ptr(21),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
w, r := prepareTestRequest(hc, bktName, "", lifecycle)
|
|
|
|
hc.Handler().PutBucketLifecycleHandler(w, r)
|
2024-09-27 09:18:41 +00:00
|
|
|
assertS3Error(hc.t, w, apierr.GetAPIError(apierr.ErrMissingContentMD5))
|
2024-08-12 11:22:56 +00:00
|
|
|
|
2024-10-15 11:18:38 +00:00
|
|
|
w, r = prepareTestRequest(hc, bktName, "", lifecycle)
|
|
|
|
r.Header.Set(api.ContentMD5, "")
|
|
|
|
hc.Handler().PutBucketLifecycleHandler(w, r)
|
|
|
|
assertS3Error(hc.t, w, apierr.GetAPIError(apierr.ErrInvalidDigest))
|
|
|
|
|
2024-08-12 11:22:56 +00:00
|
|
|
w, r = prepareTestRequest(hc, bktName, "", lifecycle)
|
|
|
|
r.Header.Set(api.ContentMD5, "some-hash")
|
|
|
|
hc.Handler().PutBucketLifecycleHandler(w, r)
|
2024-09-27 09:18:41 +00:00
|
|
|
assertS3Error(hc.t, w, apierr.GetAPIError(apierr.ErrInvalidDigest))
|
2024-08-12 11:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPutBucketLifecycleInvalidXML(t *testing.T) {
|
|
|
|
hc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName := "bucket-lifecycle-invalid-xml"
|
|
|
|
createBucket(hc, bktName)
|
|
|
|
|
2024-10-15 11:18:38 +00:00
|
|
|
cfg := &data.CORSConfiguration{}
|
|
|
|
body, err := xml.Marshal(cfg)
|
|
|
|
require.NoError(t, err)
|
|
|
|
contentMD5, err := getContentMD5(bytes.NewReader(body))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
w, r := prepareTestRequest(hc, bktName, "", cfg)
|
|
|
|
r.Header.Set(api.ContentMD5, base64.StdEncoding.EncodeToString(contentMD5))
|
2024-08-12 11:22:56 +00:00
|
|
|
hc.Handler().PutBucketLifecycleHandler(w, r)
|
2024-09-27 09:18:41 +00:00
|
|
|
assertS3Error(hc.t, w, apierr.GetAPIError(apierr.ErrMalformedXML))
|
2024-08-12 11:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func putBucketLifecycleConfiguration(hc *handlerContext, bktName string, cfg *data.LifecycleConfiguration) {
|
|
|
|
w := putBucketLifecycleConfigurationBase(hc, bktName, cfg)
|
|
|
|
assertStatus(hc.t, w, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2024-09-27 09:18:41 +00:00
|
|
|
func putBucketLifecycleConfigurationErr(hc *handlerContext, bktName string, cfg *data.LifecycleConfiguration, err apierr.Error) {
|
2024-08-12 11:22:56 +00:00
|
|
|
w := putBucketLifecycleConfigurationBase(hc, bktName, cfg)
|
|
|
|
assertS3Error(hc.t, w, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func putBucketLifecycleConfigurationBase(hc *handlerContext, bktName string, cfg *data.LifecycleConfiguration) *httptest.ResponseRecorder {
|
|
|
|
w, r := prepareTestRequest(hc, bktName, "", cfg)
|
|
|
|
|
|
|
|
rawBody, err := xml.Marshal(cfg)
|
|
|
|
require.NoError(hc.t, err)
|
|
|
|
|
|
|
|
hash := md5.New()
|
|
|
|
hash.Write(rawBody)
|
|
|
|
r.Header.Set(api.ContentMD5, base64.StdEncoding.EncodeToString(hash.Sum(nil)))
|
|
|
|
hc.Handler().PutBucketLifecycleHandler(w, r)
|
|
|
|
return w
|
|
|
|
}
|
|
|
|
|
|
|
|
func getBucketLifecycleConfiguration(hc *handlerContext, bktName string) *data.LifecycleConfiguration {
|
|
|
|
w := getBucketLifecycleConfigurationBase(hc, bktName)
|
|
|
|
assertStatus(hc.t, w, http.StatusOK)
|
|
|
|
res := &data.LifecycleConfiguration{}
|
|
|
|
parseTestResponse(hc.t, w, res)
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2024-09-27 09:18:41 +00:00
|
|
|
func getBucketLifecycleConfigurationErr(hc *handlerContext, bktName string, err apierr.Error) {
|
2024-08-12 11:22:56 +00:00
|
|
|
w := getBucketLifecycleConfigurationBase(hc, bktName)
|
|
|
|
assertS3Error(hc.t, w, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getBucketLifecycleConfigurationBase(hc *handlerContext, bktName string) *httptest.ResponseRecorder {
|
|
|
|
w, r := prepareTestRequest(hc, bktName, "", nil)
|
|
|
|
hc.Handler().GetBucketLifecycleHandler(w, r)
|
|
|
|
return w
|
|
|
|
}
|
|
|
|
|
|
|
|
func deleteBucketLifecycleConfiguration(hc *handlerContext, bktName string) {
|
|
|
|
w := deleteBucketLifecycleConfigurationBase(hc, bktName)
|
|
|
|
assertStatus(hc.t, w, http.StatusNoContent)
|
|
|
|
}
|
|
|
|
|
|
|
|
func deleteBucketLifecycleConfigurationBase(hc *handlerContext, bktName string) *httptest.ResponseRecorder {
|
|
|
|
w, r := prepareTestRequest(hc, bktName, "", nil)
|
|
|
|
hc.Handler().DeleteBucketLifecycleHandler(w, r)
|
|
|
|
return w
|
|
|
|
}
|
|
|
|
|
|
|
|
func ptr[T any](t T) *T {
|
|
|
|
return &t
|
|
|
|
}
|