[#19] transformer/test: Check owner ID and payload hash for parts

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-02-24 16:21:56 +03:00 committed by Gitea
parent eba6831125
commit 611e20587b

View file

@ -2,11 +2,13 @@ package transformer
import ( import (
"crypto/rand" "crypto/rand"
"crypto/sha256"
"testing" "testing"
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id" cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
cidtest "github.com/TrueCloudLab/frostfs-sdk-go/container/id/test" cidtest "github.com/TrueCloudLab/frostfs-sdk-go/container/id/test"
objectSDK "github.com/TrueCloudLab/frostfs-sdk-go/object" objectSDK "github.com/TrueCloudLab/frostfs-sdk-go/object"
"github.com/TrueCloudLab/frostfs-sdk-go/user"
"github.com/TrueCloudLab/frostfs-sdk-go/version" "github.com/TrueCloudLab/frostfs-sdk-go/version"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -17,11 +19,15 @@ func TestTransformer(t *testing.T) {
tt := new(testTarget) tt := new(testTarget)
target, _ := newPayloadSizeLimiter(maxSize, tt) target, pk := newPayloadSizeLimiter(maxSize, tt)
cnr := cidtest.ID() cnr := cidtest.ID()
hdr := newObject(cnr) hdr := newObject(cnr)
var owner user.ID
user.IDFromKey(&owner, pk.PrivateKey.PublicKey)
hdr.SetOwnerID(&owner)
expectedPayload := make([]byte, maxSize*2+maxSize/2) expectedPayload := make([]byte, maxSize*2+maxSize/2)
_, _ = rand.Read(expectedPayload) _, _ = rand.Read(expectedPayload)
@ -34,11 +40,20 @@ func TestTransformer(t *testing.T) {
require.True(t, ok) require.True(t, ok)
require.Equal(t, cnr, childCnr) require.Equal(t, cnr, childCnr)
require.Equal(t, objectSDK.TypeRegular, tt.objects[i].Type()) require.Equal(t, objectSDK.TypeRegular, tt.objects[i].Type())
require.Equal(t, &owner, tt.objects[i].OwnerID())
payload := tt.objects[i].Payload() payload := tt.objects[i].Payload()
require.EqualValues(t, tt.objects[i].PayloadSize(), len(payload)) require.EqualValues(t, tt.objects[i].PayloadSize(), len(payload))
actualPayload = append(actualPayload, payload...) actualPayload = append(actualPayload, payload...)
if len(payload) != 0 {
cs, ok := tt.objects[i].PayloadChecksum()
require.True(t, ok)
h := sha256.Sum256(payload)
require.Equal(t, h[:], cs.Value())
}
switch i { switch i {
case 0, 1: case 0, 1:
require.EqualValues(t, maxSize, len(payload)) require.EqualValues(t, maxSize, len(payload))
@ -51,6 +66,14 @@ func TestTransformer(t *testing.T) {
} }
} }
require.Equal(t, expectedPayload, actualPayload) require.Equal(t, expectedPayload, actualPayload)
t.Run("parent checksum", func(t *testing.T) {
cs, ok := ids.ParentHeader.PayloadChecksum()
require.True(t, ok)
h := sha256.Sum256(expectedPayload)
require.Equal(t, h[:], cs.Value())
})
} }
func newObject(cnr cid.ID) *objectSDK.Object { func newObject(cnr cid.ID) *objectSDK.Object {