Skip to content

Commit

Permalink
[nspcc-dev#633] object: Disallow empty attribute values
Browse files Browse the repository at this point in the history
Values of object attributes must not be empty according to NeoFS
specification.

Make `FormatValidator.Validate` method to return an error if at least one
attribute has empty value.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
  • Loading branch information
Leonard Lyubich committed Jun 23, 2021
1 parent 7fa93d3 commit 651cff8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/core/object/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ func expirationEpochAttribute(obj *Object) (uint64, error) {
return 0, errNoExpirationEpoch
}

var errDuplAttr = errors.New("duplication of attributes detected")
var (
errDuplAttr = errors.New("duplication of attributes detected")
errEmptyAttrVal = errors.New("empty attribute value")
)

func (v *FormatValidator) checkAttributes(obj *Object) error {
as := obj.Attributes()
Expand All @@ -245,6 +248,11 @@ func (v *FormatValidator) checkAttributes(obj *Object) error {
return errDuplAttr
}

val := a.Value()
if val == "" {
return errEmptyAttrVal
}

mUnique[key] = struct{}{}
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/core/object/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,17 @@ func TestFormatValidator_Validate(t *testing.T) {
err = v.checkAttributes(obj.Object())
require.Equal(t, errDuplAttr, err)
})

t.Run("empty value", func(t *testing.T) {
obj := blankValidObject(t, ownerKey)

a := object.NewAttribute()
a.SetKey("key")

obj.SetAttributes(a)

err := v.checkAttributes(obj.Object())
require.Equal(t, errEmptyAttrVal, err)
})
})
}

0 comments on commit 651cff8

Please sign in to comment.