Tests the scenario where the `grpc.CallAuthority` call option is used with different transport credentials. The test verifies that the specified authority is correctly propagated to the serve when a correct authority is used.
(t *testing.T)
| 85 | // authority is correctly propagated to the serve when a correct authority is |
| 86 | // used. |
| 87 | func (s) TestCorrectAuthorityWithCreds(t *testing.T) { |
| 88 | const authority = "auth.test.example.com" |
| 89 | const authorityWithPort = "auth.test.example.com:8010" |
| 90 | |
| 91 | tests := []struct { |
| 92 | name string |
| 93 | creds func(t *testing.T) (grpc.ServerOption, grpc.DialOption) |
| 94 | expectedAuth string |
| 95 | }{ |
| 96 | { |
| 97 | name: "Insecure", |
| 98 | creds: func(*testing.T) (grpc.ServerOption, grpc.DialOption) { |
| 99 | c := insecure.NewCredentials() |
| 100 | return grpc.Creds(c), grpc.WithTransportCredentials(c) |
| 101 | }, |
| 102 | expectedAuth: authority, |
| 103 | }, |
| 104 | { |
| 105 | name: "Local", |
| 106 | creds: func(*testing.T) (grpc.ServerOption, grpc.DialOption) { |
| 107 | c := local.NewCredentials() |
| 108 | return grpc.Creds(c), grpc.WithTransportCredentials(c) |
| 109 | }, |
| 110 | expectedAuth: authority, |
| 111 | }, |
| 112 | { |
| 113 | name: "TLS", |
| 114 | creds: func(t *testing.T) (grpc.ServerOption, grpc.DialOption) { |
| 115 | return loadTLSCreds(t) |
| 116 | }, |
| 117 | expectedAuth: authority, |
| 118 | }, |
| 119 | { |
| 120 | name: "TLSAuthorityWithPort", |
| 121 | creds: func(t *testing.T) (grpc.ServerOption, grpc.DialOption) { |
| 122 | return loadTLSCreds(t) |
| 123 | }, |
| 124 | expectedAuth: authorityWithPort, |
| 125 | }, |
| 126 | } |
| 127 | |
| 128 | for _, tt := range tests { |
| 129 | t.Run(tt.name, func(t *testing.T) { |
| 130 | ss := &stubserver.StubServer{ |
| 131 | EmptyCallF: func(ctx context.Context, _ *testpb.Empty) (*testpb.Empty, error) { |
| 132 | if err := authorityChecker(ctx, tt.expectedAuth); err != nil { |
| 133 | return nil, err |
| 134 | } |
| 135 | return &testpb.Empty{}, nil |
| 136 | }, |
| 137 | } |
| 138 | serverOpt, dialOpt := tt.creds(t) |
| 139 | if err := ss.StartServer(serverOpt); err != nil { |
| 140 | t.Fatalf("Error starting endpoint server: %v", err) |
| 141 | } |
| 142 | defer ss.Stop() |
| 143 | |
| 144 | cc, err := grpc.NewClient(ss.Address, dialOpt) |
nothing calls this directly
no test coverage detected