s3api: enforce object lock protections on delete (COMPLIANCE/GOVERNANCE)

Enforce object lock protections before creating delete markers; active COMPLIANCE retention denies deletes and active GOVERNANCE retention denies deletes unless bypass is authorized. Includes unit tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Chris LuandCopilot committed 2026-02-16 01:52:08 -08:00
1 parent 703d5e27b3
commit 5e040ba03d
2 files changed
+108 -39

No files matched your search

@@ -0,0 +1,62 @@
package s3api
import (
"testing"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
"github.com/stretchr/testify/assert"
)
func TestObjectLockVersionToCheckForDelete(t *testing.T) {
tests := []struct {
name string
versioningState string
requestedVersionID string
expectedVersionID string
expectedShouldCheck bool
}{
{
name: "enabled versioning without version id checks latest version",
versioningState: s3_constants.VersioningEnabled,
requestedVersionID: "",
expectedVersionID: "",
expectedShouldCheck: true,
},
{
name: "suspended versioning without version id checks null version",
versioningState: s3_constants.VersioningSuspended,
requestedVersionID: "",
expectedVersionID: "null",
expectedShouldCheck: true,
},
{
name: "specific version id is always checked",
versioningState: s3_constants.VersioningEnabled,
requestedVersionID: "3LgYQ7f7VxQ3",
expectedVersionID: "3LgYQ7f7VxQ3",
expectedShouldCheck: true,
},
{
name: "non-versioned buckets still check current object",
versioningState: "",
requestedVersionID: "",
expectedVersionID: "",
expectedShouldCheck: true,
},
{
name: "unknown versioning state without version id is skipped",
versioningState: "UnexpectedState",
requestedVersionID: "",
expectedVersionID: "",
expectedShouldCheck: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
versionID, shouldCheck := objectLockVersionToCheckForDelete(tc.versioningState, tc.requestedVersionID)
assert.Equal(t, tc.expectedVersionID, versionID)
assert.Equal(t, tc.expectedShouldCheck, shouldCheck)
})
}
}