2022-06-15 12:17:29 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2022-07-25 13:00:35 +00:00
|
|
|
"bytes"
|
2022-06-15 12:17:29 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
2022-06-15 12:17:29 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
const (
|
|
|
|
emptyVersion = ""
|
|
|
|
)
|
|
|
|
|
2022-07-21 09:05:47 +00:00
|
|
|
func TestDeleteBucket(t *testing.T) {
|
|
|
|
tc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
|
|
|
_, objInfo := createVersionedBucketAndObject(t, tc, bktName, objName)
|
|
|
|
|
2022-07-25 13:00:35 +00:00
|
|
|
deleteMarkerVersion, isDeleteMarker := deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.True(t, isDeleteMarker)
|
|
|
|
|
2022-07-21 09:05:47 +00:00
|
|
|
deleteBucket(t, tc, bktName, http.StatusConflict)
|
2022-08-04 17:31:33 +00:00
|
|
|
deleteObject(t, tc, bktName, objName, objInfo.VersionID())
|
2022-07-21 09:05:47 +00:00
|
|
|
deleteBucket(t, tc, bktName, http.StatusConflict)
|
2022-07-25 13:00:35 +00:00
|
|
|
deleteObject(t, tc, bktName, objName, deleteMarkerVersion)
|
2022-07-21 09:05:47 +00:00
|
|
|
deleteBucket(t, tc, bktName, http.StatusNoContent)
|
|
|
|
}
|
|
|
|
|
2022-06-15 12:17:29 +00:00
|
|
|
func TestDeleteObject(t *testing.T) {
|
|
|
|
tc := prepareHandlerContext(t)
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
2022-10-04 08:31:09 +00:00
|
|
|
bktInfo, objInfo := createBucketAndObject(tc, bktName, objName)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
checkFound(t, tc, bktName, objName, emptyVersion)
|
|
|
|
deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
checkNotFound(t, tc, bktName, objName, emptyVersion)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
require.False(t, existInMockedFrostFS(tc, bktInfo, objInfo))
|
2022-06-24 12:39:30 +00:00
|
|
|
}
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-07-25 13:00:35 +00:00
|
|
|
func TestDeleteObjectFromSuspended(t *testing.T) {
|
|
|
|
tc := prepareHandlerContext(t)
|
|
|
|
bktName, objName := "bucket-versioned-for-removal", "object-to-delete"
|
|
|
|
|
|
|
|
createSuspendedBucket(t, tc, bktName)
|
|
|
|
putObject(t, tc, bktName, objName)
|
|
|
|
|
|
|
|
versionID, isDeleteMarker := deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.True(t, isDeleteMarker)
|
2022-08-05 01:41:33 +00:00
|
|
|
require.Equal(t, data.UnversionedObjectVersionID, versionID)
|
2022-07-25 13:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteDeletedObject(t *testing.T) {
|
|
|
|
tc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
t.Run("unversioned bucket", func(t *testing.T) {
|
|
|
|
bktName, objName := "bucket-unversioned-removal", "object-to-delete"
|
2022-10-04 08:31:09 +00:00
|
|
|
createBucketAndObject(tc, bktName, objName)
|
2022-07-25 13:00:35 +00:00
|
|
|
|
|
|
|
versionID, isDeleteMarker := deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.Empty(t, versionID)
|
|
|
|
require.False(t, isDeleteMarker)
|
|
|
|
versionID, isDeleteMarker = deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.Empty(t, versionID)
|
|
|
|
require.False(t, isDeleteMarker)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("versioned bucket", func(t *testing.T) {
|
|
|
|
bktName, objName := "bucket-versioned-for-removal", "object-to-delete"
|
|
|
|
createVersionedBucketAndObject(t, tc, bktName, objName)
|
|
|
|
|
|
|
|
_, isDeleteMarker := deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.True(t, isDeleteMarker)
|
|
|
|
_, isDeleteMarker = deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.True(t, isDeleteMarker)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("versioned bucket not found obj", func(t *testing.T) {
|
|
|
|
bktName, objName := "bucket-versioned-for-removal", "object-to-delete"
|
|
|
|
_, objInfo := createVersionedBucketAndObject(t, tc, bktName, objName)
|
|
|
|
|
2022-08-04 17:31:33 +00:00
|
|
|
versionID, isDeleteMarker := deleteObject(t, tc, bktName, objName, objInfo.VersionID())
|
2022-07-25 13:00:35 +00:00
|
|
|
require.False(t, isDeleteMarker)
|
2022-08-04 17:31:33 +00:00
|
|
|
require.Equal(t, objInfo.VersionID(), versionID)
|
2022-07-25 13:00:35 +00:00
|
|
|
|
|
|
|
versionID2, isDeleteMarker := deleteObject(t, tc, bktName, objName, versionID)
|
|
|
|
require.False(t, isDeleteMarker)
|
2022-08-04 17:31:33 +00:00
|
|
|
require.Equal(t, objInfo.VersionID(), versionID2)
|
2022-07-25 13:00:35 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
func TestDeleteObjectVersioned(t *testing.T) {
|
|
|
|
tc := prepareHandlerContext(t)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
|
|
|
bktInfo, objInfo := createVersionedBucketAndObject(t, tc, bktName, objName)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
checkFound(t, tc, bktName, objName, emptyVersion)
|
|
|
|
deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
checkNotFound(t, tc, bktName, objName, emptyVersion)
|
|
|
|
|
2022-08-04 17:31:33 +00:00
|
|
|
checkFound(t, tc, bktName, objName, objInfo.VersionID())
|
|
|
|
deleteObject(t, tc, bktName, objName, objInfo.VersionID())
|
|
|
|
checkNotFound(t, tc, bktName, objName, objInfo.VersionID())
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
require.False(t, existInMockedFrostFS(tc, bktInfo, objInfo), "object exists but shouldn't")
|
2022-06-15 12:17:29 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 09:32:31 +00:00
|
|
|
func TestDeleteObjectUnversioned(t *testing.T) {
|
|
|
|
tc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName, objName := "bucket-for-removal-unversioned", "object-to-delete-unversioned"
|
2022-10-04 08:31:09 +00:00
|
|
|
bktInfo, objInfo := createBucketAndObject(tc, bktName, objName)
|
2022-07-01 09:32:31 +00:00
|
|
|
|
|
|
|
checkFound(t, tc, bktName, objName, emptyVersion)
|
|
|
|
deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
checkNotFound(t, tc, bktName, objName, emptyVersion)
|
|
|
|
|
|
|
|
versions := listVersions(t, tc, bktName)
|
|
|
|
require.Len(t, versions.DeleteMarker, 0, "delete markers must be empty")
|
|
|
|
require.Len(t, versions.Version, 0, "versions must be empty")
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
require.False(t, existInMockedFrostFS(tc, bktInfo, objInfo), "object exists but shouldn't")
|
2022-07-01 09:32:31 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
func TestRemoveDeleteMarker(t *testing.T) {
|
2022-06-15 12:17:29 +00:00
|
|
|
tc := prepareHandlerContext(t)
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
|
|
|
bktInfo, objInfo := createVersionedBucketAndObject(t, tc, bktName, objName)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
checkFound(t, tc, bktName, objName, emptyVersion)
|
2022-07-25 13:00:35 +00:00
|
|
|
deleteMarkerVersion, isDeleteMarker := deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.True(t, isDeleteMarker)
|
2022-06-24 12:39:30 +00:00
|
|
|
checkNotFound(t, tc, bktName, objName, emptyVersion)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-08-04 17:31:33 +00:00
|
|
|
checkFound(t, tc, bktName, objName, objInfo.VersionID())
|
2022-06-24 12:39:30 +00:00
|
|
|
deleteObject(t, tc, bktName, objName, deleteMarkerVersion)
|
2022-07-05 08:04:21 +00:00
|
|
|
checkFound(t, tc, bktName, objName, emptyVersion)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
require.True(t, existInMockedFrostFS(tc, bktInfo, objInfo), "object doesn't exist but should")
|
2022-06-24 12:39:30 +00:00
|
|
|
}
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2023-04-14 12:36:22 +00:00
|
|
|
func TestDeleteMarkerVersioned(t *testing.T) {
|
|
|
|
tc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
|
|
|
createVersionedBucketAndObject(t, tc, bktName, objName)
|
|
|
|
|
|
|
|
t.Run("not create new delete marker if last version is delete marker", func(t *testing.T) {
|
|
|
|
deleteMarkerVersion, isDeleteMarker := deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.True(t, isDeleteMarker)
|
|
|
|
versions := listVersions(t, tc, bktName)
|
|
|
|
require.Equal(t, deleteMarkerVersion, versions.DeleteMarker[0].VersionID)
|
|
|
|
|
|
|
|
_, isDeleteMarker = deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.True(t, isDeleteMarker)
|
|
|
|
versions = listVersions(t, tc, bktName)
|
|
|
|
require.Len(t, versions.DeleteMarker, 1)
|
|
|
|
require.Equal(t, deleteMarkerVersion, versions.DeleteMarker[0].VersionID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("do not create delete marker if object does not exist", func(t *testing.T) {
|
|
|
|
versionsBefore := listVersions(t, tc, bktName)
|
|
|
|
_, isDeleteMarker := deleteObject(t, tc, bktName, "dummy", emptyVersion)
|
|
|
|
require.False(t, isDeleteMarker)
|
|
|
|
versionsAfter := listVersions(t, tc, bktName)
|
|
|
|
require.Equal(t, versionsBefore, versionsAfter)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteMarkerSuspended(t *testing.T) {
|
|
|
|
tc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
|
|
|
bktInfo, _ := createVersionedBucketAndObject(t, tc, bktName, objName)
|
|
|
|
putBucketVersioning(t, tc, bktName, false)
|
|
|
|
|
|
|
|
t.Run("not create new delete marker if last version is delete marker", func(t *testing.T) {
|
|
|
|
deleteMarkerVersion, isDeleteMarker := deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.True(t, isDeleteMarker)
|
|
|
|
require.Equal(t, data.UnversionedObjectVersionID, deleteMarkerVersion)
|
|
|
|
|
|
|
|
deleteMarkerVersion, isDeleteMarker = deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.True(t, isDeleteMarker)
|
|
|
|
require.Equal(t, data.UnversionedObjectVersionID, deleteMarkerVersion)
|
|
|
|
|
|
|
|
versions := listVersions(t, tc, bktName)
|
|
|
|
require.Len(t, versions.DeleteMarker, 1)
|
|
|
|
require.Equal(t, deleteMarkerVersion, versions.DeleteMarker[0].VersionID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("do not create delete marker if object does not exist", func(t *testing.T) {
|
|
|
|
versionsBefore := listVersions(t, tc, bktName)
|
|
|
|
_, isDeleteMarker := deleteObject(t, tc, bktName, "dummy", emptyVersion)
|
|
|
|
require.False(t, isDeleteMarker)
|
|
|
|
versionsAfter := listVersions(t, tc, bktName)
|
|
|
|
require.Equal(t, versionsBefore, versionsAfter)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("remove last unversioned non delete marker", func(t *testing.T) {
|
|
|
|
objName := "obj3"
|
|
|
|
putObject(t, tc, bktName, objName)
|
|
|
|
|
|
|
|
nodeVersion, err := tc.tree.GetUnversioned(tc.Context(), bktInfo, objName)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
deleteMarkerVersion, isDeleteMarker := deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.True(t, isDeleteMarker)
|
|
|
|
require.Equal(t, data.UnversionedObjectVersionID, deleteMarkerVersion)
|
|
|
|
|
|
|
|
objVersions := getVersion(listVersions(t, tc, bktName), objName)
|
|
|
|
require.Len(t, objVersions, 0)
|
|
|
|
|
|
|
|
require.False(t, tc.MockedPool().ObjectExists(nodeVersion.OID))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
func TestDeleteObjectCombined(t *testing.T) {
|
|
|
|
tc := prepareHandlerContext(t)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
2022-10-04 08:31:09 +00:00
|
|
|
bktInfo, objInfo := createBucketAndObject(tc, bktName, objName)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
putBucketVersioning(t, tc, bktName, true)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
checkFound(t, tc, bktName, objName, emptyVersion)
|
|
|
|
deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
checkNotFound(t, tc, bktName, objName, emptyVersion)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-08-04 17:31:33 +00:00
|
|
|
checkFound(t, tc, bktName, objName, objInfo.VersionID())
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
require.True(t, existInMockedFrostFS(tc, bktInfo, objInfo), "object doesn't exist but should")
|
2022-06-15 12:17:29 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
func TestDeleteObjectSuspended(t *testing.T) {
|
2022-06-15 12:17:29 +00:00
|
|
|
tc := prepareHandlerContext(t)
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
2022-10-04 08:31:09 +00:00
|
|
|
bktInfo, objInfo := createBucketAndObject(tc, bktName, objName)
|
2022-06-24 12:39:30 +00:00
|
|
|
|
|
|
|
putBucketVersioning(t, tc, bktName, true)
|
|
|
|
|
|
|
|
checkFound(t, tc, bktName, objName, emptyVersion)
|
|
|
|
deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
checkNotFound(t, tc, bktName, objName, emptyVersion)
|
|
|
|
|
|
|
|
putBucketVersioning(t, tc, bktName, false)
|
|
|
|
|
|
|
|
deleteObject(t, tc, bktName, objName, emptyVersion)
|
2022-08-04 17:31:33 +00:00
|
|
|
checkNotFound(t, tc, bktName, objName, objInfo.VersionID())
|
2022-06-24 12:39:30 +00:00
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
require.False(t, existInMockedFrostFS(tc, bktInfo, objInfo), "object exists but shouldn't")
|
2022-06-24 12:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteMarkers(t *testing.T) {
|
|
|
|
tc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
2022-10-04 08:31:09 +00:00
|
|
|
createTestBucket(tc, bktName)
|
2022-06-24 12:39:30 +00:00
|
|
|
putBucketVersioning(t, tc, bktName, true)
|
|
|
|
|
|
|
|
checkNotFound(t, tc, bktName, objName, emptyVersion)
|
|
|
|
deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
|
|
|
|
versions := listVersions(t, tc, bktName)
|
2023-04-14 12:36:22 +00:00
|
|
|
require.Len(t, versions.DeleteMarker, 0, "invalid delete markers length")
|
2022-06-24 12:39:30 +00:00
|
|
|
require.Len(t, versions.Version, 0, "versions must be empty")
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
require.Len(t, listOIDsFromMockedFrostFS(t, tc, bktName), 0, "shouldn't be any object in frostfs")
|
2022-06-24 12:39:30 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 06:25:23 +00:00
|
|
|
func TestDeleteObjectFromListCache(t *testing.T) {
|
|
|
|
tc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
|
|
|
bktInfo, objInfo := createVersionedBucketAndObject(t, tc, bktName, objName)
|
|
|
|
|
2022-08-13 10:03:49 +00:00
|
|
|
versions := listObjectsV1(t, tc, bktName, "", "", "", -1)
|
2022-07-05 06:25:23 +00:00
|
|
|
require.Len(t, versions.Contents, 1)
|
|
|
|
|
2022-08-04 17:31:33 +00:00
|
|
|
checkFound(t, tc, bktName, objName, objInfo.VersionID())
|
|
|
|
deleteObject(t, tc, bktName, objName, objInfo.VersionID())
|
|
|
|
checkNotFound(t, tc, bktName, objName, objInfo.VersionID())
|
2022-07-05 06:25:23 +00:00
|
|
|
|
|
|
|
// check cache is clean after object removal
|
2022-08-13 10:03:49 +00:00
|
|
|
versions = listObjectsV1(t, tc, bktName, "", "", "", -1)
|
2022-07-05 06:25:23 +00:00
|
|
|
require.Len(t, versions.Contents, 0)
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
require.False(t, existInMockedFrostFS(tc, bktInfo, objInfo))
|
2022-07-05 06:25:23 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 08:04:21 +00:00
|
|
|
func TestDeleteObjectCheckMarkerReturn(t *testing.T) {
|
|
|
|
tc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
|
|
|
createVersionedBucketAndObject(t, tc, bktName, objName)
|
|
|
|
|
2022-07-25 13:00:35 +00:00
|
|
|
deleteMarkerVersion, isDeleteMarker := deleteObject(t, tc, bktName, objName, emptyVersion)
|
|
|
|
require.True(t, isDeleteMarker)
|
2022-07-05 08:04:21 +00:00
|
|
|
|
|
|
|
versions := listVersions(t, tc, bktName)
|
|
|
|
require.Len(t, versions.DeleteMarker, 1)
|
2022-07-25 13:00:35 +00:00
|
|
|
require.Equal(t, deleteMarkerVersion, versions.DeleteMarker[0].VersionID)
|
2022-07-05 08:04:21 +00:00
|
|
|
|
2022-07-25 13:00:35 +00:00
|
|
|
deleteMarkerVersion2, isDeleteMarker2 := deleteObject(t, tc, bktName, objName, deleteMarkerVersion)
|
|
|
|
require.True(t, isDeleteMarker2)
|
2022-07-05 08:04:21 +00:00
|
|
|
versions = listVersions(t, tc, bktName)
|
|
|
|
require.Len(t, versions.DeleteMarker, 0)
|
2022-07-25 13:00:35 +00:00
|
|
|
require.Equal(t, deleteMarkerVersion, deleteMarkerVersion2)
|
2022-07-05 08:04:21 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 08:31:09 +00:00
|
|
|
func createBucketAndObject(tc *handlerContext, bktName, objName string) (*data.BucketInfo, *data.ObjectInfo) {
|
|
|
|
bktInfo := createTestBucket(tc, bktName)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-10-04 08:31:09 +00:00
|
|
|
objInfo := createTestObject(tc, bktInfo, objName)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
return bktInfo, objInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func createVersionedBucketAndObject(t *testing.T, tc *handlerContext, bktName, objName string) (*data.BucketInfo, *data.ObjectInfo) {
|
2022-10-04 08:31:09 +00:00
|
|
|
createTestBucket(tc, bktName)
|
2022-06-24 12:39:30 +00:00
|
|
|
bktInfo, err := tc.Layer().GetBucketInfo(tc.Context(), bktName)
|
|
|
|
require.NoError(t, err)
|
|
|
|
putBucketVersioning(t, tc, bktName, true)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-10-04 08:31:09 +00:00
|
|
|
objInfo := createTestObject(tc, bktInfo, objName)
|
2022-06-24 12:39:30 +00:00
|
|
|
|
|
|
|
return bktInfo, objInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func putBucketVersioning(t *testing.T, tc *handlerContext, bktName string, enabled bool) {
|
|
|
|
cfg := &VersioningConfiguration{Status: "Suspended"}
|
|
|
|
if enabled {
|
|
|
|
cfg.Status = "Enabled"
|
|
|
|
}
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r := prepareTestRequest(tc, bktName, "", cfg)
|
2022-06-15 12:17:29 +00:00
|
|
|
tc.Handler().PutBucketVersioningHandler(w, r)
|
|
|
|
assertStatus(t, w, http.StatusOK)
|
2022-06-24 12:39:30 +00:00
|
|
|
}
|
|
|
|
|
2022-07-25 13:00:35 +00:00
|
|
|
func deleteObject(t *testing.T, tc *handlerContext, bktName, objName, version string) (string, bool) {
|
2022-06-24 12:39:30 +00:00
|
|
|
query := make(url.Values)
|
|
|
|
query.Add(api.QueryVersionID, version)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r := prepareTestFullRequest(tc, bktName, objName, query, nil)
|
2022-06-15 12:17:29 +00:00
|
|
|
tc.Handler().DeleteObjectHandler(w, r)
|
|
|
|
assertStatus(t, w, http.StatusNoContent)
|
|
|
|
|
2022-07-25 13:00:35 +00:00
|
|
|
return w.Header().Get(api.AmzVersionID), w.Header().Get(api.AmzDeleteMarker) != ""
|
2022-06-24 12:39:30 +00:00
|
|
|
}
|
|
|
|
|
2022-07-21 09:05:47 +00:00
|
|
|
func deleteBucket(t *testing.T, tc *handlerContext, bktName string, code int) {
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r := prepareTestRequest(tc, bktName, "", nil)
|
2022-07-21 09:05:47 +00:00
|
|
|
tc.Handler().DeleteBucketHandler(w, r)
|
|
|
|
assertStatus(t, w, code)
|
|
|
|
}
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
func checkNotFound(t *testing.T, tc *handlerContext, bktName, objName, version string) {
|
|
|
|
query := make(url.Values)
|
|
|
|
query.Add(api.QueryVersionID, version)
|
|
|
|
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r := prepareTestFullRequest(tc, bktName, objName, query, nil)
|
2022-06-15 12:17:29 +00:00
|
|
|
tc.Handler().HeadObjectHandler(w, r)
|
|
|
|
assertStatus(t, w, http.StatusNotFound)
|
2022-06-24 12:39:30 +00:00
|
|
|
}
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
func checkFound(t *testing.T, tc *handlerContext, bktName, objName, version string) {
|
2022-06-15 12:17:29 +00:00
|
|
|
query := make(url.Values)
|
2022-06-24 12:39:30 +00:00
|
|
|
query.Add(api.QueryVersionID, version)
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r := prepareTestFullRequest(tc, bktName, objName, query, nil)
|
2022-06-15 12:17:29 +00:00
|
|
|
tc.Handler().HeadObjectHandler(w, r)
|
2022-06-24 12:39:30 +00:00
|
|
|
assertStatus(t, w, http.StatusOK)
|
|
|
|
}
|
2022-06-15 12:17:29 +00:00
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
func listVersions(t *testing.T, tc *handlerContext, bktName string) *ListObjectsVersionsResponse {
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r := prepareTestRequest(tc, bktName, "", nil)
|
2022-06-24 12:39:30 +00:00
|
|
|
tc.Handler().ListBucketObjectVersionsHandler(w, r)
|
|
|
|
assertStatus(t, w, http.StatusOK)
|
|
|
|
res := &ListObjectsVersionsResponse{}
|
|
|
|
parseTestResponse(t, w, res)
|
|
|
|
return res
|
2022-06-15 12:17:29 +00:00
|
|
|
}
|
2022-07-05 06:25:23 +00:00
|
|
|
|
2023-04-14 12:36:22 +00:00
|
|
|
func getVersion(resp *ListObjectsVersionsResponse, objName string) []*ObjectVersionResponse {
|
|
|
|
var res []*ObjectVersionResponse
|
|
|
|
for i, version := range resp.Version {
|
|
|
|
if version.Key == objName {
|
|
|
|
res = append(res, &resp.Version[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2022-07-25 13:00:35 +00:00
|
|
|
func putObject(t *testing.T, tc *handlerContext, bktName, objName string) {
|
|
|
|
body := bytes.NewReader([]byte("content"))
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r := prepareTestPayloadRequest(tc, bktName, objName, body)
|
2022-07-25 13:00:35 +00:00
|
|
|
tc.Handler().PutObjectHandler(w, r)
|
|
|
|
assertStatus(t, w, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
|
|
|
func createSuspendedBucket(t *testing.T, tc *handlerContext, bktName string) *data.BucketInfo {
|
2022-10-04 08:31:09 +00:00
|
|
|
createTestBucket(tc, bktName)
|
2022-07-25 13:00:35 +00:00
|
|
|
bktInfo, err := tc.Layer().GetBucketInfo(tc.Context(), bktName)
|
|
|
|
require.NoError(t, err)
|
|
|
|
putBucketVersioning(t, tc, bktName, false)
|
|
|
|
return bktInfo
|
|
|
|
}
|