forked from TrueCloudLab/frostfs-api-go
Merge pull request #83 from nspcc-dev/object-fix-headrequest-signed-data
object: fix signed payload calculation of HeadRequest message
This commit is contained in:
commit
ba27e296c3
3 changed files with 39 additions and 0 deletions
|
@ -82,6 +82,8 @@ func (m HeadRequest) ReadSignedData(p []byte) (int, error) {
|
|||
|
||||
if m.GetFullHeaders() {
|
||||
p[0] = 1
|
||||
} else {
|
||||
p[0] = 0
|
||||
}
|
||||
|
||||
off := 1
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package object
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/service"
|
||||
|
@ -187,3 +188,34 @@ func TestSignVerifyRequests(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeadRequest_ReadSignedData(t *testing.T) {
|
||||
t.Run("full headers", func(t *testing.T) {
|
||||
req := new(HeadRequest)
|
||||
|
||||
// unset FullHeaders flag
|
||||
req.SetFullHeaders(false)
|
||||
|
||||
// allocate two different buffers for reading
|
||||
buf1 := testData(t, req.SignedDataSize())
|
||||
buf2 := testData(t, req.SignedDataSize())
|
||||
|
||||
// read to both buffers
|
||||
n1, err := req.ReadSignedData(buf1)
|
||||
require.NoError(t, err)
|
||||
|
||||
n2, err := req.ReadSignedData(buf2)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, buf1[:n1], buf2[:n2])
|
||||
})
|
||||
}
|
||||
|
||||
func testData(t *testing.T, sz int) []byte {
|
||||
data := make([]byte, sz)
|
||||
|
||||
_, err := rand.Read(data)
|
||||
require.NoError(t, err)
|
||||
|
||||
return data
|
||||
}
|
||||
|
|
|
@ -386,3 +386,8 @@ func Stringify(dst io.Writer, obj *Object) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetFullHeaders is a FullHeaders field setter.
|
||||
func (m *HeadRequest) SetFullHeaders(v bool) {
|
||||
m.FullHeaders = v
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue