2021-07-02 15:12:43 +01:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metabase_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2022-08-12 18:52:02 +01:00
|
|
|
"storj.io/common/uuid"
|
2021-07-02 15:12:43 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
|
|
|
"storj.io/storj/satellite/metabase/metabasetest"
|
|
|
|
)
|
|
|
|
|
2021-07-08 15:50:37 +01:00
|
|
|
func TestUpdateObjectMetadata(t *testing.T) {
|
2021-07-02 15:12:43 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
|
|
|
now := time.Now()
|
2022-08-12 18:52:02 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2021-07-02 15:12:43 +01:00
|
|
|
|
2022-08-12 18:52:02 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectLocations(obj.Location()) {
|
2021-07-02 15:12:43 +01:00
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-07-08 15:50:37 +01:00
|
|
|
metabasetest.UpdateObjectMetadata{
|
|
|
|
Opts: metabase.UpdateObjectMetadata{
|
2022-08-12 18:52:02 +01:00
|
|
|
ProjectID: test.ObjectLocation.ProjectID,
|
|
|
|
BucketName: test.ObjectLocation.BucketName,
|
|
|
|
ObjectKey: test.ObjectLocation.ObjectKey,
|
2021-07-02 15:12:43 +01:00
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-08-12 18:52:02 +01:00
|
|
|
t.Run("StreamID missing", func(t *testing.T) {
|
2021-07-08 15:50:37 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.UpdateObjectMetadata{
|
|
|
|
Opts: metabase.UpdateObjectMetadata{
|
2022-08-12 18:52:02 +01:00
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
StreamID: uuid.UUID{},
|
2021-07-08 15:50:37 +01:00
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
2022-08-12 18:52:02 +01:00
|
|
|
ErrText: "StreamID missing",
|
2021-07-08 15:50:37 +01:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2022-08-12 18:52:02 +01:00
|
|
|
t.Run("Metadata missing", func(t *testing.T) {
|
2021-07-02 15:12:43 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
2021-07-08 15:50:37 +01:00
|
|
|
metabasetest.UpdateObjectMetadata{
|
|
|
|
Opts: metabase.UpdateObjectMetadata{
|
2022-08-12 18:52:02 +01:00
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
StreamID: obj.StreamID,
|
2021-07-02 15:12:43 +01:00
|
|
|
},
|
2023-04-19 10:54:16 +01:00
|
|
|
ErrClass: &metabase.ErrObjectNotFound,
|
2022-08-12 18:52:02 +01:00
|
|
|
ErrText: "object with specified version and committed status is missing",
|
2021-07-02 15:12:43 +01:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Update metadata", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.CreateTestObject{}.Run(ctx, t, db, obj, 0)
|
|
|
|
|
|
|
|
encryptedMetadata := testrand.Bytes(1024)
|
|
|
|
encryptedMetadataNonce := testrand.Nonce()
|
|
|
|
encryptedMetadataKey := testrand.Bytes(265)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-07-08 15:50:37 +01:00
|
|
|
metabasetest.UpdateObjectMetadata{
|
|
|
|
Opts: metabase.UpdateObjectMetadata{
|
2022-08-12 18:52:02 +01:00
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
StreamID: obj.StreamID,
|
2021-07-02 15:12:43 +01:00
|
|
|
EncryptedMetadata: encryptedMetadata,
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
2021-07-02 15:12:43 +01:00
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
EncryptedMetadata: encryptedMetadata,
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
2021-07-02 15:12:43 +01:00
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2022-08-12 18:52:02 +01:00
|
|
|
|
|
|
|
t.Run("Update metadata with version != 1", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
newObj := metabasetest.RandObjectStream()
|
|
|
|
metabasetest.CreatePendingObject(ctx, t, db, newObj, 0)
|
|
|
|
|
|
|
|
newObjDiffVersion := newObj
|
2023-09-15 17:30:47 +01:00
|
|
|
newObjDiffVersion.Version = newObj.Version + 10000
|
2022-08-12 18:52:02 +01:00
|
|
|
metabasetest.CreateTestObject{}.Run(ctx, t, db, newObjDiffVersion, 0)
|
|
|
|
|
|
|
|
encryptedMetadata := testrand.Bytes(1024)
|
|
|
|
encryptedMetadataNonce := testrand.Nonce()
|
|
|
|
encryptedMetadataKey := testrand.Bytes(265)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: newObj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: newObjDiffVersion,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.UpdateObjectMetadata{
|
|
|
|
Opts: metabase.UpdateObjectMetadata{
|
|
|
|
ProjectID: newObj.ProjectID,
|
|
|
|
BucketName: newObj.BucketName,
|
|
|
|
ObjectKey: newObj.ObjectKey,
|
|
|
|
StreamID: newObj.StreamID,
|
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.Verify{
|
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: newObj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: newObjDiffVersion,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
|
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
2021-07-02 15:12:43 +01:00
|
|
|
})
|
|
|
|
}
|