Skip to content

Commit

Permalink
object: Improve testing and increase coverage for Object type (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Nov 15, 2024
2 parents eb97b11 + 7d16474 commit 2da6182
Show file tree
Hide file tree
Showing 19 changed files with 3,395 additions and 305 deletions.
2 changes: 1 addition & 1 deletion client/container_statistic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func TestClientStatistic_ObjectPut(t *testing.T) {
prm.WithinSession(tokenSession)

var hdr object.Object
hdr.SetOwnerID(&usr.ID)
hdr.SetOwner(usr.ID)
hdr.SetContainerID(containerID)

writer, err := c.ObjectPutInit(ctx, hdr, usr, prm)
Expand Down
14 changes: 7 additions & 7 deletions client/object_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ func (x *PayloadReader) readHeader(dst *object.Object) bool {

x.remainingPayloadLen = int(objv2.GetHeader().GetPayloadLength())

*dst = *object.NewFromV2(&objv2) // need smth better

return true
x.err = dst.ReadFromV2(objv2)
return x.err == nil
}

func (x *PayloadReader) readChunk(buf []byte) (int, bool) {
Expand Down Expand Up @@ -404,10 +403,11 @@ func (c *Client) ObjectHead(ctx context.Context, containerID cid.ID, objectID oi
objv2.SetHeader(v.GetHeader())
objv2.SetSignature(v.GetSignature())

obj := object.NewFromV2(&objv2)
obj.SetID(objectID)

return obj, nil
var obj object.Object
if err = obj.ReadFromV2(objv2); err != nil {
return nil, fmt.Errorf("invalid header response: %w", err)
}
return &obj, nil
}
}

Expand Down
16 changes: 8 additions & 8 deletions object/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (o *Object) CalculateAndSetPayloadChecksum() {

// VerifyPayloadChecksum checks if payload checksum in the object
// corresponds to its payload.
func (o *Object) VerifyPayloadChecksum() error {
func (o Object) VerifyPayloadChecksum() error {
actual := CalculatePayloadChecksum(o.Payload())

cs, set := o.PayloadChecksum()
Expand All @@ -54,7 +54,7 @@ func (o *Object) VerifyPayloadChecksum() error {
}

// CalculateID calculates identifier for the object.
func (o *Object) CalculateID() (oid.ID, error) {
func (o Object) CalculateID() (oid.ID, error) {
return sha256.Sum256(o.ToV2().GetHeader().StableMarshal(nil)), nil
}

Expand All @@ -73,7 +73,7 @@ func (o *Object) CalculateAndSetID() error {

// VerifyID checks if identifier in the object corresponds to
// its structure.
func (o *Object) VerifyID() error {
func (o Object) VerifyID() error {
id, err := o.CalculateID()
if err != nil {
return err
Expand Down Expand Up @@ -113,13 +113,13 @@ func (o *Object) Sign(signer neofscrypto.Signer) error {
// SignedData returns actual payload to sign.
//
// See also [Object.Sign].
func (o *Object) SignedData() []byte {
func (o Object) SignedData() []byte {
return o.GetID().Marshal()
}

// VerifySignature verifies object ID signature.
func (o *Object) VerifySignature() bool {
m := (*object.Object)(o)
func (o Object) VerifySignature() bool {
m := (*object.Object)(&o)

sigV2 := m.GetSignature()
if sigV2 == nil {
Expand Down Expand Up @@ -157,7 +157,7 @@ func (o *Object) SetVerificationFields(signer neofscrypto.Signer) error {
}

// CheckVerificationFields checks all verification fields of the object.
func (o *Object) CheckVerificationFields() error {
func (o Object) CheckVerificationFields() error {
if err := o.CheckHeaderVerificationFields(); err != nil {
return fmt.Errorf("invalid header structure: %w", err)
}
Expand All @@ -172,7 +172,7 @@ func (o *Object) CheckVerificationFields() error {
var errInvalidSignature = errors.New("invalid signature")

// CheckHeaderVerificationFields checks all verification fields except payload.
func (o *Object) CheckHeaderVerificationFields() error {
func (o Object) CheckHeaderVerificationFields() error {
if !o.VerifySignature() {
return errInvalidSignature
}
Expand Down
Loading

0 comments on commit 2da6182

Please sign in to comment.