snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
35
internal/api/grpc_test.go
Normal file
35
internal/api/grpc_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
func TestGRPC_Authorize_Unauthenticated(t *testing.T) {
|
||||
err := authorize(context.Background(), []byte("apikey xxx"))
|
||||
require.Error(t, err)
|
||||
|
||||
md := metadata.New(map[string]string{})
|
||||
ctx := metadata.NewIncomingContext(context.Background(), md)
|
||||
err = authorize(ctx, []byte("apikey xxx"))
|
||||
require.Error(t, err)
|
||||
|
||||
md = metadata.New(map[string]string{
|
||||
"authorization": "apikey yyy",
|
||||
})
|
||||
ctx = metadata.NewIncomingContext(context.Background(), md)
|
||||
err = authorize(ctx, []byte("apikey xxx"))
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestGRPC_Authorize_OK(t *testing.T) {
|
||||
md := metadata.New(map[string]string{
|
||||
"authorization": "apikey xxx",
|
||||
})
|
||||
ctx := metadata.NewIncomingContext(context.Background(), md)
|
||||
err := authorize(ctx, []byte("apikey xxx"))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
Reference in New Issue
Block a user