forked from TrueCloudLab/frostfs-node
[#633] object: Disallow empty attribute values
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>
This commit is contained in:
parent
01dd17e30a
commit
25391111ad
2 changed files with 21 additions and 2 deletions
|
@ -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()
|
||||
|
@ -245,6 +248,10 @@ func (v *FormatValidator) checkAttributes(obj *Object) error {
|
|||
return errDuplAttr
|
||||
}
|
||||
|
||||
if a.Value() == "" {
|
||||
return errEmptyAttrVal
|
||||
}
|
||||
|
||||
mUnique[key] = struct{}{}
|
||||
}
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ func TestFormatValidator_Validate(t *testing.T) {
|
|||
|
||||
t.Run("attributes", func(t *testing.T) {
|
||||
t.Run("duplication", func(t *testing.T) {
|
||||
obj := blankValidObject(t, ownerKey)
|
||||
obj := blankValidObject(t, &ownerKey.PrivateKey)
|
||||
|
||||
a1 := object.NewAttribute()
|
||||
a1.SetKey("key1")
|
||||
|
@ -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.PrivateKey)
|
||||
|
||||
a := object.NewAttribute()
|
||||
a.SetKey("key")
|
||||
|
||||
obj.SetAttributes(a)
|
||||
|
||||
err := v.checkAttributes(obj.Object())
|
||||
require.Equal(t, errEmptyAttrVal, err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue