TestCorrectAuthorityWithCustomCreds tests the `grpc.CallAuthority` call option using custom credentials. It verifies that the provided authority is correctly propagated to the server when a correct authority is used.
(t *testing.T)
| 344 | // option using custom credentials. It verifies that the provided authority is |
| 345 | // correctly propagated to the server when a correct authority is used. |
| 346 | func (s) TestCorrectAuthorityWithCustomCreds(t *testing.T) { |
| 347 | const authority = "auth.test.example.com" |
| 348 | creds := &testCreds{authority: "auth.test.example.com"} |
| 349 | ss := stubserver.StubServer{ |
| 350 | EmptyCallF: func(ctx context.Context, _ *testpb.Empty) (*testpb.Empty, error) { |
| 351 | if err := authorityChecker(ctx, authority); err != nil { |
| 352 | return nil, err |
| 353 | } |
| 354 | return &testpb.Empty{}, nil |
| 355 | }, |
| 356 | } |
| 357 | if err := ss.StartServer(); err != nil { |
| 358 | t.Fatalf("Failed to start stub server: %v", err) |
| 359 | } |
| 360 | defer ss.Stop() |
| 361 | |
| 362 | cc, err := grpc.NewClient(ss.Address, grpc.WithTransportCredentials(creds)) |
| 363 | if err != nil { |
| 364 | t.Fatalf("grpc.NewClient(%q) = %v", ss.Address, err) |
| 365 | } |
| 366 | defer cc.Close() |
| 367 | |
| 368 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 369 | defer cancel() |
| 370 | if _, err = testgrpc.NewTestServiceClient(cc).EmptyCall(ctx, &testpb.Empty{}, grpc.CallAuthority(authority)); status.Code(err) != codes.OK { |
| 371 | t.Fatalf("EmptyCall() returned status %v, want %v", status.Code(err), codes.OK) |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | // TestAuthorityOverrideWithCertChain tests that the authority being used to |
| 376 | // override per-RPC authority is validated against the leaf certificate only |
nothing calls this directly
no test coverage detected