2020-05-11 13:05:41 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/service"
|
|
|
|
"github.com/nspcc-dev/neofs-crypto/test"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRequestSign(t *testing.T) {
|
|
|
|
sk := test.DecodeKey(0)
|
|
|
|
|
|
|
|
type sigType interface {
|
2020-06-10 17:22:34 +00:00
|
|
|
service.RequestData
|
2020-05-11 13:05:41 +00:00
|
|
|
service.SignKeyPairAccumulator
|
|
|
|
service.SignKeyPairSource
|
|
|
|
SetToken(*service.Token)
|
|
|
|
}
|
|
|
|
|
|
|
|
items := []struct {
|
|
|
|
constructor func() sigType
|
|
|
|
payloadCorrupt []func(sigType)
|
|
|
|
}{
|
|
|
|
{ // NetmapRequest
|
|
|
|
constructor: func() sigType {
|
|
|
|
return new(NetmapRequest)
|
|
|
|
},
|
|
|
|
},
|
2020-05-11 13:11:17 +00:00
|
|
|
{ // MetricsRequest
|
|
|
|
constructor: func() sigType {
|
|
|
|
return new(MetricsRequest)
|
|
|
|
},
|
|
|
|
},
|
2020-05-11 13:12:49 +00:00
|
|
|
{ // HealthRequest
|
|
|
|
constructor: func() sigType {
|
|
|
|
return new(HealthRequest)
|
|
|
|
},
|
|
|
|
},
|
2020-05-11 13:15:31 +00:00
|
|
|
{ // DumpRequest
|
|
|
|
constructor: func() sigType {
|
|
|
|
return new(DumpRequest)
|
|
|
|
},
|
|
|
|
},
|
2020-05-11 13:16:54 +00:00
|
|
|
{ // DumpVarsRequest
|
|
|
|
constructor: func() sigType {
|
|
|
|
return new(DumpVarsRequest)
|
|
|
|
},
|
|
|
|
},
|
2020-05-11 13:31:39 +00:00
|
|
|
{
|
|
|
|
constructor: func() sigType {
|
|
|
|
return new(ChangeStateRequest)
|
|
|
|
},
|
|
|
|
payloadCorrupt: []func(sigType){
|
|
|
|
func(s sigType) {
|
|
|
|
req := s.(*ChangeStateRequest)
|
|
|
|
|
|
|
|
req.SetState(req.GetState() + 1)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-05-11 13:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range items {
|
|
|
|
{ // token corruptions
|
|
|
|
v := item.constructor()
|
|
|
|
|
|
|
|
token := new(service.Token)
|
|
|
|
v.SetToken(token)
|
|
|
|
|
2020-06-10 17:22:34 +00:00
|
|
|
require.NoError(t, service.SignRequestData(sk, v))
|
2020-05-11 13:05:41 +00:00
|
|
|
|
2020-06-10 17:22:34 +00:00
|
|
|
require.NoError(t, service.VerifyRequestData(v))
|
2020-05-11 13:05:41 +00:00
|
|
|
|
|
|
|
token.SetSessionKey(append(token.GetSessionKey(), 1))
|
|
|
|
|
2020-06-10 17:22:34 +00:00
|
|
|
require.Error(t, service.VerifyRequestData(v))
|
2020-05-11 13:05:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // payload corruptions
|
|
|
|
for _, corruption := range item.payloadCorrupt {
|
|
|
|
v := item.constructor()
|
|
|
|
|
2020-06-10 17:22:34 +00:00
|
|
|
require.NoError(t, service.SignRequestData(sk, v))
|
2020-05-11 13:05:41 +00:00
|
|
|
|
2020-06-10 17:22:34 +00:00
|
|
|
require.NoError(t, service.VerifyRequestData(v))
|
2020-05-11 13:05:41 +00:00
|
|
|
|
|
|
|
corruption(v)
|
|
|
|
|
2020-06-10 17:22:34 +00:00
|
|
|
require.Error(t, service.VerifyRequestData(v))
|
2020-05-11 13:05:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|