forked from infobloxopen/atlas-app-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterceptor_test.go
More file actions
34 lines (30 loc) · 1.23 KB
/
Copy pathinterceptor_test.go
File metadata and controls
34 lines (30 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package auth
import (
"context"
"testing"
"github.com/dgrijalva/jwt-go"
"github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
)
func TestLogrusUnaryServerInterceptor(t *testing.T) {
testAccountId := "some-ib-customer"
testHandler := func(ctx context.Context, req interface{}) (interface{}, error) {
logger := ctxlogrus.Extract(ctx)
assert.Equal(t, logger.Data[MultiTenancyField], testAccountId)
return nil, nil
}
chain := grpc_middleware.ChainUnaryServer(grpc_logrus.UnaryServerInterceptor(logrus.NewEntry(logrus.StandardLogger())), LogrusUnaryServerInterceptor())
ctx := contextWithToken(makeToken(jwt.MapClaims{MultiTenancyField: testAccountId}, t), DefaultTokenType)
chain(ctx, nil, &grpc.UnaryServerInfo{}, testHandler)
negativeTestHandler := func(ctx context.Context, req interface{}) (interface{}, error) {
logger := ctxlogrus.Extract(ctx)
_, ok := logger.Data[MultiTenancyField]
assert.False(t, ok)
return nil, nil
}
chain(context.Background(), nil, &grpc.UnaryServerInfo{}, negativeTestHandler)
}