Repository: grpc/grpc-go
File: internal/xds/resolver/xds_resolver_test.go (Go)

Code before:

			// Build an xDS resolver.
			stateCh, _, _ := buildResolverForTarget(t, resolver.Target{URL: *testutils.MustParseURL("xds:///" + defaultTestServiceName)}, bc)

			// Update the management server with a listener resource that
			// contains inline route configuration.
			configureResourcesOnManagementServer(ctx, t, mgmtServer, nodeID, []*v3listenerpb.Listener{test.listener}, nil)

			// Ensure that the resolver pushes a state update to the channel.
			cs := verifyUpdateFromResolver(ctx, t, stateCh, "")

			// Ensure that it returns the expected error.
			_, err := cs.SelectConfig(iresolver.RPCInfo{Method: methodName, Context: ctx})
			if err := verifyResolverError(err, codes.Unavailable, test.wantErr, nodeID); err != nil {
				t.Fatal(err)
			}
		})
	}
}

func newDurationP(d time.Duration) *time.Duration {
	return &d
}

// TestResolver_AutoHostRewrite verifies the propagation of the AutoHostRewrite
// field from the xDS RouteConfiguration to the internal MatchedRoute.
//
// Per gRFC A81, this feature should only be active if three conditions are met:
// 1. The environment variable (XDSAuthorityRewrite) is enabled.
// 2. The xDS server is marked as a "trusted_xds_server" in the bootstrap config.
// 3. The specific Route Configuration requests `auto_host_rewrite=true`.
func (s) TestResolver_AutoHostRewrite(t *testing.T) {
	for _, tt := range []struct {
		name                string
		autoHostRewrite     bool
		envconfig           bool
		serverfeature       serverFeature.ServerFeature
		wantAutoHostRewrite bool
	}{
		{
			name:                "Enabled",
			autoHostRewrite:     true,
			envconfig:           true,
			serverfeature:       serverFeature.ServerFeatureTrustedXDSServer,
			wantAutoHostRewrite: true,
		},
		{
			name:                "Disable_EnvVarOff",
			autoHostRewrite:     true,
			envconfig:           false,
			serverfeature:       serverFeature.ServerFeatureTrustedXDSServer,

Review comment (suggestion):
We need to be clear here that we are *only* testing if the xDS resolver correctly propagates the value of the `auto_host_rewrite` field, and makes it available to the picker.

Code after:

			// Build an xDS resolver.
			stateCh, _, _ := buildResolverForTarget(t, resolver.Target{URL: *testutils.MustParseURL("xds:///" + defaultTestServiceName)}, bc)

			// Update the management server with a listener resource that
			// contains inline route configuration.
			configureResourcesOnManagementServer(ctx, t, mgmtServer, nodeID, []*v3listenerpb.Listener{test.listener}, nil)

			// Ensure that the resolver pushes a state update to the channel.
			cs := verifyUpdateFromResolver(ctx, t, stateCh, "")

			// Ensure that it returns the expected error.
			_, err := cs.SelectConfig(iresolver.RPCInfo{Method: methodName, Context: ctx})
			if err := verifyResolverError(err, codes.Unavailable, test.wantErr, nodeID); err != nil {
				t.Fatal(err)
			}
		})
	}
}

func newDurationP(d time.Duration) *time.Duration {
	return &d
}

// TestResolver_AutoHostRewrite verifies the propagation of the AutoHostRewrite
// field from the xDS resolver.
//
// Per gRFC A81, this feature should only be active if two conditions met:
// 1. The environment variable (XDSAuthorityRewrite) is enabled.
// 2. The xDS server is marked as "trusted_xds_server" in the bootstrap config.
func (s) TestResolver_AutoHostRewrite(t *testing.T) {
	for _, tt := range []struct {
		name                string
		autoHostRewrite     bool
		envconfig           bool
		serverfeature       serverFeature.ServerFeature
		wantAutoHostRewrite bool
	}{
		{
			name:                "EnvVarDisabled_NonTrustedServer_AutoHostRewriteOff",
			autoHostRewrite:     false,
			envconfig:           false,
			wantAutoHostRewrite: false,
		},
		{
			name:                "EnvVarDisabled_NonTrustedServer_AutoHostRewriteOn",
			autoHostRewrite:     true,
			envconfig:           false,
			wantAutoHostRewrite: false,
		},
		{