forked from TrueCloudLab/frostfs-api-go
accounting: implement SignedDataSource on BalanceRequest message
This commit is contained in:
parent
b6e6aa7238
commit
b9d30d6138
4 changed files with 106 additions and 0 deletions
54
accounting/sign_test.go
Normal file
54
accounting/sign_test.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
package accounting
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/service"
|
||||
"github.com/nspcc-dev/neofs-crypto/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSignBalanceRequest(t *testing.T) {
|
||||
// create test OwnerID
|
||||
ownerID := OwnerID{1, 2, 3}
|
||||
|
||||
// create test BalanceRequest
|
||||
req := new(BalanceRequest)
|
||||
req.SetOwnerID(ownerID)
|
||||
|
||||
// create test private key
|
||||
sk := test.DecodeKey(0)
|
||||
|
||||
items := []struct {
|
||||
corrupt func()
|
||||
restore func()
|
||||
}{
|
||||
{
|
||||
corrupt: func() {
|
||||
ownerID[0]++
|
||||
req.SetOwnerID(ownerID)
|
||||
},
|
||||
restore: func() {
|
||||
ownerID[0]--
|
||||
req.SetOwnerID(ownerID)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, item := range items {
|
||||
// sign with private key
|
||||
require.NoError(t, service.AddSignatureWithKey(sk, req))
|
||||
|
||||
// ascertain that verification is passed
|
||||
require.NoError(t, service.VerifyAccumulatedSignatures(req))
|
||||
|
||||
// corrupt the request
|
||||
item.corrupt()
|
||||
|
||||
// ascertain that verification is failed
|
||||
require.Error(t, service.VerifyAccumulatedSignatures(req))
|
||||
|
||||
// ascertain that request
|
||||
item.restore()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue