2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-06-15 19:58:28 +00:00
|
|
|
package xds
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
envoy_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
|
|
|
|
envoy_endpoint_v3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
|
|
|
|
envoy_listener_v3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
|
|
|
|
envoy_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
|
2023-02-17 17:46:03 +00:00
|
|
|
envoy_tls_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
|
|
|
|
|
2023-03-17 17:31:04 +00:00
|
|
|
"github.com/hashicorp/consul/agent/connect"
|
|
|
|
"github.com/hashicorp/consul/agent/consul/discoverychain"
|
2023-02-03 06:18:10 +00:00
|
|
|
"github.com/hashicorp/consul/agent/xds/testcommon"
|
2023-02-06 17:14:35 +00:00
|
|
|
"github.com/hashicorp/consul/envoyextensions/xdscommon"
|
2022-06-15 19:58:28 +00:00
|
|
|
|
|
|
|
testinf "github.com/mitchellh/go-testing-interface"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/proxycfg"
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
var testTypeUrlToPrettyName = map[string]string{
|
|
|
|
xdscommon.ListenerType: "listeners",
|
|
|
|
xdscommon.RouteType: "routes",
|
|
|
|
xdscommon.ClusterType: "clusters",
|
|
|
|
xdscommon.EndpointType: "endpoints",
|
2023-02-17 17:46:03 +00:00
|
|
|
xdscommon.SecretType: "secrets",
|
2022-06-15 19:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type goldenTestCase struct {
|
|
|
|
name string
|
|
|
|
create func(t testinf.T) *proxycfg.ConfigSnapshot
|
|
|
|
// Setup is called before the test starts. It is passed the snapshot from
|
|
|
|
// TestConfigSnapshot and is allowed to modify it in any way to setup the
|
|
|
|
// test input.
|
|
|
|
setup func(snap *proxycfg.ConfigSnapshot)
|
|
|
|
overrideGoldenName string
|
|
|
|
generatorSetup func(*ResourceGenerator)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAllResourcesFromSnapshot(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("too slow for testing.Short")
|
|
|
|
}
|
|
|
|
|
|
|
|
type testcase = goldenTestCase
|
|
|
|
|
|
|
|
run := func(
|
|
|
|
t *testing.T,
|
2023-02-03 06:18:10 +00:00
|
|
|
sf xdscommon.SupportedProxyFeatures,
|
2022-06-15 19:58:28 +00:00
|
|
|
envoyVersion string,
|
|
|
|
latestEnvoyVersion string,
|
|
|
|
tt testcase,
|
|
|
|
) {
|
|
|
|
// Sanity check default with no overrides first
|
|
|
|
snap := tt.create(t)
|
|
|
|
|
|
|
|
// TODO: it would be nice to be able to ensure these snapshots are always valid before we use them in a test.
|
|
|
|
// require.True(t, snap.Valid())
|
|
|
|
|
|
|
|
// We need to replace the TLS certs with deterministic ones to make golden
|
|
|
|
// files workable. Note we don't update these otherwise they'd change
|
2023-02-17 17:46:03 +00:00
|
|
|
// golden files for every test case and so not be any use!
|
2023-02-03 06:18:10 +00:00
|
|
|
testcommon.SetupTLSRootsAndLeaf(t, snap)
|
2022-06-15 19:58:28 +00:00
|
|
|
|
|
|
|
if tt.setup != nil {
|
|
|
|
tt.setup(snap)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Need server just for logger dependency
|
2023-02-03 06:18:10 +00:00
|
|
|
g := NewResourceGenerator(testutil.Logger(t), nil, false)
|
2022-06-15 19:58:28 +00:00
|
|
|
g.ProxyFeatures = sf
|
|
|
|
if tt.generatorSetup != nil {
|
|
|
|
tt.generatorSetup(g)
|
|
|
|
}
|
|
|
|
|
2023-02-03 06:18:10 +00:00
|
|
|
resources, err := g.AllResourcesFromSnapshot(snap)
|
2022-06-15 19:58:28 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
typeUrls := []string{
|
|
|
|
xdscommon.ListenerType,
|
|
|
|
xdscommon.RouteType,
|
|
|
|
xdscommon.ClusterType,
|
|
|
|
xdscommon.EndpointType,
|
2023-02-17 17:46:03 +00:00
|
|
|
xdscommon.SecretType,
|
2022-06-15 19:58:28 +00:00
|
|
|
}
|
|
|
|
require.Len(t, resources, len(typeUrls))
|
|
|
|
|
|
|
|
for _, typeUrl := range typeUrls {
|
|
|
|
prettyName := testTypeUrlToPrettyName[typeUrl]
|
|
|
|
t.Run(prettyName, func(t *testing.T) {
|
|
|
|
items, ok := resources[typeUrl]
|
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
sort.Slice(items, func(i, j int) bool {
|
|
|
|
switch typeUrl {
|
|
|
|
case xdscommon.ListenerType:
|
|
|
|
return items[i].(*envoy_listener_v3.Listener).Name < items[j].(*envoy_listener_v3.Listener).Name
|
|
|
|
case xdscommon.RouteType:
|
|
|
|
return items[i].(*envoy_route_v3.RouteConfiguration).Name < items[j].(*envoy_route_v3.RouteConfiguration).Name
|
|
|
|
case xdscommon.ClusterType:
|
|
|
|
return items[i].(*envoy_cluster_v3.Cluster).Name < items[j].(*envoy_cluster_v3.Cluster).Name
|
|
|
|
case xdscommon.EndpointType:
|
|
|
|
return items[i].(*envoy_endpoint_v3.ClusterLoadAssignment).ClusterName < items[j].(*envoy_endpoint_v3.ClusterLoadAssignment).ClusterName
|
2023-02-17 17:46:03 +00:00
|
|
|
case xdscommon.SecretType:
|
|
|
|
return items[i].(*envoy_tls_v3.Secret).Name < items[j].(*envoy_tls_v3.Secret).Name
|
2022-06-15 19:58:28 +00:00
|
|
|
default:
|
|
|
|
panic("not possible")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
r, err := createResponse(typeUrl, "00000001", "00000001", items)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
gotJSON := protoToJSON(t, r)
|
|
|
|
|
|
|
|
gName := tt.name
|
|
|
|
if tt.overrideGoldenName != "" {
|
|
|
|
gName = tt.overrideGoldenName
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedJSON := goldenEnvoy(t, filepath.Join(prettyName, gName), envoyVersion, latestEnvoyVersion, gotJSON)
|
|
|
|
require.JSONEq(t, expectedJSON, gotJSON)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []testcase{
|
|
|
|
{
|
|
|
|
name: "defaults",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshot(t, nil, nil)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect-proxy-exported-to-peers",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshot(t, func(ns *structs.NodeService) {
|
|
|
|
// This test is only concerned about the SPIFFE cert validator config in the public listener
|
|
|
|
// so we empty out the upstreams to avoid generating unnecessary upstream listeners.
|
|
|
|
ns.Proxy.Upstreams = structs.Upstreams{}
|
|
|
|
}, []proxycfg.UpdateEvent{
|
|
|
|
{
|
|
|
|
CorrelationID: "peering-trust-bundles",
|
|
|
|
Result: proxycfg.TestPeerTrustBundles(t),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
2022-07-19 18:56:28 +00:00
|
|
|
{
|
|
|
|
name: "transparent-proxy",
|
|
|
|
create: proxycfg.TestConfigSnapshotTransparentProxy,
|
|
|
|
},
|
2022-06-15 19:58:28 +00:00
|
|
|
{
|
|
|
|
name: "connect-proxy-with-peered-upstreams",
|
|
|
|
create: proxycfg.TestConfigSnapshotPeering,
|
|
|
|
},
|
2022-07-19 18:56:28 +00:00
|
|
|
{
|
|
|
|
name: "transparent-proxy-with-peered-upstreams",
|
|
|
|
create: proxycfg.TestConfigSnapshotPeeringTProxy,
|
|
|
|
},
|
2022-09-27 13:49:28 +00:00
|
|
|
{
|
|
|
|
name: "local-mesh-gateway-with-peered-upstreams",
|
|
|
|
create: proxycfg.TestConfigSnapshotPeeringLocalMeshGateway,
|
|
|
|
},
|
2023-03-10 20:52:54 +00:00
|
|
|
{
|
2023-05-16 18:36:05 +00:00
|
|
|
name: "telemetry-collector",
|
|
|
|
create: proxycfg.TestConfigSnapshotTelemetryCollector,
|
2023-03-10 20:52:54 +00:00
|
|
|
},
|
2022-06-15 19:58:28 +00:00
|
|
|
}
|
2022-07-14 18:45:51 +00:00
|
|
|
tests = append(tests, getConnectProxyTransparentProxyGoldenTestCases()...)
|
2022-06-28 19:52:25 +00:00
|
|
|
tests = append(tests, getMeshGatewayPeeringGoldenTestCases()...)
|
2023-03-22 18:56:18 +00:00
|
|
|
tests = append(tests, getTrafficControlPeeringGoldenTestCases(false)...)
|
2022-06-15 19:58:28 +00:00
|
|
|
tests = append(tests, getEnterpriseGoldenTestCases()...)
|
2023-03-17 17:31:04 +00:00
|
|
|
tests = append(tests, getAPIGatewayGoldenTestCases(t)...)
|
2022-06-15 19:58:28 +00:00
|
|
|
|
2023-02-06 17:14:35 +00:00
|
|
|
latestEnvoyVersion := xdscommon.EnvoyVersions[0]
|
|
|
|
for _, envoyVersion := range xdscommon.EnvoyVersions {
|
2023-02-03 06:18:10 +00:00
|
|
|
sf, err := xdscommon.DetermineSupportedProxyFeaturesFromString(envoyVersion)
|
2022-06-15 19:58:28 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
t.Run("envoy-"+envoyVersion, func(t *testing.T) {
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
run(t, sf, envoyVersion, latestEnvoyVersion, tt)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-06-28 19:52:25 +00:00
|
|
|
|
2022-07-14 18:45:51 +00:00
|
|
|
func getConnectProxyTransparentProxyGoldenTestCases() []goldenTestCase {
|
|
|
|
return []goldenTestCase{
|
|
|
|
{
|
|
|
|
name: "transparent-proxy-destination",
|
|
|
|
create: proxycfg.TestConfigSnapshotTransparentProxyDestination,
|
|
|
|
},
|
2022-08-01 18:12:43 +00:00
|
|
|
{
|
2023-06-01 17:04:39 +00:00
|
|
|
name: "transparent-proxy-destination-http",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotTransparentProxyDestinationHTTP(t, nil)
|
|
|
|
},
|
2022-08-01 18:12:43 +00:00
|
|
|
},
|
2022-07-14 18:45:51 +00:00
|
|
|
{
|
|
|
|
name: "transparent-proxy-terminating-gateway-destinations-only",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotTerminatingGatewayDestinations(t, true, nil)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-28 19:52:25 +00:00
|
|
|
func getMeshGatewayPeeringGoldenTestCases() []goldenTestCase {
|
|
|
|
return []goldenTestCase{
|
|
|
|
{
|
|
|
|
name: "mesh-gateway-with-exported-peered-services",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotPeeredMeshGateway(t, "default-services-tcp", nil, nil)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh-gateway-with-exported-peered-services-http",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotPeeredMeshGateway(t, "default-services-http", nil, nil)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh-gateway-with-exported-peered-services-http-with-router",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotPeeredMeshGateway(t, "chain-and-l7-stuff", nil, nil)
|
|
|
|
},
|
|
|
|
},
|
2022-09-23 03:14:25 +00:00
|
|
|
{
|
|
|
|
name: "mesh-gateway-peering-control-plane",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotPeeredMeshGateway(t, "control-plane", nil, nil)
|
|
|
|
},
|
|
|
|
},
|
2022-10-06 13:54:14 +00:00
|
|
|
{
|
|
|
|
name: "mesh-gateway-with-imported-peered-services",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotPeeredMeshGateway(t, "imported-services", nil, nil)
|
|
|
|
},
|
|
|
|
},
|
2022-09-26 16:50:17 +00:00
|
|
|
{
|
|
|
|
name: "mesh-gateway-with-peer-through-mesh-gateway-enabled",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotPeeredMeshGateway(t, "peer-through-mesh-gateway", nil, nil)
|
|
|
|
},
|
|
|
|
},
|
2022-06-28 19:52:25 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-09 17:58:28 +00:00
|
|
|
|
2023-03-22 18:56:18 +00:00
|
|
|
func getTrafficControlPeeringGoldenTestCases(enterprise bool) []goldenTestCase {
|
|
|
|
cases := []goldenTestCase{
|
2022-09-09 17:58:28 +00:00
|
|
|
{
|
|
|
|
name: "connect-proxy-with-chain-and-failover-to-cluster-peer",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "failover-to-cluster-peer", enterprise, nil, nil)
|
2022-09-09 17:58:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect-proxy-with-chain-and-redirect-to-cluster-peer",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
2023-03-22 18:56:18 +00:00
|
|
|
return proxycfg.TestConfigSnapshotDiscoveryChain(t, "redirect-to-cluster-peer", enterprise, nil, nil)
|
2022-09-09 17:58:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-03-22 18:56:18 +00:00
|
|
|
|
|
|
|
if enterprise {
|
|
|
|
for i := range cases {
|
|
|
|
cases[i].name = "enterprise-" + cases[i].name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cases
|
2022-09-09 17:58:28 +00:00
|
|
|
}
|
2023-02-17 17:46:03 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
gatewayTestPrivateKey = `-----BEGIN RSA PRIVATE KEY-----
|
|
|
|
MIIEowIBAAKCAQEAx95Opa6t4lGEpiTUogEBptqOdam2ch4BHQGhNhX/MrDwwuZQ
|
|
|
|
httBwMfngQ/wd9NmYEPAwj0dumUoAITIq6i2jQlhqTodElkbsd5vWY8R/bxJWQSo
|
|
|
|
NvVE12TlzECxGpJEiHt4W0r8pGffk+rvpljiUyCfnT1kGF3znOSjK1hRMTn6RKWC
|
|
|
|
yYaBvXQiB4SGilfLgJcEpOJKtISIxmZ+S409g9X5VU88/Bmmrz4cMyxce86Kc2ug
|
|
|
|
5/MOv0CjWDJwlrv8njneV2zvraQ61DDwQftrXOvuCbO5IBRHMOBHiHTZ4rtGuhMa
|
|
|
|
Ir21V4vb6n8c4YzXiFvhUYcyX7rltGZzVd+WmQIDAQABAoIBACYvceUzp2MK4gYA
|
|
|
|
GWPOP2uKbBdM0l+hHeNV0WAM+dHMfmMuL4pkT36ucqt0ySOLjw6rQyOZG5nmA6t9
|
|
|
|
sv0g4ae2eCMlyDIeNi1Yavu4Wt6YX4cTXbQKThm83C6W2X9THKbauBbxD621bsDK
|
|
|
|
7PhiGPN60yPue7YwFQAPqqD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
|
|
qwxn8SmLkSKbf2+MsQVzLCXXN5u+D8Yv+4py+oKP4EQ5aFZuDEx+r/G/31rTthww
|
|
|
|
AAJAMaoXmoYVdgXV+CPuBb2M4XCpuzLu3bcA2PXm5ipSyIgntMKwXV7r
|
|
|
|
-----END CERTIFICATE-----`
|
|
|
|
)
|
|
|
|
|
2023-03-17 17:31:04 +00:00
|
|
|
func getAPIGatewayGoldenTestCases(t *testing.T) []goldenTestCase {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
service := structs.NewServiceName("service", nil)
|
|
|
|
serviceUID := proxycfg.NewUpstreamIDFromServiceName(service)
|
2023-03-30 14:08:38 +00:00
|
|
|
serviceChain := discoverychain.TestCompileConfigEntries(t, "service", "default", "default", "dc1", connect.TestClusterID+".consul", nil, nil)
|
2023-03-17 17:31:04 +00:00
|
|
|
|
2023-02-17 17:46:03 +00:00
|
|
|
return []goldenTestCase{
|
|
|
|
{
|
|
|
|
name: "api-gateway-with-tcp-route-and-inline-certificate",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotAPIGateway(t, "default", nil, func(entry *structs.APIGatewayConfigEntry, bound *structs.BoundAPIGatewayConfigEntry) {
|
|
|
|
entry.Listeners = []structs.APIGatewayListener{
|
|
|
|
{
|
|
|
|
Name: "listener",
|
|
|
|
Protocol: structs.ListenerProtocolTCP,
|
|
|
|
Port: 8080,
|
|
|
|
TLS: structs.APIGatewayTLSConfiguration{
|
|
|
|
Certificates: []structs.ResourceReference{{
|
|
|
|
Kind: structs.InlineCertificate,
|
|
|
|
Name: "certificate",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
bound.Listeners = []structs.BoundAPIGatewayListener{
|
|
|
|
{
|
|
|
|
Name: "listener",
|
|
|
|
Certificates: []structs.ResourceReference{{
|
|
|
|
Kind: structs.InlineCertificate,
|
|
|
|
Name: "certificate",
|
|
|
|
}},
|
|
|
|
Routes: []structs.ResourceReference{{
|
|
|
|
Kind: structs.TCPRoute,
|
|
|
|
Name: "route",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
2023-05-19 18:50:59 +00:00
|
|
|
},
|
|
|
|
[]structs.BoundRoute{
|
|
|
|
&structs.TCPRouteConfigEntry{
|
|
|
|
Kind: structs.TCPRoute,
|
|
|
|
Name: "route",
|
|
|
|
Services: []structs.TCPService{{
|
|
|
|
Name: "service",
|
|
|
|
}},
|
|
|
|
Parents: []structs.ResourceReference{
|
|
|
|
{
|
|
|
|
Kind: structs.APIGateway,
|
|
|
|
Name: "api-gateway",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, []structs.InlineCertificateConfigEntry{{
|
|
|
|
Kind: structs.InlineCertificate,
|
|
|
|
Name: "certificate",
|
|
|
|
PrivateKey: gatewayTestPrivateKey,
|
|
|
|
Certificate: gatewayTestCertificate,
|
|
|
|
}}, nil)
|
2023-02-17 17:46:03 +00:00
|
|
|
},
|
|
|
|
},
|
2023-03-17 17:31:04 +00:00
|
|
|
{
|
|
|
|
name: "api-gateway-with-http-route-and-inline-certificate",
|
|
|
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
|
|
|
return proxycfg.TestConfigSnapshotAPIGateway(t, "default", nil, func(entry *structs.APIGatewayConfigEntry, bound *structs.BoundAPIGatewayConfigEntry) {
|
|
|
|
entry.Listeners = []structs.APIGatewayListener{
|
|
|
|
{
|
|
|
|
Name: "listener",
|
|
|
|
Protocol: structs.ListenerProtocolHTTP,
|
|
|
|
Port: 8080,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
bound.Listeners = []structs.BoundAPIGatewayListener{
|
|
|
|
{
|
|
|
|
Name: "listener",
|
|
|
|
Routes: []structs.ResourceReference{{
|
|
|
|
Kind: structs.HTTPRoute,
|
|
|
|
Name: "route",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}, []structs.BoundRoute{
|
|
|
|
&structs.HTTPRouteConfigEntry{
|
|
|
|
Kind: structs.HTTPRoute,
|
|
|
|
Name: "route",
|
|
|
|
Rules: []structs.HTTPRouteRule{{
|
2023-06-12 16:58:05 +00:00
|
|
|
Filters: structs.HTTPFilters{
|
|
|
|
Headers: []structs.HTTPHeaderFilter{
|
|
|
|
{
|
|
|
|
Add: map[string]string{
|
|
|
|
"X-Header-Add": "added",
|
|
|
|
},
|
|
|
|
Set: map[string]string{
|
|
|
|
"X-Header-Set": "set",
|
|
|
|
},
|
|
|
|
Remove: []string{"X-Header-Remove"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-03-17 17:31:04 +00:00
|
|
|
Services: []structs.HTTPService{{
|
|
|
|
Name: "service",
|
|
|
|
}},
|
|
|
|
}},
|
2023-05-19 18:50:59 +00:00
|
|
|
Parents: []structs.ResourceReference{
|
|
|
|
{
|
|
|
|
Kind: structs.APIGateway,
|
|
|
|
Name: "api-gateway",
|
|
|
|
},
|
|
|
|
},
|
2023-03-17 17:31:04 +00:00
|
|
|
},
|
|
|
|
}, nil, []proxycfg.UpdateEvent{{
|
|
|
|
CorrelationID: "discovery-chain:" + serviceUID.String(),
|
|
|
|
Result: &structs.DiscoveryChainResponse{
|
|
|
|
Chain: serviceChain,
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
CorrelationID: "upstream-target:" + serviceChain.ID() + ":" + serviceUID.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: proxycfg.TestUpstreamNodes(t, "service"),
|
|
|
|
},
|
|
|
|
}})
|
|
|
|
},
|
|
|
|
},
|
2023-02-17 17:46:03 +00:00
|
|
|
}
|
|
|
|
}
|