TestAuthorityReplacedWithResolverAddress tests the scenario where the resolver returned address contains a ServerName override. The test verifies that the :authority header value sent to the server as part of the http/2 HEADERS frame is set to the value specified in the resolver returned address.
(t *testing.T)
| 209 | // :authority header value sent to the server as part of the http/2 HEADERS frame |
| 210 | // is set to the value specified in the resolver returned address. |
| 211 | func (s) TestAuthorityReplacedWithResolverAddress(t *testing.T) { |
| 212 | const expectedAuthority = "test.server.name" |
| 213 | |
| 214 | ss := &stubserver.StubServer{ |
| 215 | EmptyCallF: func(ctx context.Context, _ *testpb.Empty) (*testpb.Empty, error) { |
| 216 | return authorityChecker(ctx, expectedAuthority) |
| 217 | }, |
| 218 | } |
| 219 | if err := ss.Start(nil); err != nil { |
| 220 | t.Fatalf("Error starting endpoint server: %v", err) |
| 221 | } |
| 222 | defer ss.Stop() |
| 223 | |
| 224 | r := manual.NewBuilderWithScheme("whatever") |
| 225 | r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: ss.Address, ServerName: expectedAuthority}}}) |
| 226 | cc, err := grpc.NewClient(r.Scheme()+":///whatever", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r)) |
| 227 | if err != nil { |
| 228 | t.Fatalf("grpc.NewClient(%q) = %v", ss.Address, err) |
| 229 | } |
| 230 | defer cc.Close() |
| 231 | |
| 232 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 233 | defer cancel() |
| 234 | if _, err = testgrpc.NewTestServiceClient(cc).EmptyCall(ctx, &testpb.Empty{}); err != nil { |
| 235 | t.Fatalf("EmptyCall() rpc failed: %v", err) |
| 236 | } |
| 237 | } |
nothing calls this directly
no test coverage detected