2021-08-16 13:04:33 +01:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metabase_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2023-10-17 17:00:03 +01:00
|
|
|
"time"
|
2021-08-16 13:04:33 +01:00
|
|
|
|
2021-08-31 12:44:18 +01:00
|
|
|
"storj.io/common/storj"
|
2021-08-16 13:04:33 +01:00
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
|
|
|
"storj.io/storj/satellite/metabase"
|
|
|
|
"storj.io/storj/satellite/metabase/metabasetest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBeginMoveObject(t *testing.T) {
|
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
for _, test := range metabasetest.InvalidObjectLocations(obj.Location()) {
|
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.BeginMoveObject{
|
|
|
|
Opts: metabase.BeginMoveObject{
|
|
|
|
ObjectLocation: test.ObjectLocation,
|
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-08-08 16:14:08 +01:00
|
|
|
t.Run("begin move object", func(t *testing.T) {
|
2021-08-16 13:04:33 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
2022-08-08 16:14:08 +01:00
|
|
|
expectedRawObjects := []metabase.RawObject{}
|
|
|
|
expectedRawSegments := []metabase.RawSegment{}
|
2021-08-16 13:04:33 +01:00
|
|
|
|
2022-08-08 16:14:08 +01:00
|
|
|
for _, expectedVersion := range []metabase.Version{1, 2, 3, 11} {
|
2022-09-21 09:10:06 +01:00
|
|
|
obj.ObjectKey = metabasetest.RandObjectKey()
|
2022-08-08 16:14:08 +01:00
|
|
|
obj.StreamID = testrand.UUID()
|
|
|
|
obj.Version = expectedVersion
|
|
|
|
expectedObject, expectedSegments := metabasetest.CreateTestObject{
|
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj, 10)
|
2021-08-16 13:04:33 +01:00
|
|
|
|
2022-08-08 16:14:08 +01:00
|
|
|
expectedRawObjects = append(expectedRawObjects, metabase.RawObject(expectedObject))
|
2021-08-16 13:04:33 +01:00
|
|
|
|
2022-08-08 16:14:08 +01:00
|
|
|
var encKeyAndNonces []metabase.EncryptedKeyAndNonce
|
|
|
|
for _, expectedSegment := range expectedSegments {
|
|
|
|
encKeyAndNonces = append(encKeyAndNonces, metabase.EncryptedKeyAndNonce{
|
|
|
|
EncryptedKeyNonce: expectedSegment.EncryptedKeyNonce,
|
|
|
|
EncryptedKey: expectedSegment.EncryptedKey,
|
|
|
|
Position: expectedSegment.Position,
|
|
|
|
})
|
2021-08-16 13:04:33 +01:00
|
|
|
|
2022-08-08 16:14:08 +01:00
|
|
|
expectedRawSegments = append(expectedRawSegments, metabase.RawSegment(expectedSegment))
|
|
|
|
}
|
|
|
|
|
|
|
|
metabasetest.BeginMoveObject{
|
|
|
|
Opts: metabase.BeginMoveObject{
|
|
|
|
ObjectLocation: obj.Location(),
|
|
|
|
},
|
|
|
|
Result: metabase.BeginMoveObjectResult{
|
|
|
|
StreamID: expectedObject.StreamID,
|
|
|
|
Version: expectedVersion,
|
|
|
|
EncryptedKeysNonces: encKeyAndNonces,
|
|
|
|
EncryptionParameters: expectedObject.Encryption,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
}
|
2021-08-16 13:04:33 +01:00
|
|
|
|
|
|
|
metabasetest.Verify{
|
2022-08-08 16:14:08 +01:00
|
|
|
Objects: expectedRawObjects,
|
2021-08-16 13:04:33 +01:00
|
|
|
Segments: expectedRawSegments,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2021-08-31 12:44:18 +01:00
|
|
|
|
|
|
|
func TestFinishMoveObject(t *testing.T) {
|
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2021-09-22 08:50:24 +01:00
|
|
|
newBucketName := "New bucket name"
|
2021-08-31 12:44:18 +01:00
|
|
|
|
|
|
|
for _, test := range metabasetest.InvalidObjectStreams(obj) {
|
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
2021-09-22 08:50:24 +01:00
|
|
|
NewBucket: newBucketName,
|
2021-08-31 12:44:18 +01:00
|
|
|
ObjectStream: test.ObjectStream,
|
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-22 08:50:24 +01:00
|
|
|
t.Run("invalid NewBucket", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
ObjectStream: obj,
|
2023-10-17 17:00:03 +01:00
|
|
|
NewEncryptedObjectKey: metabase.ObjectKey("\x01\x02\x03"),
|
2021-09-22 08:50:24 +01:00
|
|
|
NewEncryptedMetadataKey: []byte{1, 2, 3},
|
2022-03-23 16:06:14 +00:00
|
|
|
NewEncryptedMetadataKeyNonce: testrand.Nonce(),
|
2021-09-22 08:50:24 +01:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "NewBucket is missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-08-31 12:44:18 +01:00
|
|
|
t.Run("invalid NewEncryptedObjectKey", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
2021-09-22 08:50:24 +01:00
|
|
|
NewBucket: newBucketName,
|
2021-08-31 12:44:18 +01:00
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "NewEncryptedObjectKey is missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2022-03-30 12:12:08 +01:00
|
|
|
t.Run("invalid EncryptedMetadataKeyNonce", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
2022-06-07 12:20:45 +01:00
|
|
|
numberOfSegments := 10
|
2023-10-17 17:00:03 +01:00
|
|
|
newObjectKey := metabasetest.RandObjectKey()
|
2022-06-07 12:20:45 +01:00
|
|
|
newEncryptedMetadataKey := testrand.Bytes(32)
|
|
|
|
|
|
|
|
newObj, segments := metabasetest.CreateTestObject{
|
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
OverrideEncryptedMetadata: true,
|
|
|
|
EncryptedMetadata: testrand.Bytes(64),
|
|
|
|
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
|
|
|
|
EncryptedMetadataEncryptedKey: testrand.Bytes(265),
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj, byte(numberOfSegments))
|
|
|
|
|
|
|
|
newEncryptedKeysNonces := make([]metabase.EncryptedKeyAndNonce, newObj.SegmentCount)
|
|
|
|
|
2022-03-30 12:12:08 +01:00
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
2022-06-07 12:20:45 +01:00
|
|
|
NewBucket: newBucketName,
|
|
|
|
ObjectStream: obj,
|
|
|
|
NewSegmentKeys: newEncryptedKeysNonces,
|
|
|
|
NewEncryptedObjectKey: newObjectKey,
|
|
|
|
NewEncryptedMetadataKeyNonce: storj.Nonce{},
|
|
|
|
NewEncryptedMetadataKey: newEncryptedMetadataKey,
|
2022-03-30 12:12:08 +01:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "EncryptedMetadataKeyNonce is missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2022-06-07 12:20:45 +01:00
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(newObj),
|
|
|
|
},
|
|
|
|
Segments: metabasetest.SegmentsToRaw(segments),
|
|
|
|
}.Check(ctx, t, db)
|
2022-03-30 12:12:08 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid EncryptedMetadataKey", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
2022-06-07 12:20:45 +01:00
|
|
|
numberOfSegments := 10
|
2023-10-17 17:00:03 +01:00
|
|
|
newObjectKey := metabasetest.RandObjectKey()
|
2022-06-07 12:20:45 +01:00
|
|
|
|
|
|
|
newObj, segments := metabasetest.CreateTestObject{
|
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
OverrideEncryptedMetadata: true,
|
|
|
|
EncryptedMetadata: testrand.Bytes(64),
|
|
|
|
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
|
|
|
|
EncryptedMetadataEncryptedKey: testrand.Bytes(265),
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj, byte(numberOfSegments))
|
|
|
|
|
|
|
|
newEncryptedKeysNonces := make([]metabase.EncryptedKeyAndNonce, newObj.SegmentCount)
|
|
|
|
newEncryptedMetadataKeyNonce := testrand.Nonce()
|
|
|
|
|
2022-03-30 12:12:08 +01:00
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
NewBucket: newBucketName,
|
|
|
|
ObjectStream: obj,
|
2022-06-07 12:20:45 +01:00
|
|
|
NewSegmentKeys: newEncryptedKeysNonces,
|
|
|
|
NewEncryptedObjectKey: newObjectKey,
|
|
|
|
NewEncryptedMetadataKeyNonce: newEncryptedMetadataKeyNonce,
|
|
|
|
NewEncryptedMetadataKey: nil,
|
2022-03-30 12:12:08 +01:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "EncryptedMetadataKey is missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2022-06-07 12:20:45 +01:00
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(newObj),
|
|
|
|
},
|
|
|
|
Segments: metabasetest.SegmentsToRaw(segments),
|
|
|
|
}.Check(ctx, t, db)
|
2022-03-30 12:12:08 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty EncryptedMetadataKey and EncryptedMetadataKeyNonce", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
NewBucket: newBucketName,
|
|
|
|
ObjectStream: obj,
|
2023-10-17 17:00:03 +01:00
|
|
|
NewEncryptedObjectKey: metabase.ObjectKey("\x00"),
|
2022-03-30 12:12:08 +01:00
|
|
|
},
|
|
|
|
// validation pass without EncryptedMetadataKey and EncryptedMetadataKeyNonce
|
2023-04-19 10:54:16 +01:00
|
|
|
ErrClass: &metabase.ErrObjectNotFound,
|
2022-03-30 12:12:08 +01:00
|
|
|
ErrText: "object not found",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
2021-08-31 12:44:18 +01:00
|
|
|
|
2023-10-17 17:00:03 +01:00
|
|
|
t.Run("existing object is overwritten", func(t *testing.T) {
|
2022-01-27 10:30:45 +00:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
moveObjStream := metabasetest.RandObjectStream()
|
2023-10-17 17:00:03 +01:00
|
|
|
initialObject := metabasetest.CreateObject(ctx, t, db, moveObjStream, 0)
|
2022-01-27 10:30:45 +00:00
|
|
|
|
|
|
|
conflictObjStream := metabasetest.RandObjectStream()
|
|
|
|
conflictObjStream.ProjectID = moveObjStream.ProjectID
|
|
|
|
metabasetest.CreateObject(ctx, t, db, conflictObjStream, 0)
|
|
|
|
|
2023-10-17 17:00:03 +01:00
|
|
|
newNonce := testrand.Nonce()
|
|
|
|
newMetadataKey := testrand.Bytes(265)
|
|
|
|
|
|
|
|
now := time.Now()
|
2022-01-27 10:30:45 +00:00
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
NewBucket: conflictObjStream.BucketName,
|
|
|
|
ObjectStream: moveObjStream,
|
2023-10-17 17:00:03 +01:00
|
|
|
NewEncryptedObjectKey: conflictObjStream.ObjectKey,
|
|
|
|
NewEncryptedMetadataKeyNonce: newNonce,
|
|
|
|
NewEncryptedMetadataKey: newMetadataKey,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: conflictObjStream.ProjectID,
|
|
|
|
BucketName: conflictObjStream.BucketName,
|
|
|
|
ObjectKey: conflictObjStream.ObjectKey,
|
|
|
|
StreamID: initialObject.StreamID,
|
|
|
|
Version: conflictObjStream.Version + 1,
|
|
|
|
},
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.CommittedUnversioned,
|
|
|
|
Encryption: initialObject.Encryption,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("existing object is not overwritten, permission denied", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
moveObjStream := metabasetest.RandObjectStream()
|
|
|
|
initialObject := metabasetest.CreateObject(ctx, t, db, moveObjStream, 0)
|
|
|
|
|
|
|
|
conflictObjStream := metabasetest.RandObjectStream()
|
|
|
|
conflictObjStream.ProjectID = moveObjStream.ProjectID
|
|
|
|
conflictObject := metabasetest.CreateObject(ctx, t, db, conflictObjStream, 0)
|
|
|
|
|
|
|
|
newNonce := testrand.Nonce()
|
|
|
|
newMetadataKey := testrand.Bytes(265)
|
|
|
|
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
NewBucket: conflictObjStream.BucketName,
|
|
|
|
ObjectStream: moveObjStream,
|
|
|
|
NewEncryptedObjectKey: conflictObjStream.ObjectKey,
|
|
|
|
NewEncryptedMetadataKeyNonce: newNonce,
|
|
|
|
NewEncryptedMetadataKey: newMetadataKey,
|
|
|
|
|
|
|
|
NewDisallowDelete: true,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrPermissionDenied,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(conflictObject),
|
|
|
|
metabase.RawObject(initialObject),
|
2022-01-27 10:30:45 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-08-31 12:44:18 +01:00
|
|
|
t.Run("object does not exist", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
newObj := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
newEncryptedMetadataKeyNonce := testrand.Nonce()
|
|
|
|
newEncryptedMetadataKey := testrand.Bytes(32)
|
|
|
|
newEncryptedKeysNonces := make([]metabase.EncryptedKeyAndNonce, 10)
|
2023-10-17 17:00:03 +01:00
|
|
|
newObjectKey := metabasetest.RandObjectKey()
|
2021-08-31 12:44:18 +01:00
|
|
|
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
2021-09-22 08:50:24 +01:00
|
|
|
NewBucket: newBucketName,
|
2021-08-31 12:44:18 +01:00
|
|
|
ObjectStream: newObj,
|
|
|
|
NewSegmentKeys: newEncryptedKeysNonces,
|
|
|
|
NewEncryptedObjectKey: newObjectKey,
|
2022-03-23 16:06:14 +00:00
|
|
|
NewEncryptedMetadataKeyNonce: newEncryptedMetadataKeyNonce,
|
2021-08-31 12:44:18 +01:00
|
|
|
NewEncryptedMetadataKey: newEncryptedMetadataKey,
|
|
|
|
},
|
2023-04-19 10:54:16 +01:00
|
|
|
ErrClass: &metabase.ErrObjectNotFound,
|
2021-08-31 12:44:18 +01:00
|
|
|
ErrText: "object not found",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2022-06-29 05:43:51 +01:00
|
|
|
t.Run("not enough segments", func(t *testing.T) {
|
2021-08-31 12:44:18 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
numberOfSegments := 10
|
2023-10-17 17:00:03 +01:00
|
|
|
newObjectKey := metabasetest.RandObjectKey()
|
2021-08-31 12:44:18 +01:00
|
|
|
|
2022-02-24 14:26:05 +00:00
|
|
|
newObj, _ := metabasetest.CreateTestObject{
|
2021-08-31 12:44:18 +01:00
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
2021-10-29 12:04:55 +01:00
|
|
|
EncryptedMetadata: testrand.Bytes(64),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
|
2021-08-31 12:44:18 +01:00
|
|
|
EncryptedMetadataEncryptedKey: testrand.Bytes(265),
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj, byte(numberOfSegments))
|
|
|
|
|
|
|
|
newEncryptedMetadataKeyNonce := testrand.Nonce()
|
|
|
|
newEncryptedMetadataKey := testrand.Bytes(32)
|
|
|
|
newEncryptedKeysNonces := make([]metabase.EncryptedKeyAndNonce, newObj.SegmentCount-1)
|
|
|
|
expectedEncryptedSize := 1060
|
|
|
|
expectedSegments := make([]metabase.RawSegment, newObj.SegmentCount)
|
|
|
|
|
|
|
|
for i := 0; i < int(newObj.SegmentCount-1); i++ {
|
|
|
|
newEncryptedKeysNonces[i] = metabase.EncryptedKeyAndNonce{
|
|
|
|
Position: metabase.SegmentPosition{Index: uint32(i)},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Nonce().Bytes(),
|
2021-08-31 12:44:18 +01:00
|
|
|
EncryptedKey: testrand.Bytes(32),
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedSegments[i] = metabasetest.DefaultRawSegment(newObj.ObjectStream, metabase.SegmentPosition{Index: uint32(i)})
|
|
|
|
expectedSegments[i].EncryptedKeyNonce = newEncryptedKeysNonces[i].EncryptedKeyNonce
|
|
|
|
expectedSegments[i].EncryptedKey = newEncryptedKeysNonces[i].EncryptedKey
|
|
|
|
expectedSegments[i].PlainOffset = int64(int32(i) * expectedSegments[i].PlainSize)
|
|
|
|
expectedSegments[i].EncryptedSize = int32(expectedEncryptedSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
2021-09-22 08:50:24 +01:00
|
|
|
NewBucket: newBucketName,
|
2021-08-31 12:44:18 +01:00
|
|
|
ObjectStream: obj,
|
|
|
|
NewSegmentKeys: newEncryptedKeysNonces,
|
|
|
|
NewEncryptedObjectKey: newObjectKey,
|
2022-03-23 16:06:14 +00:00
|
|
|
NewEncryptedMetadataKeyNonce: newEncryptedMetadataKeyNonce,
|
2021-08-31 12:44:18 +01:00
|
|
|
NewEncryptedMetadataKey: newEncryptedMetadataKey,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
2022-06-29 05:43:51 +01:00
|
|
|
ErrText: "wrong number of segments keys received",
|
2021-08-31 12:44:18 +01:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong segment indexes", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
numberOfSegments := 10
|
2023-10-17 17:00:03 +01:00
|
|
|
newObjectKey := metabasetest.RandObjectKey()
|
2021-08-31 12:44:18 +01:00
|
|
|
|
2022-02-24 14:26:05 +00:00
|
|
|
newObj, _ := metabasetest.CreateTestObject{
|
2021-08-31 12:44:18 +01:00
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
2021-10-29 12:04:55 +01:00
|
|
|
EncryptedMetadata: testrand.Bytes(64),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
|
2021-08-31 12:44:18 +01:00
|
|
|
EncryptedMetadataEncryptedKey: testrand.Bytes(265),
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj, byte(numberOfSegments))
|
|
|
|
|
|
|
|
newEncryptedMetadataKeyNonce := testrand.Nonce()
|
|
|
|
newEncryptedMetadataKey := testrand.Bytes(32)
|
|
|
|
newEncryptedKeysNonces := make([]metabase.EncryptedKeyAndNonce, newObj.SegmentCount)
|
|
|
|
expectedEncryptedSize := 1060
|
|
|
|
expectedSegments := make([]metabase.RawSegment, newObj.SegmentCount)
|
|
|
|
|
|
|
|
for i := 0; i < int(newObj.SegmentCount); i++ {
|
|
|
|
newEncryptedKeysNonces[i] = metabase.EncryptedKeyAndNonce{
|
|
|
|
Position: metabase.SegmentPosition{Index: uint32(i + 5)},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Nonce().Bytes(),
|
2021-08-31 12:44:18 +01:00
|
|
|
EncryptedKey: testrand.Bytes(32),
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedSegments[i] = metabasetest.DefaultRawSegment(newObj.ObjectStream, metabase.SegmentPosition{Index: uint32(i)})
|
|
|
|
expectedSegments[i].EncryptedKeyNonce = newEncryptedKeysNonces[i].EncryptedKeyNonce
|
|
|
|
expectedSegments[i].EncryptedKey = newEncryptedKeysNonces[i].EncryptedKey
|
|
|
|
expectedSegments[i].PlainOffset = int64(int32(i) * expectedSegments[i].PlainSize)
|
|
|
|
expectedSegments[i].EncryptedSize = int32(expectedEncryptedSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
2021-09-22 08:50:24 +01:00
|
|
|
NewBucket: newBucketName,
|
2021-08-31 12:44:18 +01:00
|
|
|
ObjectStream: obj,
|
|
|
|
NewSegmentKeys: newEncryptedKeysNonces,
|
|
|
|
NewEncryptedObjectKey: newObjectKey,
|
2022-03-23 16:06:14 +00:00
|
|
|
NewEncryptedMetadataKeyNonce: newEncryptedMetadataKeyNonce,
|
2021-08-31 12:44:18 +01:00
|
|
|
NewEncryptedMetadataKey: newEncryptedMetadataKey,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.Error,
|
|
|
|
ErrText: "segment is missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2022-06-29 05:43:51 +01:00
|
|
|
// Assert that an error occurs when a new object is put at the key (different stream_id)
|
|
|
|
// between BeginMoveObject and FinishMoveObject,
|
|
|
|
t.Run("source object changed", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
2023-10-17 17:00:03 +01:00
|
|
|
newObj, newSegments := metabasetest.CreateTestObject{
|
2022-06-29 05:43:51 +01:00
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
OverrideEncryptedMetadata: true,
|
|
|
|
EncryptedMetadata: testrand.Bytes(64),
|
|
|
|
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
|
|
|
|
EncryptedMetadataEncryptedKey: testrand.Bytes(265),
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj, 2)
|
|
|
|
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
NewBucket: newBucketName,
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: newObj.ProjectID,
|
|
|
|
BucketName: newObj.BucketName,
|
|
|
|
ObjectKey: newObj.ObjectKey,
|
|
|
|
Version: newObj.Version,
|
|
|
|
StreamID: testrand.UUID(),
|
|
|
|
},
|
|
|
|
NewSegmentKeys: []metabase.EncryptedKeyAndNonce{
|
|
|
|
metabasetest.RandEncryptedKeyAndNonce(0),
|
|
|
|
metabasetest.RandEncryptedKeyAndNonce(1),
|
|
|
|
},
|
2023-10-17 17:00:03 +01:00
|
|
|
NewEncryptedObjectKey: metabasetest.RandObjectKey(),
|
2022-06-29 05:43:51 +01:00
|
|
|
NewEncryptedMetadataKeyNonce: testrand.Nonce(),
|
|
|
|
NewEncryptedMetadataKey: testrand.Bytes(32),
|
|
|
|
},
|
2023-04-19 10:54:16 +01:00
|
|
|
ErrClass: &metabase.ErrObjectNotFound,
|
2022-06-29 05:43:51 +01:00
|
|
|
ErrText: "object was changed during move",
|
|
|
|
}.Check(ctx, t, db)
|
2023-10-17 17:00:03 +01:00
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{metabase.RawObject(newObj)},
|
|
|
|
Segments: metabasetest.SegmentsToRaw(newSegments),
|
|
|
|
}.Check(ctx, t, db)
|
2022-06-29 05:43:51 +01:00
|
|
|
})
|
|
|
|
|
2021-08-31 12:44:18 +01:00
|
|
|
t.Run("finish move object", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
2022-08-08 16:14:08 +01:00
|
|
|
expectedRawObjects := []metabase.RawObject{}
|
|
|
|
expectedRawSegments := []metabase.RawSegment{}
|
2021-10-12 14:37:12 +01:00
|
|
|
|
2022-08-08 16:14:08 +01:00
|
|
|
for _, expectedVersion := range []metabase.Version{1, 2, 3, 11} {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
obj.Version = expectedVersion
|
|
|
|
object, segments := metabasetest.CreateTestObject{
|
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj, 10)
|
2021-08-31 12:44:18 +01:00
|
|
|
|
2022-08-08 16:14:08 +01:00
|
|
|
newEncryptedKeysNonces := make([]metabase.EncryptedKeyAndNonce, object.SegmentCount)
|
2021-08-31 12:44:18 +01:00
|
|
|
|
2022-08-08 16:14:08 +01:00
|
|
|
for i, segment := range segments {
|
|
|
|
|
|
|
|
newEncryptedKeysNonces[i] = metabase.EncryptedKeyAndNonce{
|
|
|
|
Position: segment.Position,
|
|
|
|
EncryptedKeyNonce: testrand.Nonce().Bytes(),
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
|
|
|
}
|
|
|
|
|
|
|
|
segment.EncryptedKey = newEncryptedKeysNonces[i].EncryptedKey
|
|
|
|
segment.EncryptedKeyNonce = newEncryptedKeysNonces[i].EncryptedKeyNonce
|
|
|
|
expectedRawSegments = append(expectedRawSegments, metabase.RawSegment(segment))
|
2021-08-31 12:44:18 +01:00
|
|
|
}
|
|
|
|
|
2023-10-17 17:00:03 +01:00
|
|
|
newObjectKey := metabasetest.RandObjectKey()
|
2022-08-08 16:14:08 +01:00
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
NewBucket: newBucketName,
|
|
|
|
ObjectStream: obj,
|
|
|
|
NewSegmentKeys: newEncryptedKeysNonces,
|
|
|
|
NewEncryptedObjectKey: newObjectKey,
|
|
|
|
},
|
|
|
|
ErrText: "",
|
|
|
|
}.Check(ctx, t, db)
|
2021-08-31 12:44:18 +01:00
|
|
|
|
2023-10-17 17:00:03 +01:00
|
|
|
object.ObjectKey = newObjectKey
|
2022-08-08 16:14:08 +01:00
|
|
|
object.BucketName = newBucketName
|
2023-10-17 17:00:03 +01:00
|
|
|
object.Version = 1 // there are no overwritten object, hence it should start from 1
|
2021-08-31 12:44:18 +01:00
|
|
|
|
2022-08-08 16:14:08 +01:00
|
|
|
expectedRawObjects = append(expectedRawObjects, metabase.RawObject(object))
|
|
|
|
}
|
2021-08-31 12:44:18 +01:00
|
|
|
|
|
|
|
metabasetest.Verify{
|
2022-08-08 16:14:08 +01:00
|
|
|
Objects: expectedRawObjects,
|
|
|
|
Segments: expectedRawSegments,
|
2021-08-31 12:44:18 +01:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2022-06-07 12:20:45 +01:00
|
|
|
|
|
|
|
t.Run("finish move object with empty metadata, key, nonce object", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
numberOfSegments := 10
|
2023-10-17 17:00:03 +01:00
|
|
|
newObjectKey := metabasetest.RandObjectKey()
|
2022-06-07 12:20:45 +01:00
|
|
|
|
|
|
|
newObj, _ := metabasetest.CreateTestObject{
|
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
OverrideEncryptedMetadata: true,
|
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj, byte(numberOfSegments))
|
|
|
|
|
|
|
|
newEncryptedMetadataKeyNonce := testrand.Nonce()
|
|
|
|
newEncryptedMetadataKey := testrand.Bytes(32)
|
|
|
|
newEncryptedKeysNonces := make([]metabase.EncryptedKeyAndNonce, newObj.SegmentCount)
|
|
|
|
expectedEncryptedSize := 1060
|
|
|
|
expectedSegments := make([]metabase.RawSegment, newObj.SegmentCount)
|
|
|
|
|
|
|
|
for i := 0; i < int(newObj.SegmentCount); i++ {
|
|
|
|
newEncryptedKeysNonces[i] = metabase.EncryptedKeyAndNonce{
|
|
|
|
Position: metabase.SegmentPosition{Index: uint32(i)},
|
|
|
|
EncryptedKeyNonce: nil,
|
|
|
|
EncryptedKey: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedSegments[i] = metabasetest.DefaultRawSegment(newObj.ObjectStream, metabase.SegmentPosition{Index: uint32(i)})
|
|
|
|
expectedSegments[i].EncryptedKeyNonce = nil
|
|
|
|
expectedSegments[i].EncryptedKey = nil
|
|
|
|
expectedSegments[i].PlainOffset = int64(int32(i) * expectedSegments[i].PlainSize)
|
|
|
|
expectedSegments[i].EncryptedSize = int32(expectedEncryptedSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
NewBucket: newBucketName,
|
|
|
|
ObjectStream: obj,
|
|
|
|
NewSegmentKeys: newEncryptedKeysNonces,
|
|
|
|
NewEncryptedObjectKey: newObjectKey,
|
|
|
|
NewEncryptedMetadataKeyNonce: newEncryptedMetadataKeyNonce,
|
|
|
|
NewEncryptedMetadataKey: newEncryptedMetadataKey,
|
|
|
|
},
|
|
|
|
ErrText: "",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2023-10-17 17:00:03 +01:00
|
|
|
newObj.ObjectKey = newObjectKey
|
2022-06-07 12:20:45 +01:00
|
|
|
newObj.BucketName = newBucketName
|
2023-10-17 17:00:03 +01:00
|
|
|
newObj.Version = 1
|
2022-06-07 12:20:45 +01:00
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(newObj),
|
|
|
|
},
|
|
|
|
Segments: expectedSegments,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2022-12-13 11:31:29 +00:00
|
|
|
|
2023-10-17 17:00:03 +01:00
|
|
|
t.Run("finish move object - different versions reject when NewDisallowDelete", func(t *testing.T) {
|
2022-12-13 11:31:29 +00:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
committedTargetStreams := []metabase.ObjectStream{}
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
for _, version := range []metabase.Version{1, 2} {
|
|
|
|
obj.Version = version
|
|
|
|
object, _ := metabasetest.CreateTestObject{}.Run(ctx, t, db, obj, 1)
|
|
|
|
committedTargetStreams = append(committedTargetStreams, object.ObjectStream)
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceStream := metabasetest.RandObjectStream()
|
|
|
|
sourceStream.ProjectID = obj.ProjectID
|
|
|
|
_, _ = metabasetest.CreateTestObject{}.Run(ctx, t, db, sourceStream, 1)
|
|
|
|
|
|
|
|
// it's not possible to move if under location were we have committed version
|
|
|
|
for _, targetStream := range committedTargetStreams {
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
ObjectStream: sourceStream,
|
|
|
|
NewBucket: targetStream.BucketName,
|
2023-10-17 17:00:03 +01:00
|
|
|
NewEncryptedObjectKey: targetStream.ObjectKey,
|
|
|
|
|
|
|
|
NewDisallowDelete: true,
|
2022-12-13 11:31:29 +00:00
|
|
|
},
|
2023-10-17 17:00:03 +01:00
|
|
|
ErrClass: &metabase.ErrPermissionDenied,
|
2022-12-13 11:31:29 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("finish move object - target pending object", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
metabasetest.CreatePendingObject(ctx, t, db, obj, 1)
|
|
|
|
|
|
|
|
sourceStream := metabasetest.RandObjectStream()
|
|
|
|
sourceStream.ProjectID = obj.ProjectID
|
|
|
|
_, _ = metabasetest.CreateTestObject{}.Run(ctx, t, db, sourceStream, 0)
|
|
|
|
|
|
|
|
// it's possible to move if under location were we have only pending version
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
ObjectStream: sourceStream,
|
|
|
|
NewBucket: obj.BucketName,
|
2023-10-17 17:00:03 +01:00
|
|
|
NewEncryptedObjectKey: obj.ObjectKey,
|
2022-12-13 11:31:29 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2023-11-01 22:21:14 +00:00
|
|
|
|
|
|
|
t.Run("versioned targets unversioned and versioned", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
obj.Version = 12000
|
|
|
|
unversionedObject := metabasetest.CreateObject(ctx, t, db, obj, 0)
|
|
|
|
obj.Version = 13000
|
|
|
|
versionedObject := metabasetest.CreateObjectVersioned(ctx, t, db, obj, 0)
|
|
|
|
|
|
|
|
sourceStream := metabasetest.RandObjectStream()
|
|
|
|
sourceStream.ProjectID = obj.ProjectID
|
|
|
|
sourceObject := metabasetest.CreateObject(ctx, t, db, sourceStream, 0)
|
|
|
|
|
|
|
|
movedObject := sourceObject
|
|
|
|
movedObject.ObjectStream.ProjectID = obj.ProjectID
|
|
|
|
movedObject.ObjectStream.BucketName = obj.BucketName
|
|
|
|
movedObject.ObjectStream.ObjectKey = obj.ObjectKey
|
|
|
|
movedObject.ObjectStream.Version = 13001
|
|
|
|
movedObject.Status = metabase.CommittedVersioned
|
|
|
|
|
|
|
|
// versioned copy should leave everything else as is
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
ObjectStream: sourceStream,
|
|
|
|
NewBucket: obj.BucketName,
|
|
|
|
NewEncryptedObjectKey: obj.ObjectKey,
|
|
|
|
|
|
|
|
NewVersioned: true,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(unversionedObject),
|
|
|
|
metabase.RawObject(versionedObject),
|
|
|
|
metabase.RawObject(movedObject),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("unversioned targets unversioned and versioned", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
obj.Version = 12000
|
|
|
|
metabasetest.CreateObject(ctx, t, db, obj, 0)
|
|
|
|
obj.Version = 13000
|
|
|
|
versionedObject := metabasetest.CreateObjectVersioned(ctx, t, db, obj, 0)
|
|
|
|
|
|
|
|
sourceStream := metabasetest.RandObjectStream()
|
|
|
|
sourceStream.ProjectID = obj.ProjectID
|
|
|
|
sourceObject := metabasetest.CreateObject(ctx, t, db, sourceStream, 0)
|
|
|
|
|
|
|
|
movedObject := sourceObject
|
|
|
|
movedObject.ObjectStream.ProjectID = obj.ProjectID
|
|
|
|
movedObject.ObjectStream.BucketName = obj.BucketName
|
|
|
|
movedObject.ObjectStream.ObjectKey = obj.ObjectKey
|
|
|
|
movedObject.ObjectStream.Version = 13001
|
|
|
|
movedObject.Status = metabase.CommittedUnversioned
|
|
|
|
|
|
|
|
// unversioned copy should only delete the unversioned object
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
ObjectStream: sourceStream,
|
|
|
|
NewBucket: obj.BucketName,
|
|
|
|
NewEncryptedObjectKey: obj.ObjectKey,
|
|
|
|
NewVersioned: false,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(versionedObject),
|
|
|
|
metabase.RawObject(movedObject),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("unversioned delete marker targets unversioned and versioned", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
obj.Version = 12000
|
|
|
|
_ = metabasetest.CreateObject(ctx, t, db, obj, 0)
|
|
|
|
obj.Version = 13000
|
|
|
|
versionedObject := metabasetest.CreateObjectVersioned(ctx, t, db, obj, 0)
|
|
|
|
|
|
|
|
sourceStream := metabasetest.RandObjectStream()
|
|
|
|
sourceStream.ProjectID = obj.ProjectID
|
|
|
|
sourceObject := metabasetest.CreateObject(ctx, t, db, sourceStream, 0)
|
|
|
|
|
|
|
|
deletionResult := metabasetest.DeleteObjectLastCommitted{
|
|
|
|
Opts: metabase.DeleteObjectLastCommitted{
|
|
|
|
ObjectLocation: sourceObject.Location(),
|
|
|
|
Suspended: true,
|
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Removed: []metabase.Object{sourceObject},
|
|
|
|
Markers: []metabase.Object{
|
|
|
|
{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: sourceObject.ProjectID,
|
|
|
|
BucketName: sourceObject.BucketName,
|
|
|
|
ObjectKey: sourceObject.ObjectKey,
|
|
|
|
StreamID: sourceStream.StreamID,
|
|
|
|
Version: 12346,
|
|
|
|
},
|
|
|
|
Status: metabase.DeleteMarkerUnversioned,
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
movedObject := deletionResult.Markers[0]
|
|
|
|
movedObject.ObjectStream.ProjectID = obj.ProjectID
|
|
|
|
movedObject.ObjectStream.BucketName = obj.BucketName
|
|
|
|
movedObject.ObjectStream.ObjectKey = obj.ObjectKey
|
|
|
|
movedObject.ObjectStream.Version = 13001
|
|
|
|
movedObject.Status = metabase.CommittedUnversioned
|
|
|
|
|
|
|
|
// move of delete marker should fail
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
ObjectStream: deletionResult.Markers[0].ObjectStream,
|
|
|
|
NewBucket: obj.BucketName,
|
|
|
|
NewEncryptedObjectKey: obj.ObjectKey,
|
|
|
|
|
|
|
|
NewVersioned: false,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(versionedObject),
|
|
|
|
metabase.RawObject(movedObject),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("versioned delete marker targets unversioned and versioned", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
obj.Version = 12000
|
|
|
|
unversionedObject := metabasetest.CreateObject(ctx, t, db, obj, 0)
|
|
|
|
obj.Version = 13000
|
|
|
|
versionedObject := metabasetest.CreateObjectVersioned(ctx, t, db, obj, 0)
|
|
|
|
|
|
|
|
sourceStream := metabasetest.RandObjectStream()
|
|
|
|
sourceStream.ProjectID = obj.ProjectID
|
|
|
|
sourceStream.Version = 13001
|
|
|
|
sourceObject := metabasetest.CreateObjectVersioned(ctx, t, db, sourceStream, 0)
|
|
|
|
|
|
|
|
deletionResult := metabasetest.DeleteObjectLastCommitted{
|
|
|
|
Opts: metabase.DeleteObjectLastCommitted{
|
|
|
|
ObjectLocation: sourceObject.Location(),
|
|
|
|
Versioned: true,
|
|
|
|
},
|
|
|
|
Result: metabase.DeleteObjectResult{
|
|
|
|
Markers: []metabase.Object{
|
|
|
|
{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: sourceObject.ProjectID,
|
|
|
|
BucketName: sourceObject.BucketName,
|
|
|
|
ObjectKey: sourceObject.ObjectKey,
|
|
|
|
StreamID: sourceStream.StreamID,
|
|
|
|
Version: 13002,
|
|
|
|
},
|
|
|
|
Status: metabase.DeleteMarkerVersioned,
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
movedObject := deletionResult.Markers[0]
|
|
|
|
movedObject.ObjectStream.ProjectID = obj.ProjectID
|
|
|
|
movedObject.ObjectStream.BucketName = obj.BucketName
|
|
|
|
movedObject.ObjectStream.ObjectKey = obj.ObjectKey
|
|
|
|
movedObject.ObjectStream.Version = 13001
|
|
|
|
movedObject.Status = metabase.CommittedVersioned
|
|
|
|
|
|
|
|
// copy of delete marker should fail
|
|
|
|
metabasetest.FinishMoveObject{
|
|
|
|
Opts: metabase.FinishMoveObject{
|
|
|
|
ObjectStream: deletionResult.Markers[0].ObjectStream,
|
|
|
|
NewBucket: obj.BucketName,
|
|
|
|
NewEncryptedObjectKey: obj.ObjectKey,
|
|
|
|
|
|
|
|
NewVersioned: true,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(movedObject),
|
|
|
|
metabase.RawObject(sourceObject),
|
|
|
|
metabase.RawObject(unversionedObject),
|
|
|
|
metabase.RawObject(versionedObject),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2021-08-31 12:44:18 +01:00
|
|
|
})
|
|
|
|
}
|