Compare commits
1 commit
master
...
bugfix/110
Author | SHA1 | Date | |
---|---|---|---|
45f8630deb |
2 changed files with 28 additions and 30 deletions
|
@ -124,15 +124,22 @@ func (v *FormatValidator) Validate(ctx context.Context, obj *objectSDK.Object, u
|
||||||
return fmt.Errorf("invalid attributes: %w", err)
|
return fmt.Errorf("invalid attributes: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exp, err := expirationEpochAttribute(obj)
|
||||||
|
if err != nil {
|
||||||
|
if !errors.Is(err, errNoExpirationEpoch) {
|
||||||
|
return fmt.Errorf("object did not pass expiration check: %w", err)
|
||||||
|
}
|
||||||
|
} else if !unprepared && exp < v.netState.CurrentEpoch() {
|
||||||
|
if err := v.checkIfExpired(ctx, obj); err != nil {
|
||||||
|
return fmt.Errorf("object did not pass expiration check: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !unprepared {
|
if !unprepared {
|
||||||
if err := v.validateSignatureKey(obj); err != nil {
|
if err := v.validateSignatureKey(obj); err != nil {
|
||||||
return fmt.Errorf("(%T) could not validate signature key: %w", v, err)
|
return fmt.Errorf("(%T) could not validate signature key: %w", v, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := v.checkExpiration(ctx, obj); err != nil {
|
|
||||||
return fmt.Errorf("object did not pass expiration check: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := objectSDK.CheckHeaderVerificationFields(obj); err != nil {
|
if err := objectSDK.CheckHeaderVerificationFields(obj); err != nil {
|
||||||
return fmt.Errorf("(%T) could not validate header fields: %w", v, err)
|
return fmt.Errorf("(%T) could not validate header fields: %w", v, err)
|
||||||
}
|
}
|
||||||
|
@ -348,17 +355,7 @@ func (v *FormatValidator) fillAndValidateTombstoneMeta(o *objectSDK.Object, meta
|
||||||
|
|
||||||
var errExpired = errors.New("object has expired")
|
var errExpired = errors.New("object has expired")
|
||||||
|
|
||||||
func (v *FormatValidator) checkExpiration(ctx context.Context, obj *objectSDK.Object) error {
|
func (v *FormatValidator) checkIfExpired(ctx context.Context, obj *objectSDK.Object) error {
|
||||||
exp, err := expirationEpochAttribute(obj)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, errNoExpirationEpoch) {
|
|
||||||
return nil // objects without expiration attribute are valid
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if exp < v.netState.CurrentEpoch() {
|
|
||||||
// an object could be expired but locked;
|
// an object could be expired but locked;
|
||||||
// put such an object is a correct operation
|
// put such an object is a correct operation
|
||||||
|
|
||||||
|
@ -377,7 +374,6 @@ func (v *FormatValidator) checkExpiration(ctx context.Context, obj *objectSDK.Ob
|
||||||
if !locked {
|
if !locked {
|
||||||
return errExpired
|
return errExpired
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,6 +195,8 @@ func TestFormatValidator_Validate(t *testing.T) {
|
||||||
val := "text"
|
val := "text"
|
||||||
err := v.Validate(context.Background(), fn(val), false)
|
err := v.Validate(context.Background(), fn(val), false)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
err = v.Validate(context.Background(), fn(val), true)
|
||||||
|
require.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("expired object", func(t *testing.T) {
|
t.Run("expired object", func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue