2020-10-28 15:28:06 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metabase_test
|
|
|
|
|
|
|
|
import (
|
2021-01-06 16:21:17 +00:00
|
|
|
"math"
|
2020-10-28 15:28:06 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-10-04 16:38:20 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2021-09-24 15:18:21 +01:00
|
|
|
"storj.io/common/memory"
|
2020-10-28 15:28:06 +00:00
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"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 TestBeginObjectNextVersion(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
|
|
|
|
2021-10-29 11:38:28 +01:00
|
|
|
objectStream := metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectStreams(obj) {
|
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.BeginObjectNextVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectNextVersion{
|
|
|
|
ObjectStream: test.ObjectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: -1,
|
|
|
|
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
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-29 11:38:28 +01:00
|
|
|
t.Run("invalid EncryptedMetadata", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.BeginObjectNextVersion{
|
|
|
|
Opts: metabase.BeginObjectNextVersion{
|
|
|
|
ObjectStream: objectStream,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
EncryptedMetadata: testrand.BytesInt(32),
|
|
|
|
},
|
|
|
|
Version: -1,
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
2021-10-29 12:04:55 +01:00
|
|
|
ErrText: "EncryptedMetadataNonce and EncryptedMetadataEncryptedKey must be set if EncryptedMetadata is set",
|
2021-10-29 11:38:28 +01:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.BeginObjectNextVersion{
|
|
|
|
Opts: metabase.BeginObjectNextVersion{
|
|
|
|
ObjectStream: objectStream,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
EncryptedMetadataEncryptedKey: testrand.BytesInt(32),
|
|
|
|
},
|
|
|
|
Version: -1,
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
2021-10-29 12:04:55 +01:00
|
|
|
ErrText: "EncryptedMetadataNonce and EncryptedMetadataEncryptedKey must be not set if EncryptedMetadata is not set",
|
2021-10-29 11:38:28 +01:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
2021-02-08 21:45:29 +00:00
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
t.Run("disallow exact 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-02-08 21:45:29 +00:00
|
|
|
objectStream.Version = 5
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectNextVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectNextVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: -1,
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "Version should be metabase.NextVersion",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("NextVersion", 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
|
|
|
|
|
|
|
now1 := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now1.Add(24 * time.Hour)
|
|
|
|
futureTime := now1.Add(10 * 24 * time.Hour)
|
2021-02-08 21:45:29 +00:00
|
|
|
|
|
|
|
objectStream.Version = metabase.NextVersion
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectNextVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.BeginObjectNextVersion{
|
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
now2 := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectNextVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.BeginObjectNextVersion{
|
2021-05-06 12:42:20 +01:00
|
|
|
ObjectStream: objectStream,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &futureTime,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
Version: 2,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-02-08 21:45:29 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 1,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now1,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 2,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now2,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &futureTime,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO: expires at date
|
|
|
|
// TODO: zombie deletion deadline
|
|
|
|
|
|
|
|
t.Run("older committed version exists", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-08 21:45:29 +00:00
|
|
|
|
|
|
|
objectStream.Version = metabase.NextVersion
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectNextVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectNextVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
2021-02-08 21:45:29 +00:00
|
|
|
Version: 1,
|
2020-10-28 15:28:06 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
now2 := time.Now()
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectNextVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectNextVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
Version: 2,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2022-11-14 14:41:55 +00:00
|
|
|
// CommitObject will also delete old object with version 1
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
2021-02-08 21:45:29 +00:00
|
|
|
Version: 2,
|
2020-10-28 15:28:06 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.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: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 2,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now2,
|
2021-02-08 21:45:29 +00:00
|
|
|
Status: metabase.Committed,
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-02-08 21:45:29 +00:00
|
|
|
t.Run("newer committed version exists", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-08 21:45:29 +00:00
|
|
|
|
|
|
|
now1 := time.Now()
|
|
|
|
|
|
|
|
objectStream.Version = metabase.NextVersion
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectNextVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.BeginObjectNextVersion{
|
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectNextVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.BeginObjectNextVersion{
|
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
Version: 2,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 2,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2022-11-14 14:41:55 +00:00
|
|
|
// CommitObject will also delete old object with version 2
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 1,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-02-08 21:45:29 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 1,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now1,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2021-10-29 11:38:28 +01:00
|
|
|
|
|
|
|
t.Run("begin object next version with metadata", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
|
|
|
|
|
|
|
objectStream.Version = metabase.NextVersion
|
|
|
|
|
|
|
|
encryptedMetadata := testrand.BytesInt(64)
|
|
|
|
encryptedMetadataNonce := testrand.Nonce()
|
|
|
|
encryptedMetadataEncryptedKey := testrand.BytesInt(32)
|
|
|
|
|
|
|
|
metabasetest.BeginObjectNextVersion{
|
|
|
|
Opts: metabase.BeginObjectNextVersion{
|
|
|
|
ObjectStream: objectStream,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataEncryptedKey,
|
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: metabase.DefaultVersion,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataEncryptedKey,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-11-14 14:41:55 +00:00
|
|
|
func TestBeginObjectExactVersion(t *testing.T) {
|
|
|
|
// BeginObjectExactVersion will be removed when MultipleVersions feature will be enabled in prod
|
|
|
|
// but for now lets keep this test but just disable MultipleVersions
|
2022-09-21 09:10:06 +01:00
|
|
|
metabasetest.RunWithConfig(t, metabase.Config{
|
|
|
|
ApplicationName: "satellite-test",
|
2022-11-14 14:41:55 +00:00
|
|
|
MultipleVersions: false,
|
2022-09-21 09:10:06 +01:00
|
|
|
}, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectStreams(obj) {
|
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.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: test.ObjectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: -1,
|
|
|
|
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
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-02-08 21:45:29 +00:00
|
|
|
objectStream := metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
}
|
|
|
|
|
2021-10-29 11:38:28 +01:00
|
|
|
t.Run("invalid EncryptedMetadata", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
objectStream.Version = 1
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: objectStream,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
EncryptedMetadata: testrand.BytesInt(32),
|
|
|
|
},
|
|
|
|
Version: metabase.DefaultVersion,
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
2021-10-29 12:04:55 +01:00
|
|
|
ErrText: "EncryptedMetadataNonce and EncryptedMetadataEncryptedKey must be set if EncryptedMetadata is set",
|
2021-10-29 11:38:28 +01:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: objectStream,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
EncryptedMetadataEncryptedKey: testrand.BytesInt(32),
|
|
|
|
},
|
|
|
|
Version: metabase.DefaultVersion,
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
2021-10-29 12:04:55 +01:00
|
|
|
ErrText: "EncryptedMetadataNonce and EncryptedMetadataEncryptedKey must be not set if EncryptedMetadata is not set",
|
2021-10-29 11:38:28 +01:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
t.Run("disallow NextVersion", 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-02-08 21:45:29 +00:00
|
|
|
objectStream.Version = metabase.NextVersion
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: -1,
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "Version should not be metabase.NextVersion",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Specific 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
|
|
|
|
|
|
|
now1 := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now1.Add(24 * time.Hour)
|
2021-02-08 21:45:29 +00:00
|
|
|
|
|
|
|
objectStream.Version = 5
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: 5,
|
|
|
|
}.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: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 5,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now1,
|
|
|
|
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("Duplicate pending 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
|
|
|
|
|
|
|
now1 := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now1.Add(24 * time.Hour)
|
2021-02-08 21:45:29 +00:00
|
|
|
|
|
|
|
objectStream.Version = 5
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: 5,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: -1,
|
2022-01-27 10:30:45 +00:00
|
|
|
ErrClass: &metabase.ErrObjectAlreadyExists,
|
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: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 5,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now1,
|
|
|
|
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("Duplicate committed 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
|
|
|
|
|
|
|
now1 := time.Now()
|
2021-02-08 21:45:29 +00:00
|
|
|
|
|
|
|
objectStream.Version = 5
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: 5,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitObject{
|
2021-02-08 21:45:29 +00:00
|
|
|
ObjectStream: objectStream,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: -1,
|
2022-01-27 10:30:45 +00:00
|
|
|
ErrClass: &metabase.ErrObjectAlreadyExists,
|
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: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 5,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now1,
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
// TODO: expires at date
|
|
|
|
// TODO: zombie deletion deadline
|
|
|
|
|
2021-02-08 21:45:29 +00:00
|
|
|
t.Run("Older committed version exists", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-08 21:45:29 +00:00
|
|
|
|
|
|
|
now1 := time.Now()
|
|
|
|
|
|
|
|
objectStream.Version = 1
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: objectStream,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
objectStream.Version = 3
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
Version: 3,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: objectStream,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-02-08 21:45:29 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 1,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now1,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 3,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now1,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Newer committed version exists", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-08 21:45:29 +00:00
|
|
|
|
|
|
|
now1 := time.Now()
|
|
|
|
|
|
|
|
objectStream.Version = 3
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
Version: 3,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: objectStream,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
objectStream.Version = 1
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: objectStream,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-02-08 21:45:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: objectStream,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-02-08 21:45:29 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 1,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now1,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 3,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now1,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-08 21:45:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2021-10-29 11:38:28 +01:00
|
|
|
|
|
|
|
t.Run("begin object exact version with metadata", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
|
|
|
|
|
|
|
objectStream.Version = 1
|
|
|
|
|
|
|
|
encryptedMetadata := testrand.BytesInt(64)
|
|
|
|
encryptedMetadataNonce := testrand.Nonce()
|
|
|
|
encryptedMetadataEncryptedKey := testrand.BytesInt(32)
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: objectStream,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataEncryptedKey,
|
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: metabase.DefaultVersion,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataEncryptedKey,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBeginSegment(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
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectStreams(obj) {
|
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.BeginSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: test.ObjectStream,
|
|
|
|
},
|
|
|
|
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("RootPieceID 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.BeginSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
2020-12-21 10:48:48 +00:00
|
|
|
Pieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "RootPieceID 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("Pieces 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.BeginSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
2020-12-21 10:48:48 +00:00
|
|
|
ErrText: "pieces missing",
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("StorageNode in pieces missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginSegment{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Pieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: storj.NodeID{},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "piece number 1 is missing storage node id",
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Piece number 2 is duplicated", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginSegment{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Pieces: []metabase.Piece{
|
|
|
|
{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "duplicated piece number 1",
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Pieces should be ordered", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-12-21 10:48:48 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginSegment{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Pieces: []metabase.Piece{
|
|
|
|
{
|
|
|
|
Number: 2,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "pieces should be ordered",
|
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("pending 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.BeginSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
},
|
2022-05-09 16:11:36 +01:00
|
|
|
ErrClass: &metabase.ErrPendingObjectMissing,
|
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("pending object missing when object committed", 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
|
|
|
now := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
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.CommitObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
},
|
2022-05-09 16:11:36 +01:00
|
|
|
ErrClass: &metabase.ErrPendingObjectMissing,
|
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("begin segment successfully", 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
|
|
|
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
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
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.BeginSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}.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("multiple begin segment successfully", 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
|
|
|
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
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
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)
|
|
|
|
|
|
|
|
for i := 0; i < 5; i++ {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}.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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommitSegment(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()
|
2021-03-12 17:43:30 +00:00
|
|
|
now := time.Now()
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectStreams(obj) {
|
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.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: test.ObjectStream,
|
|
|
|
},
|
|
|
|
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("invalid request", 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
|
|
|
|
|
|
|
now := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
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.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
2020-12-21 10:48:48 +00:00
|
|
|
Pieces: metabase.Pieces{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "RootPieceID missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
2020-12-21 10:48:48 +00:00
|
|
|
ErrText: "pieces missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Pieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: storj.NodeID{},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "piece number 1 is missing storage node id",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Pieces: []metabase.Piece{
|
|
|
|
{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "duplicated piece number 1",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-12-21 10:48:48 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Pieces: []metabase.Piece{
|
|
|
|
{
|
|
|
|
Number: 2,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "pieces should be ordered",
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: testrand.PieceID(),
|
|
|
|
Pieces: metabase.Pieces{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "EncryptedKey missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: testrand.PieceID(),
|
|
|
|
|
|
|
|
Pieces: metabase.Pieces{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "EncryptedKeyNonce missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: testrand.PieceID(),
|
|
|
|
|
|
|
|
Pieces: metabase.Pieces{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Bytes(32),
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
EncryptedSize: -1,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "EncryptedSize negative or zero",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-01-04 13:43:24 +00:00
|
|
|
if metabase.ValidatePlainSize {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2021-01-04 13:43:24 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: testrand.PieceID(),
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-01-04 13:43:24 +00:00
|
|
|
Pieces: metabase.Pieces{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-01-04 13:43:24 +00:00
|
|
|
EncryptedKey: testrand.Bytes(32),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Bytes(32),
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-01-04 13:43:24 +00:00
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: -1,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "PlainSize negative or zero",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
}
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: testrand.PieceID(),
|
|
|
|
|
|
|
|
Pieces: metabase.Pieces{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Bytes(32),
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: -1,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "PlainOffset negative",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: testrand.PieceID(),
|
|
|
|
|
|
|
|
Pieces: metabase.Pieces{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Bytes(32),
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "Redundancy zero",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-03-11 14:52:53 +00:00
|
|
|
redundancy := storj.RedundancyScheme{
|
|
|
|
OptimalShares: 2,
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2021-03-11 14:52:53 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Pieces: []metabase.Piece{
|
|
|
|
{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
RootPieceID: testrand.PieceID(),
|
|
|
|
Redundancy: redundancy,
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Bytes(32),
|
2021-03-11 14:52:53 +00:00
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "number of pieces is less than redundancy optimal shares value",
|
|
|
|
}.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("duplicate", 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
|
|
|
|
|
|
|
now1 := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now1.Add(24 * time.Hour)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
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)
|
|
|
|
|
|
|
|
rootPieceID := testrand.PieceID()
|
|
|
|
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
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: now1,
|
|
|
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
2021-03-12 17:43:30 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainOffset: 0,
|
|
|
|
PlainSize: 512,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-09-27 18:38:15 +01:00
|
|
|
t.Run("overwrite", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
now1 := time.Now()
|
|
|
|
zombieDeadline := now1.Add(24 * time.Hour)
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
rootPieceID1 := testrand.PieceID()
|
|
|
|
rootPieceID2 := testrand.PieceID()
|
|
|
|
pieces1 := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
pieces2 := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
|
|
|
|
|
|
|
metabasetest.BeginSegment{
|
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
RootPieceID: rootPieceID1,
|
|
|
|
Pieces: pieces1,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitSegment{
|
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
RootPieceID: rootPieceID1,
|
|
|
|
Pieces: pieces1,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitSegment{
|
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
RootPieceID: rootPieceID2,
|
|
|
|
Pieces: pieces2,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now1,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
CreatedAt: now,
|
|
|
|
|
|
|
|
RootPieceID: rootPieceID2,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainOffset: 0,
|
|
|
|
PlainSize: 512,
|
|
|
|
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
|
|
|
|
Pieces: pieces2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
t.Run("commit segment of missing 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
|
|
|
|
|
|
|
rootPieceID := testrand.PieceID()
|
|
|
|
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
2022-05-09 16:11:36 +01:00
|
|
|
ErrClass: &metabase.ErrPendingObjectMissing,
|
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("commit segment of committed 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
|
|
|
|
|
|
|
rootPieceID := testrand.PieceID()
|
|
|
|
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
now := time.Now()
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
2022-05-09 16:11:36 +01:00
|
|
|
ErrClass: &metabase.ErrPendingObjectMissing,
|
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)
|
|
|
|
})
|
|
|
|
|
2021-06-10 11:08:21 +01:00
|
|
|
t.Run("commit segment of object with expires at", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
rootPieceID := testrand.PieceID()
|
|
|
|
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2021-06-10 11:08:21 +01:00
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
expectedExpiresAt := now.Add(33 * time.Hour)
|
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ExpiresAt: &expectedExpiresAt,
|
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitSegment{
|
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
ExpiresAt: &expectedExpiresAt,
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
ExpiresAt: &expectedExpiresAt,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2021-06-10 11:08:21 +01:00
|
|
|
ExpiresAt: &expectedExpiresAt,
|
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainOffset: 0,
|
|
|
|
PlainSize: 512,
|
|
|
|
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
t.Run("commit segment of 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
|
|
|
|
|
|
|
rootPieceID := testrand.PieceID()
|
|
|
|
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2021-03-25 07:53:10 +00:00
|
|
|
encryptedETag := testrand.Bytes(32)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
now := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2021-03-25 07:53:10 +00:00
|
|
|
EncryptedETag: encryptedETag,
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
2021-03-12 17:43:30 +00:00
|
|
|
StreamID: obj.StreamID,
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainOffset: 0,
|
|
|
|
PlainSize: 512,
|
2021-03-25 07:53:10 +00:00
|
|
|
EncryptedETag: encryptedETag,
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
2022-05-09 16:11:36 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommitInlineSegment(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()
|
|
|
|
for _, test := range metabasetest.InvalidObjectStreams(obj) {
|
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.CommitInlineSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: test.ObjectStream,
|
|
|
|
},
|
|
|
|
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("invalid request", 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,
|
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.CommitInlineSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
2021-02-19 09:28:41 +00:00
|
|
|
ErrText: "EncryptedKey missing",
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "EncryptedKey missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
|
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "EncryptedKeyNonce missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-01-04 13:43:24 +00:00
|
|
|
if metabase.ValidatePlainSize {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2021-01-04 13:43:24 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-01-04 13:43:24 +00:00
|
|
|
InlineData: []byte{1, 2, 3},
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-01-04 13:43:24 +00:00
|
|
|
EncryptedKey: testrand.Bytes(32),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Bytes(32),
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-01-04 13:43:24 +00:00
|
|
|
PlainSize: -1,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "PlainSize negative or zero",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
}
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
|
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
|
|
|
|
EncryptedKey: testrand.Bytes(32),
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: testrand.Bytes(32),
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: -1,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "PlainOffset negative",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("duplicate", 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
|
|
|
|
2022-05-20 09:26:37 +01:00
|
|
|
now := time.Now()
|
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2021-05-06 12:42:20 +01:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
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)
|
|
|
|
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
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,
|
2022-05-20 09:26:37 +01:00
|
|
|
CreatedAt: now,
|
2020-10-28 15:28:06 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
2021-03-12 17:43:30 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
PlainOffset: 0,
|
|
|
|
PlainSize: 512,
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
EncryptedSize: 3,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2020-11-09 12:40:47 +00:00
|
|
|
|
2021-09-27 18:38:15 +01:00
|
|
|
t.Run("overwrite", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
2022-05-20 09:26:37 +01:00
|
|
|
now := time.Now()
|
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2021-09-27 18:38:15 +01:00
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
|
|
|
|
|
|
|
metabasetest.CommitInlineSegment{
|
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitInlineSegment{
|
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
InlineData: []byte{4, 5, 6},
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
2022-05-20 09:26:37 +01:00
|
|
|
CreatedAt: now,
|
2021-09-27 18:38:15 +01:00
|
|
|
Status: metabase.Pending,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
CreatedAt: now,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
PlainOffset: 0,
|
|
|
|
PlainSize: 512,
|
|
|
|
|
|
|
|
InlineData: []byte{4, 5, 6},
|
|
|
|
EncryptedSize: 3,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2020-11-09 12:40:47 +00:00
|
|
|
t.Run("commit inline segment of missing object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-09 12:40:47 +00:00
|
|
|
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2020-11-09 12:40:47 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2020-11-09 12:40:47 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
2020-11-09 12:40:47 +00:00
|
|
|
},
|
2022-05-09 16:11:36 +01:00
|
|
|
ErrClass: &metabase.ErrPendingObjectMissing,
|
2020-11-09 12:40:47 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-09 12:40:47 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("commit segment of committed object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-09 12:40:47 +00:00
|
|
|
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2020-11-09 12:40:47 +00:00
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateObject(ctx, t, db, obj, 0)
|
|
|
|
metabasetest.CommitInlineSegment{
|
2020-11-09 12:40:47 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
2020-11-09 12:40:47 +00:00
|
|
|
},
|
2022-05-09 16:11:36 +01:00
|
|
|
ErrClass: &metabase.ErrPendingObjectMissing,
|
2020-11-09 12:40:47 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-11-09 12:40:47 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-09 12:40:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-02-19 09:28:41 +00:00
|
|
|
t.Run("commit empty segment of pending object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-19 09:28:41 +00:00
|
|
|
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2021-03-25 07:53:10 +00:00
|
|
|
encryptedETag := testrand.Bytes(32)
|
2021-02-19 09:28:41 +00:00
|
|
|
|
|
|
|
now := time.Now()
|
2022-05-20 09:26:37 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2021-02-19 09:28:41 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-19 09:28:41 +00:00
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2021-02-19 09:28:41 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
2021-03-25 07:53:10 +00:00
|
|
|
PlainSize: 0,
|
|
|
|
PlainOffset: 0,
|
|
|
|
EncryptedETag: encryptedETag,
|
2021-02-19 09:28:41 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-02-19 09:28:41 +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,
|
2021-02-19 09:28:41 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
2021-03-12 17:43:30 +00:00
|
|
|
StreamID: obj.StreamID,
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2021-02-19 09:28:41 +00:00
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
PlainOffset: 0,
|
|
|
|
PlainSize: 0,
|
|
|
|
|
|
|
|
EncryptedSize: 0,
|
2021-03-25 07:53:10 +00:00
|
|
|
EncryptedETag: encryptedETag,
|
2021-02-19 09:28:41 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2020-11-09 12:40:47 +00:00
|
|
|
t.Run("commit segment of pending object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-09 12:40:47 +00:00
|
|
|
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2021-03-25 07:53:10 +00:00
|
|
|
encryptedETag := testrand.Bytes(32)
|
2020-11-09 12:40:47 +00:00
|
|
|
|
|
|
|
now := time.Now()
|
2022-05-20 09:26:37 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-11-09 12:40:47 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-09 12:40:47 +00:00
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitInlineSegment{
|
2020-11-09 12:40:47 +00:00
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
2021-03-25 07:53:10 +00:00
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
EncryptedETag: encryptedETag,
|
2020-11-09 12:40:47 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-11-09 12:40:47 +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-09 12:40:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
2021-03-12 17:43:30 +00:00
|
|
|
StreamID: obj.StreamID,
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2020-11-09 12:40:47 +00:00
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
PlainOffset: 0,
|
|
|
|
PlainSize: 512,
|
2020-11-09 12:40:47 +00:00
|
|
|
|
2020-11-11 10:54:10 +00:00
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
EncryptedSize: 3,
|
2021-03-25 07:53:10 +00:00
|
|
|
EncryptedETag: encryptedETag,
|
2020-11-09 12:40:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2021-06-10 11:08:21 +01:00
|
|
|
|
|
|
|
t.Run("commit segment of object with expires at", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2021-06-10 11:08:21 +01:00
|
|
|
encryptedETag := testrand.Bytes(32)
|
|
|
|
|
|
|
|
now := time.Now()
|
2022-05-20 09:26:37 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2021-06-10 11:08:21 +01:00
|
|
|
expectedExpiresAt := now.Add(33 * time.Hour)
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ExpiresAt: &expectedExpiresAt,
|
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitInlineSegment{
|
|
|
|
Opts: metabase.CommitInlineSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
ExpiresAt: &expectedExpiresAt,
|
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
EncryptedETag: encryptedETag,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
ExpiresAt: &expectedExpiresAt,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2021-06-10 11:08:21 +01:00
|
|
|
ExpiresAt: &expectedExpiresAt,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
PlainOffset: 0,
|
|
|
|
PlainSize: 512,
|
|
|
|
|
|
|
|
InlineData: []byte{1, 2, 3},
|
|
|
|
EncryptedSize: 3,
|
|
|
|
EncryptedETag: encryptedETag,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommitObject(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
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectStreams(obj) {
|
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.CommitObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: test.ObjectStream,
|
|
|
|
},
|
|
|
|
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
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-29 12:04:55 +01:00
|
|
|
t.Run("invalid EncryptedMetadata", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: metabase.DefaultVersion,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
2022-04-14 12:20:18 +01:00
|
|
|
OverrideEncryptedMetadata: true,
|
|
|
|
EncryptedMetadata: testrand.BytesInt(32),
|
2021-10-29 12:04:55 +01:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "EncryptedMetadataNonce and EncryptedMetadataEncryptedKey must be set if EncryptedMetadata is set",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: metabase.DefaultVersion,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
2022-04-14 12:20:18 +01:00
|
|
|
OverrideEncryptedMetadata: true,
|
2021-10-29 12:04:55 +01:00
|
|
|
EncryptedMetadataEncryptedKey: testrand.BytesInt(32),
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "EncryptedMetadataNonce and EncryptedMetadataEncryptedKey must be not set if EncryptedMetadata is not set",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2020-11-12 11:29:19 +00:00
|
|
|
t.Run("version without pending", 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.CommitObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 5,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
},
|
2020-11-02 17:25:58 +00:00
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: object with specified version and pending status is missing", // TODO: this error message could be better
|
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
|
|
|
})
|
|
|
|
|
2020-11-12 11:29:19 +00:00
|
|
|
t.Run("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.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 5,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: 5,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
now := time.Now()
|
|
|
|
|
2020-11-02 15:28:51 +00:00
|
|
|
encryptedMetadata := testrand.Bytes(1024)
|
|
|
|
encryptedMetadataNonce := testrand.Nonce()
|
2020-11-16 16:46:47 +00:00
|
|
|
encryptedMetadataKey := testrand.Bytes(265)
|
2020-11-02 15:28:51 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 5,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
2022-04-14 12:20:18 +01:00
|
|
|
OverrideEncryptedMetadata: true,
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
2020-11-16 16:46:47 +00:00
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
// disallow for double commit
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 5,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
},
|
2020-11-02 17:25:58 +00:00
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: object with specified version and pending status is missing", // TODO: this error message could be better
|
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: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 5,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
2020-10-29 13:49:53 +00:00
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
2020-11-16 16:46:47 +00:00
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
2020-11-02 15:28:51 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2021-01-06 16:21:17 +00:00
|
|
|
|
2021-03-30 10:44:43 +01:00
|
|
|
t.Run("assign plain_offset", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-03-30 10:44:43 +01:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2021-03-30 10:44:43 +01:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-03-30 10:44:43 +01:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
rootPieceID := testrand.PieceID()
|
|
|
|
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2021-03-30 10:44:43 +01:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2021-03-30 10:44:43 +01:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Index: 0},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 999999,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2021-03-30 10:44:43 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2021-03-30 10:44:43 +01:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Index: 1},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 999999,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2021-03-30 10:44:43 +01:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-03-30 10:44:43 +01:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-03-30 10:44:43 +01:00
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Index: 0},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2021-03-30 10:44:43 +01:00
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 0,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2021-03-30 10:44:43 +01:00
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Index: 1},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2021-03-30 10:44:43 +01:00
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: 512,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2021-03-30 10:44:43 +01:00
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
|
|
|
SegmentCount: 2,
|
|
|
|
FixedSegmentSize: 512,
|
|
|
|
TotalPlainSize: 2 * 512,
|
|
|
|
TotalEncryptedSize: 2 * 1024,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-03-30 10:44:43 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-01-06 16:21:17 +00:00
|
|
|
t.Run("large object over 2 GB", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-01-06 16:21:17 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2021-01-06 16:21:17 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-01-06 16:21:17 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
rootPieceID := testrand.PieceID()
|
|
|
|
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
2021-10-12 14:37:12 +01:00
|
|
|
encryptedKeyNonce := testrand.Bytes(32)
|
2021-01-06 16:21:17 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2021-01-06 16:21:17 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Index: 0},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: math.MaxInt32,
|
|
|
|
PlainSize: math.MaxInt32,
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2021-01-06 16:21:17 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitSegment{
|
2021-01-06 16:21:17 +00:00
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Index: 1},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: math.MaxInt32,
|
|
|
|
PlainSize: math.MaxInt32,
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2021-01-06 16:21:17 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-01-06 16:21:17 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-01-06 16:21:17 +00:00
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
2021-03-12 17:43:30 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Index: 0},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2021-01-06 16:21:17 +00:00
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: math.MaxInt32,
|
|
|
|
PlainSize: math.MaxInt32,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2021-01-06 16:21:17 +00:00
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
{
|
2021-03-12 17:43:30 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Index: 1},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2021-01-06 16:21:17 +00:00
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce,
|
|
|
|
|
|
|
|
EncryptedSize: math.MaxInt32,
|
|
|
|
PlainSize: math.MaxInt32,
|
2021-03-30 10:44:43 +01:00
|
|
|
PlainOffset: math.MaxInt32,
|
2021-01-06 16:21:17 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2021-01-06 16:21:17 +00:00
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
|
|
|
SegmentCount: 2,
|
|
|
|
FixedSegmentSize: math.MaxInt32,
|
|
|
|
TotalPlainSize: 2 * math.MaxInt32,
|
|
|
|
TotalEncryptedSize: 2 * math.MaxInt32,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-01-06 16:21:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2021-01-14 10:24:29 +00:00
|
|
|
|
|
|
|
t.Run("commit with encryption", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-01-14 10:24:29 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2021-01-14 10:24:29 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-01-14 10:24:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: storj.EncryptionParameters{},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "Encryption is missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-01-14 10:24:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: storj.EncryptionParameters{
|
|
|
|
CipherSuite: storj.EncAESGCM,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "Encryption.BlockSize is negative or zero",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-01-14 10:24:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: storj.EncryptionParameters{
|
|
|
|
CipherSuite: storj.EncAESGCM,
|
|
|
|
BlockSize: -1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "Encryption.BlockSize is negative or zero",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-01-14 10:24:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: storj.EncryptionParameters{
|
|
|
|
CipherSuite: storj.EncAESGCM,
|
|
|
|
BlockSize: 512,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-01-14 10:24:29 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
|
|
|
SegmentCount: 0,
|
|
|
|
|
|
|
|
Encryption: storj.EncryptionParameters{
|
|
|
|
CipherSuite: storj.EncAESGCM,
|
|
|
|
BlockSize: 512,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("commit with encryption (no override)", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-01-14 10:24:29 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2021-01-14 10:24:29 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-01-14 10:24:29 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-01-14 10:24:29 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
// set different encryption than with BeginObjectExactVersion
|
|
|
|
Encryption: storj.EncryptionParameters{
|
|
|
|
CipherSuite: storj.EncNull,
|
|
|
|
BlockSize: 512,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-01-14 10:24:29 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
|
|
|
SegmentCount: 0,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-01-14 10:24:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2021-10-29 12:04:55 +01:00
|
|
|
|
|
|
|
t.Run("commit with metadata (no overwrite)", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
expectedMetadata := testrand.Bytes(memory.KiB)
|
|
|
|
expectedMetadataKey := testrand.Bytes(32)
|
|
|
|
expectedMetadataNonce := testrand.Nonce().Bytes()
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
EncryptedMetadata: expectedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: expectedMetadataKey,
|
|
|
|
EncryptedMetadataNonce: expectedMetadataNonce,
|
|
|
|
},
|
2022-04-14 12:20:18 +01:00
|
|
|
Version: metabase.DefaultVersion,
|
2021-10-29 12:04:55 +01:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
EncryptedMetadata: expectedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: expectedMetadataKey,
|
|
|
|
EncryptedMetadataNonce: expectedMetadataNonce,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("commit with metadata (overwrite)", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
expectedMetadata := testrand.Bytes(memory.KiB)
|
|
|
|
expecedMetadataKey := testrand.Bytes(32)
|
|
|
|
expecedMetadataNonce := testrand.Nonce().Bytes()
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
EncryptedMetadata: testrand.Bytes(memory.KiB),
|
|
|
|
EncryptedMetadataEncryptedKey: testrand.Bytes(32),
|
|
|
|
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
|
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
2022-04-14 12:20:18 +01:00
|
|
|
OverrideEncryptedMetadata: true,
|
2021-10-29 12:04:55 +01:00
|
|
|
EncryptedMetadata: expectedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: expecedMetadataKey,
|
|
|
|
EncryptedMetadataNonce: expecedMetadataNonce,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
EncryptedMetadata: expectedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: expecedMetadataKey,
|
|
|
|
EncryptedMetadataNonce: expecedMetadataNonce,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2022-04-14 12:20:18 +01:00
|
|
|
|
|
|
|
t.Run("commit with empty metadata (overwrite)", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
EncryptedMetadata: testrand.Bytes(memory.KiB),
|
|
|
|
EncryptedMetadataEncryptedKey: testrand.Bytes(32),
|
|
|
|
EncryptedMetadataNonce: testrand.Nonce().Bytes(),
|
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
OverrideEncryptedMetadata: true,
|
|
|
|
EncryptedMetadata: nil,
|
|
|
|
EncryptedMetadataEncryptedKey: nil,
|
|
|
|
EncryptedMetadataNonce: nil,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
}
|
2021-09-24 15:18:21 +01:00
|
|
|
|
2022-10-04 16:38:20 +01:00
|
|
|
func TestCommitObject_MultipleVersions(t *testing.T) {
|
|
|
|
metabasetest.RunWithConfig(t, metabase.Config{
|
|
|
|
ApplicationName: "satellite-test",
|
|
|
|
MinPartSize: 5 * memory.MiB,
|
|
|
|
MaxNumberOfParts: 1000,
|
|
|
|
MultipleVersions: true,
|
|
|
|
}, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
t.Run("OnDelete", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
// check deleted segments
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
_, expectedSegments := metabasetest.CreateTestObject{}.Run(ctx, t, db, obj, 3)
|
|
|
|
|
|
|
|
expectedDeletedSegments := []metabase.DeletedSegmentInfo{}
|
|
|
|
for _, segment := range expectedSegments {
|
|
|
|
expectedDeletedSegments = append(expectedDeletedSegments, metabase.DeletedSegmentInfo{
|
|
|
|
RootPieceID: segment.RootPieceID,
|
|
|
|
Pieces: segment.Pieces,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
obj.Version++
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
deletedSegments := []metabase.DeletedSegmentInfo{}
|
|
|
|
metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
OnDelete: func(segments []metabase.DeletedSegmentInfo) {
|
|
|
|
deletedSegments = append(deletedSegments, segments...)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
require.Equal(t, expectedDeletedSegments, deletedSegments)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-24 15:18:21 +01:00
|
|
|
func TestCommitObjectWithIncorrectPartSize(t *testing.T) {
|
|
|
|
metabasetest.RunWithConfig(t, metabase.Config{
|
2022-02-20 21:29:41 +00:00
|
|
|
ApplicationName: "satellite-test",
|
2021-09-24 15:18:21 +01:00
|
|
|
MinPartSize: 5 * memory.MiB,
|
|
|
|
MaxNumberOfParts: 1000,
|
|
|
|
}, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
t.Run("part size less then 5MB", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
now := time.Now()
|
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
|
|
|
|
|
|
|
rootPieceID := testrand.PieceID()
|
|
|
|
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
|
|
|
encryptedKeyNonce := testrand.Nonce()
|
|
|
|
|
|
|
|
metabasetest.CommitSegment{
|
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: 2 * memory.MiB.Int32(),
|
|
|
|
PlainSize: 2 * memory.MiB.Int32(),
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitSegment{
|
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 1, Index: 0},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: 2 * memory.MiB.Int32(),
|
|
|
|
PlainSize: 2 * memory.MiB.Int32(),
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.Error,
|
|
|
|
ErrText: "size of part number 0 is below minimum threshold, got: 2.0 MiB, min: 5.0 MiB",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: 0},
|
|
|
|
CreatedAt: now,
|
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: 2 * memory.MiB.Int32(),
|
|
|
|
PlainSize: 2 * memory.MiB.Int32(),
|
|
|
|
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Part: 1, Index: 0},
|
|
|
|
CreatedAt: now,
|
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: 2 * memory.MiB.Int32(),
|
|
|
|
PlainSize: 2 * memory.MiB.Int32(),
|
|
|
|
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("size validation with part with multiple segments", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
rootPieceID := testrand.PieceID()
|
|
|
|
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
|
|
|
encryptedKeyNonce := testrand.Nonce()
|
|
|
|
|
|
|
|
metabasetest.CommitSegment{
|
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 1, Index: 0},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: memory.MiB.Int32(),
|
|
|
|
PlainSize: memory.MiB.Int32(),
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitSegment{
|
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 1, Index: 1},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: memory.MiB.Int32(),
|
|
|
|
PlainSize: memory.MiB.Int32(),
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
|
|
|
SegmentCount: 2,
|
|
|
|
FixedSegmentSize: -1,
|
|
|
|
TotalPlainSize: 2 * memory.MiB.Int64(),
|
|
|
|
TotalEncryptedSize: 2 * memory.MiB.Int64(),
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Part: 1, Index: 0},
|
|
|
|
CreatedAt: now,
|
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: memory.MiB.Int32(),
|
|
|
|
PlainSize: memory.MiB.Int32(),
|
|
|
|
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Part: 1, Index: 1},
|
|
|
|
CreatedAt: now,
|
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: memory.MiB.Int32(),
|
|
|
|
PlainSize: memory.MiB.Int32(),
|
|
|
|
PlainOffset: memory.MiB.Int64(),
|
|
|
|
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("size validation with multiple parts", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
now := time.Now()
|
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
|
|
|
|
|
|
|
rootPieceID := testrand.PieceID()
|
|
|
|
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
|
|
|
encryptedKeyNonce := testrand.Nonce()
|
|
|
|
partsSizes := []memory.Size{6 * memory.MiB, 1 * memory.MiB, 1 * memory.MiB}
|
|
|
|
|
|
|
|
for i, size := range partsSizes {
|
|
|
|
metabasetest.CommitSegment{
|
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: uint32(i + 1), Index: 1},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: size.Int32(),
|
|
|
|
PlainSize: size.Int32(),
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
}
|
|
|
|
|
|
|
|
metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.Error,
|
|
|
|
ErrText: "size of part number 2 is below minimum threshold, got: 1.0 MiB, min: 5.0 MiB",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Part: 1, Index: 1},
|
|
|
|
CreatedAt: now,
|
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: 6 * memory.MiB.Int32(),
|
|
|
|
PlainSize: 6 * memory.MiB.Int32(),
|
|
|
|
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Part: 2, Index: 1},
|
|
|
|
CreatedAt: now,
|
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: memory.MiB.Int32(),
|
|
|
|
PlainSize: memory.MiB.Int32(),
|
|
|
|
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Part: 3, Index: 1},
|
|
|
|
CreatedAt: now,
|
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: memory.MiB.Int32(),
|
|
|
|
PlainSize: memory.MiB.Int32(),
|
|
|
|
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommitObjectWithIncorrectAmountOfParts(t *testing.T) {
|
|
|
|
metabasetest.RunWithConfig(t, metabase.Config{
|
2022-02-20 21:29:41 +00:00
|
|
|
ApplicationName: "satellite-test",
|
2021-09-24 15:18:21 +01:00
|
|
|
MinPartSize: 5 * memory.MiB,
|
|
|
|
MaxNumberOfParts: 3,
|
|
|
|
}, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
|
|
|
|
t.Run("number of parts check", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.BeginObjectExactVersion{
|
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
now := time.Now()
|
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
|
|
|
|
|
|
|
rootPieceID := testrand.PieceID()
|
|
|
|
pieces := metabase.Pieces{{Number: 0, StorageNode: testrand.NodeID()}}
|
|
|
|
encryptedKey := testrand.Bytes(32)
|
|
|
|
encryptedKeyNonce := testrand.Nonce()
|
|
|
|
|
|
|
|
var segments []metabase.RawSegment
|
|
|
|
|
|
|
|
for i := 1; i < 5; i++ {
|
|
|
|
metabasetest.CommitSegment{
|
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: uint32(i), Index: 0},
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
Pieces: pieces,
|
|
|
|
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: 6 * memory.MiB.Int32(),
|
|
|
|
PlainSize: 6 * memory.MiB.Int32(),
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
segments = append(segments, metabase.RawSegment{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{Part: uint32(i), Index: 0},
|
|
|
|
CreatedAt: now,
|
|
|
|
|
|
|
|
RootPieceID: rootPieceID,
|
|
|
|
EncryptedKey: encryptedKey,
|
|
|
|
EncryptedKeyNonce: encryptedKeyNonce[:],
|
|
|
|
|
|
|
|
EncryptedSize: 6 * memory.MiB.Int32(),
|
|
|
|
PlainSize: 6 * memory.MiB.Int32(),
|
|
|
|
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
|
|
|
|
Pieces: pieces,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
metabasetest.CommitObject{
|
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.Error,
|
|
|
|
ErrText: "exceeded maximum number of parts: 3",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: segments,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|