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/storj"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
|
|
|
"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()
|
|
|
|
|
2021-07-08 15:50:37 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectStreams(obj) {
|
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{
|
|
|
|
ObjectStream: test.ObjectStream,
|
2021-07-02 15:12:43 +01:00
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:50:37 +01:00
|
|
|
t.Run("Version invalid", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
metabasetest.UpdateObjectMetadata{
|
|
|
|
Opts: metabase.UpdateObjectMetadata{
|
|
|
|
ObjectStream: metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 0,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "Version invalid: 0",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
2021-07-02 15:12:43 +01:00
|
|
|
t.Run("Object missing", func(t *testing.T) {
|
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
|
2021-07-08 15:50:37 +01:00
|
|
|
metabasetest.UpdateObjectMetadata{
|
|
|
|
Opts: metabase.UpdateObjectMetadata{
|
|
|
|
ObjectStream: obj,
|
2021-07-02 15:12:43 +01:00
|
|
|
},
|
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
2021-07-08 15:50:37 +01:00
|
|
|
ErrText: "metabase: 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{
|
|
|
|
ObjectStream: obj,
|
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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|