(t *testing.T)
| 252 | } |
| 253 | |
| 254 | func TestGrpcAuthMiddleware(t *testing.T) { |
| 255 | prepareGlobalMetricsRegistry(t) |
| 256 | |
| 257 | cfg := Config{ |
| 258 | AuthEnabled: true, // We must enable this to enable Auth middleware for gRPC server. |
| 259 | Server: getServerConfig(t), |
| 260 | Target: []string{API}, // Something innocent that doesn't require much config. |
| 261 | NameValidationScheme: model.LegacyValidation, |
| 262 | } |
| 263 | |
| 264 | msch := &mockGrpcServiceHandler{} |
| 265 | ctx := context.Background() |
| 266 | |
| 267 | // Setup server, using Cortex config. This includes authentication middleware. |
| 268 | { |
| 269 | c, err := New(cfg) |
| 270 | require.NoError(t, err) |
| 271 | |
| 272 | serv, err := c.initServer() |
| 273 | require.NoError(t, err) |
| 274 | |
| 275 | schedulerpb.RegisterSchedulerForQuerierServer(c.Server.GRPC, msch) |
| 276 | frontendv1pb.RegisterFrontendServer(c.Server.GRPC, msch) |
| 277 | |
| 278 | require.NoError(t, services.StartAndAwaitRunning(ctx, serv)) |
| 279 | defer func() { |
| 280 | require.NoError(t, services.StopAndAwaitTerminated(ctx, serv)) |
| 281 | }() |
| 282 | } |
| 283 | |
| 284 | conn, err := grpc.NewClient(net.JoinHostPort(cfg.Server.GRPCListenAddress, strconv.Itoa(cfg.Server.GRPCListenPort)), grpc.WithTransportCredentials(insecure.NewCredentials())) |
| 285 | require.NoError(t, err) |
| 286 | defer func() { |
| 287 | require.NoError(t, conn.Close()) |
| 288 | }() |
| 289 | |
| 290 | { |
| 291 | // Verify that we can call frontendClient.NotifyClientShutdown without user in the context, and we don't get any error. |
| 292 | require.False(t, msch.clientShutdownCalled.Load()) |
| 293 | frontendClient := frontendv1pb.NewFrontendClient(conn) |
| 294 | _, err = frontendClient.NotifyClientShutdown(ctx, &frontendv1pb.NotifyClientShutdownRequest{ClientID: "random-client-id"}) |
| 295 | require.NoError(t, err) |
| 296 | require.True(t, msch.clientShutdownCalled.Load()) |
| 297 | } |
| 298 | |
| 299 | { |
| 300 | // Verify that we can call schedulerClient.NotifyQuerierShutdown without user in the context, and we don't get any error. |
| 301 | require.False(t, msch.querierShutdownCalled.Load()) |
| 302 | schedulerClient := schedulerpb.NewSchedulerForQuerierClient(conn) |
| 303 | _, err = schedulerClient.NotifyQuerierShutdown(ctx, &schedulerpb.NotifyQuerierShutdownRequest{QuerierID: "random-querier-id"}) |
| 304 | require.NoError(t, err) |
| 305 | require.True(t, msch.querierShutdownCalled.Load()) |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | func TestFlagDefaults(t *testing.T) { |
| 310 | c := Config{} |
nothing calls this directly
no test coverage detected