Skip to content

Commit

Permalink
Make validateAccessToken an inner func to the suite
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoshuck committed Mar 8, 2024
1 parent bc711dd commit 8c4bbcc
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions middleware/auth_access_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,17 @@ import (
)

func TestAuthFuncGRPC_AccessToken(t *testing.T) {
ss := &TestAuthAccessTokenSuite{
var ss TestAuthAccessTokenSuite
ss = TestAuthAccessTokenSuite{
InterceptorTestSuite: &grpc_test.InterceptorTestSuite{
TestService: newTestAuthenticationAccessToken(),
ServerOpts: []grpc.ServerOption{
grpc.StreamInterceptor(grpc_auth.StreamServerInterceptor(BearerAccessTokenAuthFuncGRPC(validateAccessToken))),
grpc.UnaryInterceptor(grpc_auth.UnaryServerInterceptor(BearerAccessTokenAuthFuncGRPC(validateAccessToken))),
grpc.StreamInterceptor(grpc_auth.StreamServerInterceptor(BearerAccessTokenAuthFuncGRPC(ss.validateAccessToken))),
grpc.UnaryInterceptor(grpc_auth.UnaryServerInterceptor(BearerAccessTokenAuthFuncGRPC(ss.validateAccessToken))),
},
},
}
suite.Run(t, ss)
}

func validateAccessToken(ctx context.Context, token string) error {
if token != "ey.LfexACqSU5qgYgp9EXSdR4rtnD7BJ0oOCNi8BKIkZ4vt25jRxyu6AXAKVNrtItb1" {
return status.Error(codes.Unauthenticated, "Invalid access token")
}
return nil
suite.Run(t, &ss)
}

type TestAuthAccessTokenSuite struct {
Expand Down Expand Up @@ -91,6 +85,13 @@ func (suite *TestAuthAccessTokenSuite) TestValidToken() {
suite.Assert().NotNil(res)
}

func (suite *TestAuthAccessTokenSuite) validateAccessToken(ctx context.Context, token string) error {
if token != "ey.LfexACqSU5qgYgp9EXSdR4rtnD7BJ0oOCNi8BKIkZ4vt25jRxyu6AXAKVNrtItb1" {
return status.Error(codes.Unauthenticated, "Invalid access token")
}
return nil
}

type testAuthAccessToken struct {
grpc_test.UnimplementedTestServiceServer
}
Expand Down

0 comments on commit 8c4bbcc

Please sign in to comment.