From 68178b8d74514dd650193a182775a2153259c350 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 29 Sep 2020 19:40:25 +0300 Subject: [PATCH] [#57] core/object: Fix validation of linking object Linking object carries only identifier of the parent object. Fix Validate method of FormatValidator to not validate parent object of the linking object. Signed-off-by: Leonard Lyubich --- pkg/core/object/fmt.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/core/object/fmt.go b/pkg/core/object/fmt.go index c0e8102ed..7d1bfc9f0 100644 --- a/pkg/core/object/fmt.go +++ b/pkg/core/object/fmt.go @@ -35,14 +35,19 @@ func (v *FormatValidator) Validate(obj *Object) error { return errNilCID } - for ; obj.GetID() != nil; obj = NewFromSDK(obj.GetParent()) { - if err := v.validateSignatureKey(obj); err != nil { - return errors.Wrapf(err, "(%T) could not validate signature key", v) - } + if err := v.validateSignatureKey(obj); err != nil { + return errors.Wrapf(err, "(%T) could not validate signature key", v) + } - if err := object.CheckHeaderVerificationFields(obj.SDK()); err != nil { - return errors.Wrapf(err, "(%T) could not validate header fields", v) - } + if err := object.CheckHeaderVerificationFields(obj.SDK()); err != nil { + return errors.Wrapf(err, "(%T) could not validate header fields", v) + } + + par := NewFromSDK(obj.GetParent()) + + // validate parent object header + if par.GetID() != nil && len(obj.GetChildren()) == 0 { + return v.Validate(par) } return nil