diff --git a/pkg/core/object/fmt.go b/pkg/core/object/fmt.go index 54452d95..36ea25f9 100644 --- a/pkg/core/object/fmt.go +++ b/pkg/core/object/fmt.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/owner" + "github.com/nspcc-dev/neofs-api-go/pkg/storagegroup" crypto "github.com/nspcc-dev/neofs-crypto" "github.com/pkg/errors" ) @@ -140,6 +141,22 @@ func (v *FormatValidator) ValidateContent(o *Object) error { if v.deleteHandler != nil { v.deleteHandler.DeleteObjects(o.Address(), addrList...) } + case object.TypeStorageGroup: + if len(o.Payload()) == 0 { + return errors.Errorf("(%T) empty payload in SG", v) + } + + sg := storagegroup.New() + + if err := sg.Unmarshal(o.Payload()); err != nil { + return errors.Wrapf(err, "(%T) could not unmarshal SG content", v) + } + + for _, id := range sg.Members() { + if id == nil { + return errors.Errorf("(%T) empty member in SG", v) + } + } } return nil diff --git a/pkg/core/object/fmt_test.go b/pkg/core/object/fmt_test.go index 8c2941a3..6ce4b4f1 100644 --- a/pkg/core/object/fmt_test.go +++ b/pkg/core/object/fmt_test.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/owner" + "github.com/nspcc-dev/neofs-api-go/pkg/storagegroup" "github.com/nspcc-dev/neofs-api-go/pkg/token" crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-node/pkg/util/test" @@ -129,4 +130,30 @@ func TestFormatValidator_Validate(t *testing.T) { require.NoError(t, v.ValidateContent(obj.Object())) }) + + t.Run("storage group content", func(t *testing.T) { + obj := NewRaw() + obj.SetType(object.TypeStorageGroup) + + require.Error(t, v.ValidateContent(obj.Object())) + + content := storagegroup.New() + content.SetMembers([]*object.ID{nil}) + + data, err := content.Marshal() + require.NoError(t, err) + + obj.SetPayload(data) + + require.Error(t, v.ValidateContent(obj.Object())) + + content.SetMembers([]*object.ID{testObjectID(t)}) + + data, err = content.Marshal() + require.NoError(t, err) + + obj.SetPayload(data) + + require.NoError(t, v.ValidateContent(obj.Object())) + }) }