More info in receipt errors and change tests
This commit is contained in:
parent
ab74809973
commit
ac79c0c15c
@ -3,6 +3,7 @@ package coordinatorproto
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/anytypeio/any-sync/util/crypto"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"golang.org/x/exp/slices"
|
||||
@ -11,7 +12,7 @@ import (
|
||||
|
||||
var (
|
||||
errReceiptSignatureIncorrect = errors.New("receipt signature is incorrect")
|
||||
errNoSuchCoordinatorNode = errors.New("no such control node")
|
||||
errNoSuchCoordinatorNode = errors.New("no such coordinator node")
|
||||
errReceiptSpaceIdIncorrect = errors.New("receipt space id is incorrect")
|
||||
errReceiptPeerIdIncorrect = errors.New("receipt peer id is incorrect")
|
||||
errReceiptAccountIncorrect = errors.New("receipt account is incorrect")
|
||||
@ -90,8 +91,9 @@ func checkCoordinator(coordinators []string, identity []byte, payload, signature
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
receiptCoordinator := coordinatorKey.PeerId()
|
||||
if !slices.Contains(coordinators, coordinatorKey.PeerId()) {
|
||||
return errNoSuchCoordinatorNode
|
||||
return fmt.Errorf("got coordinator %s: %w", receiptCoordinator, errNoSuchCoordinatorNode)
|
||||
}
|
||||
res, err := coordinatorKey.Verify(payload, signature)
|
||||
if err != nil {
|
||||
|
||||
@ -3,6 +3,7 @@ package coordinatorproto
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"github.com/anytypeio/any-sync/util/crypto"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -93,7 +94,7 @@ func TestReceiptIncorrectCoordinatorKey(t *testing.T) {
|
||||
|
||||
t.Run("random key payload", func(t *testing.T) {
|
||||
fx.updateReceipt(t, func(t *testing.T, receipt *SpaceReceipt) {
|
||||
receipt.AccountIdentity = []byte("some random stuff")
|
||||
receipt.ControlNodeIdentity = []byte("some random stuff")
|
||||
})
|
||||
err := CheckReceipt(fx.peerId, fx.spaceId, fx.accountIdentity, []string{fx.coordinatorKey.GetPublic().PeerId()}, fx.signedReceipt)
|
||||
require.Error(t, err)
|
||||
@ -104,10 +105,10 @@ func TestReceiptIncorrectCoordinatorKey(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
keyBytes, err := randomKey.GetPublic().Marshall()
|
||||
require.NoError(t, err)
|
||||
receipt.AccountIdentity = keyBytes
|
||||
receipt.ControlNodeIdentity = keyBytes
|
||||
})
|
||||
err := CheckReceipt(fx.peerId, fx.spaceId, fx.accountIdentity, []string{fx.coordinatorKey.GetPublic().PeerId()}, fx.signedReceipt)
|
||||
require.Error(t, errNoSuchCoordinatorNode, err)
|
||||
require.True(t, errors.Is(err, errNoSuchCoordinatorNode))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user