[#411] Check uniqueness in DeleteMultipleObjects
All checks were successful
/ Builds (1.20) (pull_request) Successful in 4m57s
/ Builds (1.21) (pull_request) Successful in 4m42s
/ DCO (pull_request) Successful in 4m52s
/ Vulncheck (pull_request) Successful in 4m38s
/ Lint (pull_request) Successful in 6m46s
/ Tests (1.20) (pull_request) Successful in 4m28s
/ Tests (1.21) (pull_request) Successful in 4m7s

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2024-06-26 16:31:43 +03:00
parent 943b30d9f4
commit 91541a432d
2 changed files with 19 additions and 3 deletions

View file

@ -150,15 +150,18 @@ func (h *handler) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *http.Re
return return
} }
removed := make(map[string]*layer.VersionedObject) unique := make(map[string]struct{})
toRemove := make([]*layer.VersionedObject, 0, len(requested.Objects)) toRemove := make([]*layer.VersionedObject, 0, len(requested.Objects))
for _, obj := range requested.Objects { for _, obj := range requested.Objects {
versionedObj := &layer.VersionedObject{ versionedObj := &layer.VersionedObject{
Name: obj.ObjectName, Name: obj.ObjectName,
VersionID: obj.VersionID, VersionID: obj.VersionID,
} }
toRemove = append(toRemove, versionedObj) key := versionedObj.String()
removed[versionedObj.String()] = versionedObj if _, ok := unique[key]; !ok {
toRemove = append(toRemove, versionedObj)
unique[key] = struct{}{}
}
} }
response := &DeleteObjectsResponse{ response := &DeleteObjectsResponse{

View file

@ -85,6 +85,19 @@ func TestDeleteBucketOnNotFoundError(t *testing.T) {
deleteBucket(t, hc, bktName, http.StatusNoContent) deleteBucket(t, hc, bktName, http.StatusNoContent)
} }
func TestDeleteMultipleObjectCheckUniqueness(t *testing.T) {
hc := prepareHandlerContext(t)
bktName, objName := "bucket", "object"
createTestBucket(hc, bktName)
putObject(hc, bktName, objName)
resp := deleteObjects(t, hc, bktName, [][2]string{{objName, emptyVersion}, {objName, emptyVersion}})
require.Empty(t, resp.Errors)
require.Len(t, resp.DeletedObjects, 1)
}
func TestDeleteObjectsError(t *testing.T) { func TestDeleteObjectsError(t *testing.T) {
hc := prepareHandlerContext(t) hc := prepareHandlerContext(t)