prysm-pulse/validator/rpc/intercepter_test.go
Victor Farazdagi 95a5b4945b
Fixes incorrect checks for errors in several tests (#7392)
* fixes TestServer_ListAssignments_Pagination_InputOutOfRange
* fixes TestServer_ListValidatorBalances_PaginationOutOfRange
* fix TestServer_ListAttestations_Genesis
* remove redundant TestServer_GetValidatorParticipation_DoesntExist and TestGetDuties_NextEpoch_CantFindValidatorIdx
* Merge branch 'master' into fix-invalid-errcheck-tests
* remove unnecessary import
* fix TestStore_OnAttestation
* fix TestStore_OnAttestationUsingCheckptCache
* fix TestVerifyBlkDescendant
* fix pagination tests
* fix account v2 tests
* fix account v2 tests (remote)
* fix TestServer_JWTInterceptor_BadToken
* Merge refs/heads/master into fix-invalid-errcheck-tests
2020-10-01 14:38:53 +00:00

61 lines
1.5 KiB
Go

package rpc
import (
"context"
"testing"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)
func TestServer_JWTInterceptor_Verify(t *testing.T) {
s := Server{
jwtKey: []byte("testKey"),
}
interceptor := s.JWTInterceptor()
unaryInfo := &grpc.UnaryServerInfo{
FullMethod: "Proto.CreateWallet",
}
unaryHandler := func(ctx context.Context, req interface{}) (interface{}, error) {
return nil, nil
}
token, _, err := s.createTokenString()
require.NoError(t, err)
ctxMD := map[string][]string{
"authorization": {"Bearer " + token},
}
ctx := context.Background()
ctx = metadata.NewIncomingContext(ctx, ctxMD)
_, err = interceptor(ctx, "xyz", unaryInfo, unaryHandler)
require.NoError(t, err)
}
func TestServer_JWTInterceptor_BadToken(t *testing.T) {
s := Server{
jwtKey: []byte("testKey"),
}
interceptor := s.JWTInterceptor()
unaryInfo := &grpc.UnaryServerInfo{
FullMethod: "Proto.CreateWallet",
}
unaryHandler := func(ctx context.Context, req interface{}) (interface{}, error) {
return nil, nil
}
badServer := Server{
jwtKey: []byte("badTestKey"),
}
token, _, err := badServer.createTokenString()
require.NoError(t, err)
ctxMD := map[string][]string{
"authorization": {"Bearer " + token},
}
ctx := context.Background()
ctx = metadata.NewIncomingContext(ctx, ctxMD)
_, err = interceptor(ctx, "xyz", unaryInfo, unaryHandler)
require.ErrorContains(t, "signature is invalid", err)
}