2022-05-27 02:18:47 +00:00
|
|
|
package proxycfg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/go-testing-interface"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2022-06-01 21:53:52 +00:00
|
|
|
"github.com/hashicorp/consul/proto/pbpeering"
|
2022-05-27 02:18:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfigSnapshotPeering(t testing.T) *ConfigSnapshot {
|
|
|
|
var (
|
|
|
|
paymentsUpstream = structs.Upstream{
|
|
|
|
DestinationName: "payments",
|
|
|
|
DestinationPeer: "cloud",
|
|
|
|
LocalBindPort: 9090,
|
|
|
|
}
|
|
|
|
paymentsUID = NewUpstreamID(&paymentsUpstream)
|
|
|
|
|
|
|
|
refundsUpstream = structs.Upstream{
|
|
|
|
DestinationName: "refunds",
|
|
|
|
DestinationPeer: "cloud",
|
|
|
|
LocalBindPort: 9090,
|
|
|
|
}
|
|
|
|
refundsUID = NewUpstreamID(&refundsUpstream)
|
|
|
|
)
|
|
|
|
|
2022-06-03 21:42:50 +00:00
|
|
|
const peerTrustDomain = "1c053652-8512-4373-90cf-5a7f6263a994.consul"
|
|
|
|
|
2022-05-27 02:18:47 +00:00
|
|
|
return TestConfigSnapshot(t, func(ns *structs.NodeService) {
|
|
|
|
ns.Proxy.Upstreams = structs.Upstreams{
|
|
|
|
paymentsUpstream,
|
|
|
|
refundsUpstream,
|
|
|
|
}
|
|
|
|
}, []UpdateEvent{
|
2022-06-01 21:53:52 +00:00
|
|
|
{
|
|
|
|
CorrelationID: peerTrustBundleIDPrefix + "cloud",
|
|
|
|
Result: &pbpeering.TrustBundleReadResponse{
|
|
|
|
Bundle: TestPeerTrustBundles(t).Bundles[0],
|
|
|
|
},
|
|
|
|
},
|
2022-05-27 02:18:47 +00:00
|
|
|
{
|
2022-06-03 21:42:50 +00:00
|
|
|
CorrelationID: upstreamPeerWatchIDPrefix + paymentsUID.String(),
|
2022-05-27 02:18:47 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: []structs.CheckServiceNode{
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
Address: "85.252.102.31",
|
|
|
|
Datacenter: "cloud-dc",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "payments-sidecar-proxy",
|
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
Port: 443,
|
|
|
|
Connect: structs.ServiceConnect{
|
|
|
|
PeerMeta: &structs.PeeringServiceMeta{
|
2022-06-03 21:42:50 +00:00
|
|
|
SNI: []string{
|
|
|
|
"payments.default.default.cloud.external." + peerTrustDomain,
|
|
|
|
},
|
|
|
|
SpiffeID: []string{
|
|
|
|
"spiffe://" + peerTrustDomain + "/ns/default/dc/cloud-dc/svc/payments",
|
|
|
|
},
|
|
|
|
Protocol: "tcp",
|
2022-05-27 02:18:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-06-03 21:42:50 +00:00
|
|
|
CorrelationID: upstreamPeerWatchIDPrefix + refundsUID.String(),
|
2022-05-27 02:18:47 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: []structs.CheckServiceNode{
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
Address: "106.96.90.233",
|
|
|
|
Datacenter: "cloud-dc",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "refunds-sidecar-proxy",
|
|
|
|
Kind: structs.ServiceKindConnectProxy,
|
|
|
|
Port: 443,
|
|
|
|
Connect: structs.ServiceConnect{
|
|
|
|
PeerMeta: &structs.PeeringServiceMeta{
|
2022-06-03 21:42:50 +00:00
|
|
|
SNI: []string{
|
|
|
|
"refunds.default.default.cloud.external." + peerTrustDomain,
|
|
|
|
},
|
|
|
|
SpiffeID: []string{
|
|
|
|
"spiffe://" + peerTrustDomain + "/ns/default/dc/cloud-dc/svc/refunds",
|
|
|
|
},
|
|
|
|
Protocol: "tcp",
|
2022-05-27 02:18:47 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|