From 391baa1c9a0e55d789210be66d8d0b832544e30c Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Wed, 22 May 2024 19:26:59 +0800 Subject: [PATCH] test: add reject ilm rule test case (#19788) --- internal/bucket/lifecycle/lifecycle.go | 3 +- internal/bucket/lifecycle/lifecycle_test.go | 34 ++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/internal/bucket/lifecycle/lifecycle.go b/internal/bucket/lifecycle/lifecycle.go index ea1e7a05d..d98bd9e5f 100644 --- a/internal/bucket/lifecycle/lifecycle.go +++ b/internal/bucket/lifecycle/lifecycle.go @@ -36,6 +36,7 @@ var ( errLifecycleNoRule = Errorf("Lifecycle configuration should have at least one rule") errLifecycleDuplicateID = Errorf("Rule ID must be unique. Found same ID for more than one rule") errXMLNotWellFormed = Errorf("The XML you provided was not well-formed or did not validate against our published schema") + errLifecycleBucketLocked = Errorf("--expire-day, --expire-delete-marker, --expire-all-object-versions and --noncurrent-expire-days can't be used for locked bucket") ) const ( @@ -256,7 +257,7 @@ func (lc Lifecycle) Validate(lr lock.Retention) error { !r.DelMarkerExpiration.Empty() || // DelMarkerDeleteAllVersionsAction !r.NoncurrentVersionExpiration.IsDaysNull() || // DeleteVersionAction !r.Expiration.IsDaysNull()) && lr.LockEnabled { - return fmt.Errorf("DeleteAllVersions and DeleteMarkerDeleteAllVersions cannot be set when bucket lock is enabled") + return errLifecycleBucketLocked } } // Make sure Rule ID is unique diff --git a/internal/bucket/lifecycle/lifecycle_test.go b/internal/bucket/lifecycle/lifecycle_test.go index 766c4c8b8..28ffc5f90 100644 --- a/internal/bucket/lifecycle/lifecycle_test.go +++ b/internal/bucket/lifecycle/lifecycle_test.go @@ -39,6 +39,7 @@ func TestParseAndValidateLifecycleConfig(t *testing.T) { inputConfig string expectedParsingErr error expectedValidationErr error + lr lock.Retention }{ { // Valid lifecycle config inputConfig: ` @@ -62,6 +63,37 @@ func TestParseAndValidateLifecycleConfig(t *testing.T) { expectedParsingErr: nil, expectedValidationErr: nil, }, + { // invalid lifecycle config + inputConfig: ` + + testRule1 + + prefix + + Enabled + 3 + + + testRule2 + + another-prefix + + Enabled + 3 + + `, + expectedParsingErr: nil, + expectedValidationErr: errLifecycleBucketLocked, + lr: lock.Retention{ + LockEnabled: true, + }, + }, + { // lifecycle config with no rules + inputConfig: ` + `, + expectedParsingErr: nil, + expectedValidationErr: errLifecycleNoRule, + }, { // Valid lifecycle config inputConfig: ` @@ -145,7 +177,7 @@ func TestParseAndValidateLifecycleConfig(t *testing.T) { // no need to continue this test. return } - err = lc.Validate(lock.Retention{}) + err = lc.Validate(tc.lr) if err != tc.expectedValidationErr { t.Fatalf("%d: Expected %v during validation but got %v", i+1, tc.expectedValidationErr, err) }