From 07de839f1819d186b1b001c30588df0d2dbb0cd6 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 9 Mar 2023 09:54:12 +0300 Subject: [PATCH] [#85] get-service: Fix corrupted chain logic Should return an error in case of a broken LOB reference chain. Signed-off-by: Dmitrii Stepanov --- pkg/services/object/get/assemble.go | 3 +++ pkg/services/object/get/exec.go | 4 ++++ pkg/services/object/get/get_test.go | 27 ++++++++++++--------------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pkg/services/object/get/assemble.go b/pkg/services/object/get/assemble.go index 991952901..b6e1c4fb7 100644 --- a/pkg/services/object/get/assemble.go +++ b/pkg/services/object/get/assemble.go @@ -1,6 +1,8 @@ package getsvc import ( + "errors" + apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -90,6 +92,7 @@ func (exec *execCtx) initFromChild(obj oid.ID) (prev *oid.ID, children []oid.ID) par := child.Parent() if par == nil { exec.status = statusUndefined + exec.err = errors.New("received child with empty parent") log.Debug("received child with empty parent") diff --git a/pkg/services/object/get/exec.go b/pkg/services/object/get/exec.go index 26f607a15..505ff043c 100644 --- a/pkg/services/object/get/exec.go +++ b/pkg/services/object/get/exec.go @@ -220,6 +220,8 @@ func (exec *execCtx) getChild(id oid.ID, rng *objectSDK.Range, withHdr bool) (*o exec.err = errors.New("wrong child header") exec.log.Debug("parent address in child object differs") + + return nil, false } return child, ok @@ -256,8 +258,10 @@ func (exec *execCtx) headChild(id oid.ID) (*objectSDK.Object, bool) { if !exec.isChild(child) { exec.status = statusUndefined + exec.err = errors.New("parent address in child object differs") exec.log.Debug("parent address in child object differs") + return nil, false } else { exec.status = statusOK exec.err = nil diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index ed2395271..8329a82a7 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -1094,8 +1094,8 @@ func TestGetRemoteSmall(t *testing.T) { p.WithAddress(addr) err := svc.Get(ctx, p) - require.NoError(t, err) //TODO fix me - //require.Equal(t, err.Error(), "wrong child header") + require.Error(t, err) + require.Equal(t, err.Error(), "wrong child header") w = NewSimpleObjectWriter() payloadSz := srcObj.PayloadSize() @@ -1107,9 +1107,8 @@ func TestGetRemoteSmall(t *testing.T) { rngPrm.WithAddress(addr) err = svc.GetRange(ctx, rngPrm) - require.ErrorAs(t, err, new(*apistatus.ObjectOutOfRange)) //TODO fix me - //require.Equal(t, err.Error(), "wrong child header") - + require.Error(t, err) + require.Equal(t, err.Error(), "wrong child header") }) t.Run("linked object with parent udefined", func(t *testing.T) { @@ -1180,8 +1179,8 @@ func TestGetRemoteSmall(t *testing.T) { p.WithAddress(addr) err := svc.Get(ctx, p) - require.NoError(t, err) //TODO fix me - //require.Equal(t, err.Error(), "received child with empty parent") + require.Error(t, err) + require.Equal(t, err.Error(), "received child with empty parent") w = NewSimpleObjectWriter() payloadSz := srcObj.PayloadSize() @@ -1193,8 +1192,8 @@ func TestGetRemoteSmall(t *testing.T) { rngPrm.WithAddress(addr) err = svc.GetRange(ctx, rngPrm) - require.NoError(t, err) //TODO fix me - //require.Equal(t, err.Error(), "received child with empty parent") + require.Error(t, err) + require.Equal(t, err.Error(), "received child with empty parent") }) t.Run("out of range", func(t *testing.T) { @@ -1465,9 +1464,8 @@ func TestGetRemoteSmall(t *testing.T) { p.WithAddress(addr) err := svc.Get(ctx, p) - require.NoError(t, err) //TODO fix me, it must be an error, corrupted chain - //require.Equal(t, err.Error(), "parent address in child object differs") - require.Equal(t, srcObj, w.Object()) + require.Error(t, err) + require.Equal(t, err.Error(), "parent address in child object differs") w = NewSimpleObjectWriter() payloadSz := srcObj.PayloadSize() @@ -1479,9 +1477,8 @@ func TestGetRemoteSmall(t *testing.T) { rngPrm.WithAddress(addr) err = svc.GetRange(ctx, rngPrm) - require.NoError(t, err) //TODO fix me, it must be an error, corrupted chain - //require.Equal(t, err.Error(), "parent address in child object differs") - require.Equal(t, payload[off:off+ln], w.Object().Payload()) + require.Error(t, err) + require.Equal(t, err.Error(), "parent address in child object differs") }) t.Run("OK", func(t *testing.T) {