From 611e20587b49b6e6d059babceb484275b9491a73 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 24 Feb 2023 16:21:56 +0300 Subject: [PATCH] [#19] transformer/test: Check owner ID and payload hash for parts Signed-off-by: Evgenii Stratonikov --- object/transformer/transformer_test.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/object/transformer/transformer_test.go b/object/transformer/transformer_test.go index f1f67221..2b4ee31c 100644 --- a/object/transformer/transformer_test.go +++ b/object/transformer/transformer_test.go @@ -2,11 +2,13 @@ package transformer import ( "crypto/rand" + "crypto/sha256" "testing" cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id" cidtest "github.com/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "github.com/TrueCloudLab/frostfs-sdk-go/object" + "github.com/TrueCloudLab/frostfs-sdk-go/user" "github.com/TrueCloudLab/frostfs-sdk-go/version" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/stretchr/testify/require" @@ -17,11 +19,15 @@ func TestTransformer(t *testing.T) { tt := new(testTarget) - target, _ := newPayloadSizeLimiter(maxSize, tt) + target, pk := newPayloadSizeLimiter(maxSize, tt) cnr := cidtest.ID() hdr := newObject(cnr) + var owner user.ID + user.IDFromKey(&owner, pk.PrivateKey.PublicKey) + hdr.SetOwnerID(&owner) + expectedPayload := make([]byte, maxSize*2+maxSize/2) _, _ = rand.Read(expectedPayload) @@ -34,11 +40,20 @@ func TestTransformer(t *testing.T) { require.True(t, ok) require.Equal(t, cnr, childCnr) require.Equal(t, objectSDK.TypeRegular, tt.objects[i].Type()) + require.Equal(t, &owner, tt.objects[i].OwnerID()) payload := tt.objects[i].Payload() require.EqualValues(t, tt.objects[i].PayloadSize(), len(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 { case 0, 1: require.EqualValues(t, maxSize, len(payload)) @@ -51,6 +66,14 @@ func TestTransformer(t *testing.T) { } } 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 {