Files
upstream-centrifugo/internal/api/grpc_test.go
upstream-mirror b352a9a30d
Some checks failed
test / Lint (push) Failing after 3s
test / Test with Go 1.26.8 (push) Failing after 2s
snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:17:21 +05:00

36 lines
894 B
Go

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)
}