mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
16c34b627f
* define auth endpoints * add intercepter with tests * auth functions * fix up the auth functions * add functions for storing and saving the hashed password from the validator db * validate strong password input and simplify jwt claims * tests for db funcs * comments for db funcs * wrap up the authentication tests * register auth srv * use proper db iface package and check if existing password * fix broken tests and add new test to check if password already exists * use roughtime * rlock to check the auth paths * Merge refs/heads/master into auth-rpc * Merge refs/heads/master into auth-rpc * Merge refs/heads/master into auth-rpc * leave out the stream interceptor * resolve confs * Merge branch 'master' into auth-rpc * confs * Merge branch 'auth-rpc' of github.com:prysmaticlabs/prysm into auth-rpc * Merge refs/heads/master into auth-rpc * Merge refs/heads/master into auth-rpc * Merge refs/heads/master into auth-rpc * Merge refs/heads/master into auth-rpc
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"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()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctxMD := map[string][]string{
|
|
"authorization": {token},
|
|
}
|
|
ctx := context.Background()
|
|
ctx = metadata.NewIncomingContext(ctx, ctxMD)
|
|
_, err = interceptor(ctx, "xyz", unaryInfo, unaryHandler)
|
|
if err != nil {
|
|
t.Fatal(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()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctxMD := map[string][]string{
|
|
"authorization": {token},
|
|
}
|
|
ctx := context.Background()
|
|
ctx = metadata.NewIncomingContext(ctx, ctxMD)
|
|
_, err = interceptor(ctx, "xyz", unaryInfo, unaryHandler)
|
|
if err == nil {
|
|
t.Fatalf("Unexpected success processing token %v", err)
|
|
}
|
|
if !strings.Contains(err.Error(), "signature is invalid") {
|
|
t.Fatalf("Expected error validating signature, received %v", err)
|
|
}
|
|
}
|