2020-10-28 15:28:06 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metabase_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-02-24 10:54:57 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
2022-01-26 00:25:44 +00:00
|
|
|
"storj.io/common/testrand"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2021-04-26 10:35:44 +01:00
|
|
|
"storj.io/storj/satellite/metabase/metabasetest"
|
2020-10-28 15:28:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetObjectExactVersion(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
location := obj.Location()
|
|
|
|
|
|
|
|
now := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectLocations(location) {
|
2020-10-28 15:28:06 +00:00
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.GetObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectExactVersion{
|
|
|
|
ObjectLocation: test.ObjectLocation,
|
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Version invalid", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 0,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "Version invalid: 0",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Object missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 1,
|
|
|
|
},
|
2020-11-02 10:51:36 +00:00
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: sql: no rows in result set",
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get not existing version", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateObject(ctx, t, db, obj, 0)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 11,
|
|
|
|
},
|
2020-11-02 10:51:36 +00:00
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: sql: no rows in result set",
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-10-28 15:28:06 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get pending object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2020-10-29 13:49:53 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 1,
|
|
|
|
},
|
2020-11-02 10:51:36 +00:00
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: sql: no rows in result set",
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-10-28 15:28:06 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
2020-10-29 13:49:53 +00:00
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateObject(ctx, t, db, obj, 0)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 1,
|
|
|
|
},
|
|
|
|
Result: metabase.Object{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: []metabase.RawObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetSegmentByPosition(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
t.Run("StreamID missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByPosition{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetSegmentByPosition{},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "StreamID missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Segment missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByPosition{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetSegmentByPosition{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
2020-12-15 12:49:58 +00:00
|
|
|
ErrClass: &metabase.ErrSegmentNotFound,
|
2020-10-28 15:28:06 +00:00
|
|
|
ErrText: "segment missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get segment", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-06-11 16:47:42 +01:00
|
|
|
obj1 := metabasetest.CreateObject(ctx, t, db, metabasetest.RandObjectStream(), 1)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-06-11 16:47:42 +01:00
|
|
|
expectedExpiresAt := now.Add(5 * time.Hour)
|
|
|
|
obj2 := metabasetest.CreateExpiredObject(ctx, t, db, metabasetest.RandObjectStream(), 1, expectedExpiresAt)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-06-11 16:47:42 +01:00
|
|
|
segments := make([]metabase.Segment, 0, 2)
|
|
|
|
for _, obj := range []metabase.Object{obj1, obj2} {
|
|
|
|
expectedSegment := metabase.Segment{
|
2020-10-28 15:28:06 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
2021-01-25 11:23:43 +00:00
|
|
|
Index: 0,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: obj.CreatedAt,
|
2021-06-11 16:47:42 +01:00
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
EncryptedKey: []byte{3},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-06-11 16:47:42 +01:00
|
|
|
EncryptedETag: []byte{5},
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
}
|
|
|
|
|
|
|
|
metabasetest.GetSegmentByPosition{
|
|
|
|
Opts: metabase.GetSegmentByPosition{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Result: expectedSegment,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
segments = append(segments, expectedSegment)
|
|
|
|
}
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
// check non existing segment in existing object
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByPosition{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetSegmentByPosition{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
2021-01-25 11:23:43 +00:00
|
|
|
Index: 1,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
},
|
2020-12-15 12:49:58 +00:00
|
|
|
ErrClass: &metabase.ErrSegmentNotFound,
|
2020-10-28 15:28:06 +00:00
|
|
|
ErrText: "segment missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-10-28 15:28:06 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
2021-06-11 16:47:42 +01:00
|
|
|
ObjectStream: obj1.ObjectStream,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
TotalPlainSize: 512,
|
|
|
|
TotalEncryptedSize: 1024,
|
|
|
|
FixedSegmentSize: 512,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: obj2.ObjectStream,
|
2020-10-28 15:28:06 +00:00
|
|
|
CreatedAt: now,
|
2021-06-11 16:47:42 +01:00
|
|
|
ExpiresAt: obj2.ExpiresAt,
|
2020-10-28 15:28:06 +00:00
|
|
|
Status: metabase.Committed,
|
2020-11-03 14:45:39 +00:00
|
|
|
SegmentCount: 1,
|
|
|
|
|
2020-11-24 12:29:16 +00:00
|
|
|
TotalPlainSize: 512,
|
2020-11-03 14:45:39 +00:00
|
|
|
TotalEncryptedSize: 1024,
|
2021-01-14 11:47:29 +00:00
|
|
|
FixedSegmentSize: 512,
|
2020-11-03 14:45:39 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
2021-06-11 16:47:42 +01:00
|
|
|
metabase.RawSegment(segments[0]),
|
|
|
|
metabase.RawSegment(segments[1]),
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2022-01-26 00:25:44 +00:00
|
|
|
|
|
|
|
t.Run("Get segment copy", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
objStream := metabasetest.RandObjectStream()
|
|
|
|
copyObjStream := metabasetest.RandObjectStream()
|
|
|
|
copyObjStream.ProjectID = objStream.ProjectID
|
|
|
|
|
|
|
|
obj := metabasetest.CreateObject(ctx, t, db, objStream, 1)
|
|
|
|
|
|
|
|
encryptedKeyNonces := []metabase.EncryptedKeyAndNonce{{
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
newEncryptedKeyNonces := []metabase.EncryptedKeyAndNonce{{
|
|
|
|
EncryptedKeyNonce: []byte{3},
|
|
|
|
EncryptedKey: []byte{4},
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
metabasetest.BeginCopyObject{
|
|
|
|
Opts: metabase.BeginCopyObject{
|
|
|
|
Version: obj.Version,
|
|
|
|
ObjectLocation: obj.Location(),
|
|
|
|
},
|
|
|
|
Result: metabase.BeginCopyObjectResult{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
EncryptedMetadata: obj.EncryptedMetadata,
|
|
|
|
EncryptedMetadataKey: obj.EncryptedMetadataEncryptedKey,
|
|
|
|
EncryptedMetadataKeyNonce: obj.EncryptedMetadataNonce,
|
|
|
|
EncryptedKeysNonces: encryptedKeyNonces,
|
|
|
|
EncryptionParameters: obj.Encryption,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
newEncryptedMetadataKeyNonce := testrand.Nonce()
|
|
|
|
newEncryptedMetadataKey := testrand.Bytes(32)
|
|
|
|
|
2022-02-24 10:54:57 +00:00
|
|
|
_, err := db.FinishCopyObject(ctx, metabase.FinishCopyObject{
|
|
|
|
NewStreamID: copyObjStream.StreamID,
|
|
|
|
NewBucket: copyObjStream.BucketName,
|
|
|
|
ObjectStream: obj.ObjectStream,
|
|
|
|
NewSegmentKeys: newEncryptedKeyNonces,
|
2022-03-04 11:28:04 +00:00
|
|
|
NewEncryptedObjectKey: copyObjStream.ObjectKey,
|
2022-03-23 16:06:14 +00:00
|
|
|
NewEncryptedMetadataKeyNonce: newEncryptedMetadataKeyNonce,
|
2022-02-24 10:54:57 +00:00
|
|
|
NewEncryptedMetadataKey: newEncryptedMetadataKey,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2022-01-26 00:25:44 +00:00
|
|
|
|
|
|
|
expectedSegment := metabase.Segment{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
CreatedAt: obj.CreatedAt,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
EncryptedETag: []byte{5},
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedCopiedSegmentRaw := metabase.Segment{
|
|
|
|
StreamID: copyObjStream.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
CreatedAt: obj.CreatedAt,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
|
|
|
|
Pieces: metabase.Pieces{},
|
|
|
|
|
|
|
|
EncryptedKey: newEncryptedKeyNonces[0].EncryptedKey,
|
|
|
|
EncryptedKeyNonce: newEncryptedKeyNonces[0].EncryptedKeyNonce,
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2022-02-16 23:24:38 +00:00
|
|
|
InlineData: []byte{},
|
2022-01-26 00:25:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedCopiedSegmentGet := expectedSegment
|
|
|
|
|
|
|
|
expectedCopiedSegmentGet.EncryptedETag = nil
|
|
|
|
expectedCopiedSegmentGet.StreamID = copyObjStream.StreamID
|
|
|
|
expectedCopiedSegmentGet.EncryptedKey = newEncryptedKeyNonces[0].EncryptedKey
|
|
|
|
expectedCopiedSegmentGet.EncryptedKeyNonce = newEncryptedKeyNonces[0].EncryptedKeyNonce
|
2022-02-16 23:24:38 +00:00
|
|
|
expectedCopiedSegmentGet.InlineData = []byte{}
|
2022-01-26 00:25:44 +00:00
|
|
|
|
|
|
|
metabasetest.GetSegmentByPosition{
|
|
|
|
Opts: metabase.GetSegmentByPosition{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Result: expectedSegment,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.GetSegmentByPosition{
|
|
|
|
Opts: metabase.GetSegmentByPosition{
|
|
|
|
StreamID: copyObjStream.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Result: expectedCopiedSegmentGet,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj.ObjectStream,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
TotalPlainSize: 512,
|
|
|
|
TotalEncryptedSize: 1024,
|
|
|
|
FixedSegmentSize: 512,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: copyObjStream,
|
|
|
|
CreatedAt: now,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
TotalPlainSize: 512,
|
|
|
|
TotalEncryptedSize: 1024,
|
|
|
|
FixedSegmentSize: 512,
|
|
|
|
|
|
|
|
EncryptedMetadataNonce: newEncryptedMetadataKeyNonce[:],
|
|
|
|
EncryptedMetadataEncryptedKey: newEncryptedMetadataKey,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(expectedSegment),
|
|
|
|
metabase.RawSegment(expectedCopiedSegmentRaw),
|
|
|
|
},
|
|
|
|
Copies: []metabase.RawCopy{
|
|
|
|
{
|
|
|
|
StreamID: copyObjStream.StreamID,
|
|
|
|
AncestorStreamID: objStream.StreamID,
|
|
|
|
}},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get empty inline segment copy", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
objStream := metabasetest.RandObjectStream()
|
|
|
|
copyObjStream := metabasetest.RandObjectStream()
|
|
|
|
copyObjStream.ProjectID = objStream.ProjectID
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitInlineSegment{
|
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: uint32(0)},
|
|
|
|
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
|
|
|
|
PlainSize: 0,
|
|
|
|
PlainOffset: 0,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj := metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
encryptedKeyNonces := []metabase.EncryptedKeyAndNonce{{
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
newEncryptedKeyNonces := []metabase.EncryptedKeyAndNonce{{
|
|
|
|
EncryptedKeyNonce: []byte{3},
|
|
|
|
EncryptedKey: []byte{4},
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
metabasetest.BeginCopyObject{
|
|
|
|
Opts: metabase.BeginCopyObject{
|
|
|
|
Version: obj.Version,
|
|
|
|
ObjectLocation: obj.Location(),
|
|
|
|
},
|
|
|
|
Result: metabase.BeginCopyObjectResult{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
EncryptedMetadata: obj.EncryptedMetadata,
|
|
|
|
EncryptedMetadataKey: obj.EncryptedMetadataEncryptedKey,
|
|
|
|
EncryptedMetadataKeyNonce: obj.EncryptedMetadataNonce,
|
|
|
|
EncryptedKeysNonces: encryptedKeyNonces,
|
|
|
|
EncryptionParameters: obj.Encryption,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
newEncryptedMetadataKeyNonce := testrand.Nonce()
|
|
|
|
newEncryptedMetadataKey := testrand.Bytes(32)
|
|
|
|
|
2022-02-24 10:54:57 +00:00
|
|
|
_, err := db.FinishCopyObject(ctx, metabase.FinishCopyObject{
|
|
|
|
ObjectStream: obj.ObjectStream,
|
|
|
|
NewStreamID: copyObjStream.StreamID,
|
|
|
|
NewBucket: copyObjStream.BucketName,
|
|
|
|
NewSegmentKeys: newEncryptedKeyNonces,
|
2022-03-04 11:28:04 +00:00
|
|
|
NewEncryptedObjectKey: copyObjStream.ObjectKey,
|
2022-03-23 16:06:14 +00:00
|
|
|
NewEncryptedMetadataKeyNonce: newEncryptedMetadataKeyNonce,
|
2022-02-24 10:54:57 +00:00
|
|
|
NewEncryptedMetadataKey: newEncryptedMetadataKey,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2022-01-26 00:25:44 +00:00
|
|
|
|
|
|
|
expectedSegment := metabase.Segment{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
CreatedAt: obj.CreatedAt,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
EncryptedSize: 0,
|
|
|
|
PlainSize: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedCopiedSegmentRaw := metabase.Segment{
|
|
|
|
StreamID: copyObjStream.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
CreatedAt: obj.CreatedAt,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
|
|
|
|
Pieces: metabase.Pieces{},
|
|
|
|
|
|
|
|
EncryptedKey: newEncryptedKeyNonces[0].EncryptedKey,
|
|
|
|
EncryptedKeyNonce: newEncryptedKeyNonces[0].EncryptedKeyNonce,
|
2022-02-16 23:24:38 +00:00
|
|
|
InlineData: []byte{},
|
2022-01-26 00:25:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedCopiedSegmentGet := expectedSegment
|
|
|
|
expectedCopiedSegmentGet.StreamID = copyObjStream.StreamID
|
|
|
|
|
|
|
|
expectedCopiedSegmentGet.EncryptedKey = newEncryptedKeyNonces[0].EncryptedKey
|
|
|
|
expectedCopiedSegmentGet.EncryptedKeyNonce = newEncryptedKeyNonces[0].EncryptedKeyNonce
|
2022-02-16 23:24:38 +00:00
|
|
|
expectedCopiedSegmentGet.InlineData = []byte{}
|
2022-01-26 00:25:44 +00:00
|
|
|
|
|
|
|
metabasetest.GetSegmentByPosition{
|
|
|
|
Opts: metabase.GetSegmentByPosition{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Result: expectedSegment,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.GetSegmentByPosition{
|
|
|
|
Opts: metabase.GetSegmentByPosition{
|
|
|
|
StreamID: copyObjStream.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Result: expectedCopiedSegmentGet,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj.ObjectStream,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: copyObjStream,
|
|
|
|
CreatedAt: now,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
EncryptedMetadataNonce: newEncryptedMetadataKeyNonce[:],
|
|
|
|
EncryptedMetadataEncryptedKey: newEncryptedMetadataKey,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(expectedSegment),
|
|
|
|
metabase.RawSegment(expectedCopiedSegmentRaw),
|
|
|
|
},
|
2022-02-24 00:17:35 +00:00
|
|
|
Copies: nil,
|
2022-01-26 00:25:44 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get inline segment copy", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
objStream := metabasetest.RandObjectStream()
|
|
|
|
copyObjStream := metabasetest.RandObjectStream()
|
|
|
|
data := testrand.Bytes(1024)
|
|
|
|
copyObjStream.ProjectID = objStream.ProjectID
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitInlineSegment{
|
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: uint32(0)},
|
|
|
|
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
|
|
|
|
PlainSize: 0,
|
|
|
|
PlainOffset: 0,
|
|
|
|
|
|
|
|
InlineData: data,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj := metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
encryptedKeyNonces := []metabase.EncryptedKeyAndNonce{{
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
newEncryptedKeyNonces := []metabase.EncryptedKeyAndNonce{{
|
|
|
|
EncryptedKeyNonce: []byte{3},
|
|
|
|
EncryptedKey: []byte{4},
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
metabasetest.BeginCopyObject{
|
|
|
|
Opts: metabase.BeginCopyObject{
|
|
|
|
Version: obj.Version,
|
|
|
|
ObjectLocation: obj.Location(),
|
|
|
|
},
|
|
|
|
Result: metabase.BeginCopyObjectResult{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
EncryptedMetadata: obj.EncryptedMetadata,
|
|
|
|
EncryptedMetadataKey: obj.EncryptedMetadataEncryptedKey,
|
|
|
|
EncryptedMetadataKeyNonce: obj.EncryptedMetadataNonce,
|
|
|
|
EncryptedKeysNonces: encryptedKeyNonces,
|
|
|
|
EncryptionParameters: obj.Encryption,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
newEncryptedMetadataKeyNonce := testrand.Nonce()
|
|
|
|
newEncryptedMetadataKey := testrand.Bytes(32)
|
|
|
|
|
2022-02-24 10:54:57 +00:00
|
|
|
_, err := db.FinishCopyObject(ctx, metabase.FinishCopyObject{
|
|
|
|
ObjectStream: obj.ObjectStream,
|
|
|
|
NewStreamID: copyObjStream.StreamID,
|
|
|
|
NewBucket: copyObjStream.BucketName,
|
|
|
|
NewSegmentKeys: newEncryptedKeyNonces,
|
2022-03-04 11:28:04 +00:00
|
|
|
NewEncryptedObjectKey: copyObjStream.ObjectKey,
|
2022-03-23 16:06:14 +00:00
|
|
|
NewEncryptedMetadataKeyNonce: newEncryptedMetadataKeyNonce,
|
2022-02-24 10:54:57 +00:00
|
|
|
NewEncryptedMetadataKey: newEncryptedMetadataKey,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2022-01-26 00:25:44 +00:00
|
|
|
|
|
|
|
expectedSegment := metabase.Segment{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
CreatedAt: obj.CreatedAt,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 0,
|
|
|
|
|
|
|
|
InlineData: data,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedCopiedSegmentRaw := metabase.Segment{
|
|
|
|
StreamID: copyObjStream.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
CreatedAt: obj.CreatedAt,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
|
|
|
|
Pieces: metabase.Pieces{},
|
|
|
|
|
|
|
|
EncryptedKey: newEncryptedKeyNonces[0].EncryptedKey,
|
|
|
|
EncryptedKeyNonce: newEncryptedKeyNonces[0].EncryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
|
|
|
|
InlineData: data,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedCopiedSegmentGet := expectedSegment
|
|
|
|
expectedCopiedSegmentGet.StreamID = copyObjStream.StreamID
|
|
|
|
|
|
|
|
expectedCopiedSegmentGet.EncryptedKey = newEncryptedKeyNonces[0].EncryptedKey
|
|
|
|
expectedCopiedSegmentGet.EncryptedKeyNonce = newEncryptedKeyNonces[0].EncryptedKeyNonce
|
|
|
|
|
|
|
|
metabasetest.GetSegmentByPosition{
|
|
|
|
Opts: metabase.GetSegmentByPosition{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Result: expectedSegment,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.GetSegmentByPosition{
|
|
|
|
Opts: metabase.GetSegmentByPosition{
|
|
|
|
StreamID: copyObjStream.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Result: expectedCopiedSegmentGet,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj.ObjectStream,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
TotalEncryptedSize: 1024,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: copyObjStream,
|
|
|
|
CreatedAt: now,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
EncryptedMetadataNonce: newEncryptedMetadataKeyNonce[:],
|
|
|
|
EncryptedMetadataEncryptedKey: newEncryptedMetadataKey,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
TotalEncryptedSize: 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(expectedSegment),
|
|
|
|
metabase.RawSegment(expectedCopiedSegmentRaw),
|
|
|
|
},
|
2022-02-24 00:17:35 +00:00
|
|
|
Copies: nil,
|
2022-01-26 00:25:44 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
}
|
2020-11-03 15:03:20 +00:00
|
|
|
|
|
|
|
func TestGetLatestObjectLastSegment(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-11-03 15:03:20 +00:00
|
|
|
location := obj.Location()
|
|
|
|
now := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectLocations(location) {
|
2020-11-03 15:03:20 +00:00
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.GetLatestObjectLastSegment{
|
2020-11-03 15:03:20 +00:00
|
|
|
Opts: metabase.GetLatestObjectLastSegment{
|
|
|
|
ObjectLocation: test.ObjectLocation,
|
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:03:20 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Object or segment missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:03:20 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetLatestObjectLastSegment{
|
2020-11-03 15:03:20 +00:00
|
|
|
Opts: metabase.GetLatestObjectLastSegment{
|
|
|
|
ObjectLocation: location,
|
|
|
|
},
|
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: object or segment missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:03:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get last segment", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:03:20 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateObject(ctx, t, db, obj, 2)
|
2020-11-03 15:03:20 +00:00
|
|
|
|
|
|
|
expectedSegmentSecond := metabase.Segment{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
2021-01-25 11:23:43 +00:00
|
|
|
Index: 1,
|
2020-11-03 15:03:20 +00:00
|
|
|
},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2020-11-03 15:03:20 +00:00
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
EncryptedKey: []byte{3},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-03-25 07:53:10 +00:00
|
|
|
EncryptedETag: []byte{5},
|
2020-11-03 15:03:20 +00:00
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
2021-03-30 10:44:43 +01:00
|
|
|
PlainOffset: 512,
|
2020-11-03 15:03:20 +00:00
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2020-11-03 15:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedSegmentFirst := expectedSegmentSecond
|
2021-01-25 11:23:43 +00:00
|
|
|
expectedSegmentFirst.Position.Index = 0
|
2021-03-30 10:44:43 +01:00
|
|
|
expectedSegmentFirst.PlainOffset = 0
|
2020-11-03 15:03:20 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetLatestObjectLastSegment{
|
2020-11-03 15:03:20 +00:00
|
|
|
Opts: metabase.GetLatestObjectLastSegment{
|
|
|
|
ObjectLocation: location,
|
|
|
|
},
|
|
|
|
Result: expectedSegmentSecond,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-11-03 15:03:20 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
2020-11-03 14:45:39 +00:00
|
|
|
SegmentCount: 2,
|
|
|
|
|
2020-11-24 12:29:16 +00:00
|
|
|
TotalPlainSize: 1024,
|
2020-11-03 14:45:39 +00:00
|
|
|
TotalEncryptedSize: 2048,
|
2021-01-14 11:47:29 +00:00
|
|
|
FixedSegmentSize: 512,
|
2020-11-03 14:45:39 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-03 15:03:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(expectedSegmentFirst),
|
|
|
|
metabase.RawSegment(expectedSegmentSecond),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2022-03-02 09:23:47 +00:00
|
|
|
|
|
|
|
t.Run("Get segment copy", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
objStream := metabasetest.RandObjectStream()
|
|
|
|
|
2022-02-16 23:24:38 +00:00
|
|
|
originalObj, originalSegments := metabasetest.CreateTestObject{
|
|
|
|
CommitObject: &metabase.CommitObject{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
EncryptedMetadata: testrand.Bytes(64),
|
|
|
|
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
|
|
|
|
EncryptedMetadataEncryptedKey: testrand.Bytes(265),
|
2022-03-02 09:23:47 +00:00
|
|
|
},
|
2022-02-16 23:24:38 +00:00
|
|
|
}.Run(ctx, t, db, objStream, 1)
|
2022-03-02 09:23:47 +00:00
|
|
|
|
2022-02-18 00:03:50 +00:00
|
|
|
copyObj, _, newSegments := metabasetest.CreateObjectCopy{
|
2022-02-16 23:24:38 +00:00
|
|
|
OriginalObject: originalObj,
|
|
|
|
}.Run(ctx, t, db)
|
2022-03-02 09:23:47 +00:00
|
|
|
|
|
|
|
metabasetest.GetLatestObjectLastSegment{
|
|
|
|
Opts: metabase.GetLatestObjectLastSegment{
|
2022-02-16 23:24:38 +00:00
|
|
|
ObjectLocation: originalObj.Location(),
|
2022-03-02 09:23:47 +00:00
|
|
|
},
|
2022-02-16 23:24:38 +00:00
|
|
|
Result: originalSegments[0],
|
2022-03-02 09:23:47 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2022-02-16 23:24:38 +00:00
|
|
|
copySegmentGet := originalSegments[0]
|
|
|
|
copySegmentGet.StreamID = copyObj.StreamID
|
|
|
|
copySegmentGet.EncryptedETag = nil
|
|
|
|
copySegmentGet.InlineData = []byte{}
|
|
|
|
copySegmentGet.EncryptedKey = newSegments[0].EncryptedKey
|
|
|
|
copySegmentGet.EncryptedKeyNonce = newSegments[0].EncryptedKeyNonce
|
|
|
|
|
2022-03-02 09:23:47 +00:00
|
|
|
metabasetest.GetLatestObjectLastSegment{
|
|
|
|
Opts: metabase.GetLatestObjectLastSegment{
|
2022-02-16 23:24:38 +00:00
|
|
|
ObjectLocation: copyObj.Location(),
|
2022-03-02 09:23:47 +00:00
|
|
|
},
|
2022-02-16 23:24:38 +00:00
|
|
|
Result: copySegmentGet,
|
2022-03-02 09:23:47 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
2022-02-16 23:24:38 +00:00
|
|
|
metabase.RawObject(originalObj),
|
|
|
|
metabase.RawObject(copyObj),
|
|
|
|
},
|
|
|
|
Segments: append(metabasetest.SegmentsToRaw(originalSegments), newSegments...),
|
|
|
|
Copies: []metabase.RawCopy{{
|
|
|
|
StreamID: copyObj.StreamID,
|
|
|
|
AncestorStreamID: originalObj.StreamID,
|
|
|
|
}},
|
2022-03-02 09:23:47 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get empty inline segment copy", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
objStream := metabasetest.RandObjectStream()
|
|
|
|
copyObjStream := metabasetest.RandObjectStream()
|
|
|
|
copyObjStream.ProjectID = objStream.ProjectID
|
|
|
|
objLocation := objStream.Location()
|
|
|
|
copyLocation := copyObjStream.Location()
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitInlineSegment{
|
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: uint32(0)},
|
|
|
|
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
|
|
|
|
PlainSize: 0,
|
|
|
|
PlainOffset: 0,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj := metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
encryptedKeyNonces := []metabase.EncryptedKeyAndNonce{{
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
newEncryptedKeyNonces := []metabase.EncryptedKeyAndNonce{{
|
|
|
|
EncryptedKeyNonce: []byte{3},
|
|
|
|
EncryptedKey: []byte{4},
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
metabasetest.BeginCopyObject{
|
|
|
|
Opts: metabase.BeginCopyObject{
|
|
|
|
Version: obj.Version,
|
|
|
|
ObjectLocation: obj.Location(),
|
|
|
|
},
|
|
|
|
Result: metabase.BeginCopyObjectResult{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
EncryptedMetadata: obj.EncryptedMetadata,
|
|
|
|
EncryptedMetadataKey: obj.EncryptedMetadataEncryptedKey,
|
|
|
|
EncryptedMetadataKeyNonce: obj.EncryptedMetadataNonce,
|
|
|
|
EncryptedKeysNonces: encryptedKeyNonces,
|
|
|
|
EncryptionParameters: obj.Encryption,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
newEncryptedMetadataKeyNonce := testrand.Nonce()
|
|
|
|
newEncryptedMetadataKey := testrand.Bytes(32)
|
|
|
|
|
|
|
|
_, err := db.FinishCopyObject(ctx, metabase.FinishCopyObject{
|
|
|
|
ObjectStream: obj.ObjectStream,
|
|
|
|
NewStreamID: copyObjStream.StreamID,
|
|
|
|
NewBucket: copyObjStream.BucketName,
|
|
|
|
NewSegmentKeys: newEncryptedKeyNonces,
|
2022-03-04 11:28:04 +00:00
|
|
|
NewEncryptedObjectKey: copyObjStream.ObjectKey,
|
2022-03-23 16:06:14 +00:00
|
|
|
NewEncryptedMetadataKeyNonce: newEncryptedMetadataKeyNonce,
|
2022-03-02 09:23:47 +00:00
|
|
|
NewEncryptedMetadataKey: newEncryptedMetadataKey,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
expectedSegment := metabase.Segment{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
CreatedAt: obj.CreatedAt,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
EncryptedSize: 0,
|
|
|
|
PlainSize: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedCopiedSegmentRaw := metabase.Segment{
|
|
|
|
StreamID: copyObjStream.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
CreatedAt: obj.CreatedAt,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
|
|
|
|
Pieces: metabase.Pieces{},
|
|
|
|
|
|
|
|
EncryptedKey: newEncryptedKeyNonces[0].EncryptedKey,
|
|
|
|
EncryptedKeyNonce: newEncryptedKeyNonces[0].EncryptedKeyNonce,
|
2022-02-16 23:24:38 +00:00
|
|
|
|
|
|
|
InlineData: []byte{},
|
2022-03-02 09:23:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedCopiedSegmentGet := expectedSegment
|
|
|
|
expectedCopiedSegmentGet.StreamID = copyObjStream.StreamID
|
|
|
|
|
|
|
|
expectedCopiedSegmentGet.EncryptedKey = newEncryptedKeyNonces[0].EncryptedKey
|
|
|
|
expectedCopiedSegmentGet.EncryptedKeyNonce = newEncryptedKeyNonces[0].EncryptedKeyNonce
|
2022-02-16 23:24:38 +00:00
|
|
|
expectedCopiedSegmentGet.InlineData = []byte{}
|
2022-03-02 09:23:47 +00:00
|
|
|
|
|
|
|
metabasetest.GetLatestObjectLastSegment{
|
|
|
|
Opts: metabase.GetLatestObjectLastSegment{
|
|
|
|
ObjectLocation: objLocation,
|
|
|
|
},
|
|
|
|
Result: expectedSegment,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.GetLatestObjectLastSegment{
|
|
|
|
Opts: metabase.GetLatestObjectLastSegment{
|
|
|
|
ObjectLocation: copyLocation,
|
|
|
|
},
|
|
|
|
Result: expectedCopiedSegmentGet,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj.ObjectStream,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: copyObjStream,
|
|
|
|
CreatedAt: now,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
EncryptedMetadataNonce: newEncryptedMetadataKeyNonce[:],
|
|
|
|
EncryptedMetadataEncryptedKey: newEncryptedMetadataKey,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(expectedSegment),
|
|
|
|
metabase.RawSegment(expectedCopiedSegmentRaw),
|
|
|
|
},
|
2022-02-24 00:17:35 +00:00
|
|
|
Copies: nil,
|
2022-03-02 09:23:47 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get inline segment copy", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
objStream := metabasetest.RandObjectStream()
|
|
|
|
copyObjStream := metabasetest.RandObjectStream()
|
|
|
|
data := testrand.Bytes(1024)
|
|
|
|
copyObjStream.ProjectID = objStream.ProjectID
|
|
|
|
objLocation := objStream.Location()
|
|
|
|
copyLocation := copyObjStream.Location()
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitInlineSegment{
|
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: uint32(0)},
|
|
|
|
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
|
|
|
|
PlainSize: 0,
|
|
|
|
PlainOffset: 0,
|
|
|
|
|
|
|
|
InlineData: data,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
obj := metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: objStream,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
encryptedKeyNonces := []metabase.EncryptedKeyAndNonce{{
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
newEncryptedKeyNonces := []metabase.EncryptedKeyAndNonce{{
|
|
|
|
EncryptedKeyNonce: []byte{3},
|
|
|
|
EncryptedKey: []byte{4},
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
|
|
|
|
metabasetest.BeginCopyObject{
|
|
|
|
Opts: metabase.BeginCopyObject{
|
|
|
|
Version: obj.Version,
|
|
|
|
ObjectLocation: obj.Location(),
|
|
|
|
},
|
|
|
|
Result: metabase.BeginCopyObjectResult{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
EncryptedMetadata: obj.EncryptedMetadata,
|
|
|
|
EncryptedMetadataKey: obj.EncryptedMetadataEncryptedKey,
|
|
|
|
EncryptedMetadataKeyNonce: obj.EncryptedMetadataNonce,
|
|
|
|
EncryptedKeysNonces: encryptedKeyNonces,
|
|
|
|
EncryptionParameters: obj.Encryption,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
newEncryptedMetadataKeyNonce := testrand.Nonce()
|
|
|
|
newEncryptedMetadataKey := testrand.Bytes(32)
|
|
|
|
|
|
|
|
_, err := db.FinishCopyObject(ctx, metabase.FinishCopyObject{
|
|
|
|
ObjectStream: obj.ObjectStream,
|
|
|
|
NewStreamID: copyObjStream.StreamID,
|
|
|
|
NewBucket: copyObjStream.BucketName,
|
|
|
|
NewSegmentKeys: newEncryptedKeyNonces,
|
2022-03-04 11:28:04 +00:00
|
|
|
NewEncryptedObjectKey: copyObjStream.ObjectKey,
|
2022-03-23 16:06:14 +00:00
|
|
|
NewEncryptedMetadataKeyNonce: newEncryptedMetadataKeyNonce,
|
2022-03-02 09:23:47 +00:00
|
|
|
NewEncryptedMetadataKey: newEncryptedMetadataKey,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
expectedSegment := metabase.Segment{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
CreatedAt: obj.CreatedAt,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 0,
|
|
|
|
|
|
|
|
InlineData: data,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedCopiedSegmentRaw := metabase.Segment{
|
|
|
|
StreamID: copyObjStream.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
CreatedAt: obj.CreatedAt,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
|
|
|
|
Pieces: metabase.Pieces{},
|
|
|
|
|
|
|
|
EncryptedKey: newEncryptedKeyNonces[0].EncryptedKey,
|
|
|
|
EncryptedKeyNonce: newEncryptedKeyNonces[0].EncryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
|
|
|
|
InlineData: data,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedCopiedSegmentGet := expectedSegment
|
|
|
|
expectedCopiedSegmentGet.StreamID = copyObjStream.StreamID
|
|
|
|
|
|
|
|
expectedCopiedSegmentGet.EncryptedKey = newEncryptedKeyNonces[0].EncryptedKey
|
|
|
|
expectedCopiedSegmentGet.EncryptedKeyNonce = newEncryptedKeyNonces[0].EncryptedKeyNonce
|
|
|
|
|
|
|
|
metabasetest.GetLatestObjectLastSegment{
|
|
|
|
Opts: metabase.GetLatestObjectLastSegment{
|
|
|
|
ObjectLocation: objLocation,
|
|
|
|
},
|
|
|
|
Result: expectedSegment,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.GetLatestObjectLastSegment{
|
|
|
|
Opts: metabase.GetLatestObjectLastSegment{
|
|
|
|
ObjectLocation: copyLocation,
|
|
|
|
},
|
|
|
|
Result: expectedCopiedSegmentGet,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj.ObjectStream,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
TotalEncryptedSize: 1024,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: copyObjStream,
|
|
|
|
CreatedAt: now,
|
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
EncryptedMetadataNonce: newEncryptedMetadataKeyNonce[:],
|
|
|
|
EncryptedMetadataEncryptedKey: newEncryptedMetadataKey,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
TotalEncryptedSize: 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(expectedSegment),
|
|
|
|
metabase.RawSegment(expectedCopiedSegmentRaw),
|
|
|
|
},
|
2022-02-24 00:17:35 +00:00
|
|
|
Copies: nil,
|
2022-03-02 09:23:47 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2020-11-03 15:03:20 +00:00
|
|
|
})
|
|
|
|
}
|
2020-11-10 09:17:25 +00:00
|
|
|
|
2020-11-17 17:37:58 +00:00
|
|
|
func TestBucketEmpty(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-11-17 17:37:58 +00:00
|
|
|
now := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
|
|
|
t.Run("ProjectID missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BucketEmpty{
|
2020-11-17 17:37:58 +00:00
|
|
|
Opts: metabase.BucketEmpty{},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "ProjectID missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("BucketName missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BucketEmpty{
|
2020-11-17 17:37:58 +00:00
|
|
|
Opts: metabase.BucketEmpty{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "BucketName missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("BucketEmpty true", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BucketEmpty{
|
2020-11-17 17:37:58 +00:00
|
|
|
Opts: metabase.BucketEmpty{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
},
|
|
|
|
Result: true,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("BucketEmpty false with pending object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-11-17 17:37:58 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-17 17:37:58 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BucketEmpty{
|
2020-11-17 17:37:58 +00:00
|
|
|
Opts: metabase.BucketEmpty{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
},
|
|
|
|
Result: false,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-11-17 17:37:58 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
2021-05-06 12:42:20 +01:00
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2020-11-17 17:37:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("BucketEmpty false with committed object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object := metabasetest.CreateObject(ctx, t, db, obj, 0)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BucketEmpty{
|
2020-11-17 17:37:58 +00:00
|
|
|
Opts: metabase.BucketEmpty{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
},
|
|
|
|
Result: false,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-11-17 17:37:58 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(object),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|