[#58] core/object: Add content validation to FormatValidator

Add content validation step to FormatValidator. Check tombstone payload
correctness.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-09-30 14:07:28 +03:00 committed by Alex Vanin
parent 017afbf0e3
commit 107f3097e4
2 changed files with 73 additions and 11 deletions

View file

@ -35,6 +35,10 @@ func (v *FormatValidator) Validate(obj *Object) error {
return errNilCID
}
if err := v.validateContent(obj.GetType(), obj.GetPayload()); err != nil {
return errors.Wrapf(err, "(%T) incorrect content", v)
}
if err := v.validateSignatureKey(obj); err != nil {
return errors.Wrapf(err, "(%T) could not validate signature key", v)
}
@ -83,3 +87,23 @@ func (v *FormatValidator) checkOwnerKey(id *owner.ID, key []byte) error {
return nil
}
func (v *FormatValidator) validateContent(t object.Type, payload []byte) error {
switch t {
case object.TypeTombstone:
if len(payload) == 0 {
return errors.Errorf("(%T) empty payload in tombstone", v)
}
addr, err := object.AddressFromBytes(payload)
if err != nil {
return errors.Wrapf(err, "(%T) could not parse object address from tombstone", v)
}
if addr.GetContainerID() == nil || addr.GetObjectID() == nil {
return errors.Errorf("(%T) empty address reference in tombstone", v)
}
}
return nil
}