MCPcopy
hub / github.com/grpc/grpc-go / TestCorrectAuthorityWithCustomCreds

Method TestCorrectAuthorityWithCustomCreds

credentials/credentials_ext_test.go:346–373  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

344// option using custom credentials. It verifies that the provided authority is
345// correctly propagated to the server when a correct authority is used.
346func (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

Callers

nothing calls this directly

Calls 10

StartServerMethod · 0.95
StopMethod · 0.95
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
CallAuthorityFunction · 0.92
CodeFunction · 0.92
authorityCheckerFunction · 0.70
FatalfMethod · 0.65
CloseMethod · 0.65
EmptyCallMethod · 0.65

Tested by

no test coverage detected