Skip to content

Commit

Permalink
crypto/test: Improve test helpers
Browse files Browse the repository at this point in the history
Summary:
 * get rid of `Random` wording, it is implied everywhere;
 * provide single `Signer` function returning all potentially needed
   cryptographic components;
 * do not import `user` package into `neofscryptotest`, there is
   `usertest` for this;
 * provide test signer's wrapper which always failing signing.

Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
  • Loading branch information
cthulhu-rider committed Jul 2, 2024
1 parent 356ce69 commit 16daa0d
Show file tree
Hide file tree
Showing 25 changed files with 460 additions and 327 deletions.
26 changes: 12 additions & 14 deletions bearer/bearer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
bearertest "github.com/nspcc-dev/neofs-sdk-go/bearer/test"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
"github.com/nspcc-dev/neofs-sdk-go/crypto/test"
neofscryptotest "github.com/nspcc-dev/neofs-sdk-go/crypto/test"
"github.com/nspcc-dev/neofs-sdk-go/eacl"
eacltest "github.com/nspcc-dev/neofs-sdk-go/eacl/test"
usertest "github.com/nspcc-dev/neofs-sdk-go/user/test"
Expand Down Expand Up @@ -257,11 +257,11 @@ func TestToken_Sign(t *testing.T) {

require.False(t, val.VerifySignature())

signer := test.RandomSignerRFC6979()
usr := usertest.User()

val = bearertest.Token(t)

require.NoError(t, val.Sign(signer))
require.NoError(t, val.Sign(usr))

require.True(t, val.VerifySignature())

Expand Down Expand Up @@ -294,11 +294,11 @@ func TestToken_SignedData(t *testing.T) {
require.NoError(t, dec.UnmarshalSignedData(signedData))
require.Equal(t, val, dec)

signer := test.RandomSignerRFC6979()
usr := usertest.User()
val = bearertest.Token(t)
val.SetIssuer(signer.UserID())
val.SetIssuer(usr.UserID())

test.SignedDataComponentUser(t, signer, &val)
usertest.TestSignedData(t, usr, &val)
}

func TestToken_ReadFromV2(t *testing.T) {
Expand Down Expand Up @@ -360,11 +360,9 @@ func TestToken_ReadFromV2(t *testing.T) {
require.True(t, val.AssertUser(usr))
require.False(t, val.AssertUser(usr2))

signer := test.RandomSigner()

var s neofscrypto.Signature

require.NoError(t, s.CalculateMarshalled(signer, &body, nil))
require.NoError(t, s.CalculateMarshalled(neofscryptotest.Signer(), &body, nil))

s.WriteToV2(&sig)

Expand All @@ -374,7 +372,7 @@ func TestToken_ReadFromV2(t *testing.T) {
}

func TestResolveIssuer(t *testing.T) {
signer := test.RandomSignerRFC6979()
usr := usertest.User()

var val bearer.Token

Expand All @@ -391,12 +389,12 @@ func TestResolveIssuer(t *testing.T) {

require.Zero(t, val.ResolveIssuer())

require.NoError(t, val.Sign(signer))
require.NoError(t, val.Sign(usr))

usr := signer.UserID()
usrID := usr.UserID()

require.Equal(t, usr, val.ResolveIssuer())
require.Equal(t, usr, val.Issuer())
require.Equal(t, usrID, val.ResolveIssuer())
require.Equal(t, usrID, val.Issuer())
}

func TestToken_Issuer(t *testing.T) {
Expand Down
Loading

0 comments on commit 16daa0d

Please sign in to comment.