2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 18:39:22 +00:00
|
|
|
|
2022-03-07 17:47:14 +00:00
|
|
|
package proxycfg
|
|
|
|
|
|
|
|
import (
|
2023-08-03 19:03:02 +00:00
|
|
|
"time"
|
|
|
|
|
2022-03-07 17:47:14 +00:00
|
|
|
"github.com/mitchellh/go-testing-interface"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2023-01-30 21:35:26 +00:00
|
|
|
"github.com/hashicorp/consul/api"
|
2022-03-07 17:47:14 +00:00
|
|
|
)
|
|
|
|
|
2022-05-24 16:51:52 +00:00
|
|
|
func TestConfigSnapshotTerminatingGateway(t testing.T, populateServices bool, nsFn func(ns *structs.NodeService), extraUpdates []UpdateEvent) *ConfigSnapshot {
|
2022-03-07 17:47:14 +00:00
|
|
|
roots, _ := TestCerts(t)
|
|
|
|
|
|
|
|
var (
|
|
|
|
web = structs.NewServiceName("web", nil)
|
|
|
|
api = structs.NewServiceName("api", nil)
|
|
|
|
db = structs.NewServiceName("db", nil)
|
|
|
|
cache = structs.NewServiceName("cache", nil)
|
|
|
|
)
|
|
|
|
|
2022-05-20 14:47:40 +00:00
|
|
|
baseEvents := []UpdateEvent{
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
CorrelationID: rootsWatchID,
|
|
|
|
Result: roots,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: gatewayServicesWatchID,
|
|
|
|
Result: &structs.IndexedGatewayServices{
|
|
|
|
Services: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-05-24 16:51:52 +00:00
|
|
|
tgtwyServices := []*structs.GatewayService{}
|
2022-03-07 17:47:14 +00:00
|
|
|
if populateServices {
|
|
|
|
webNodes := TestUpstreamNodes(t, web.Name)
|
|
|
|
webNodes[0].Service.Meta = map[string]string{"version": "1"}
|
|
|
|
webNodes[1].Service.Meta = map[string]string{"version": "2"}
|
|
|
|
|
|
|
|
apiNodes := structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "api",
|
|
|
|
Node: "test1",
|
|
|
|
Address: "10.10.1.1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "api",
|
|
|
|
Address: "api.mydomain",
|
|
|
|
Port: 8081,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{Status: "critical"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test2",
|
|
|
|
Node: "test2",
|
|
|
|
Address: "10.10.1.2",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "api",
|
|
|
|
Address: "api.altdomain",
|
|
|
|
Port: 8081,
|
|
|
|
Meta: map[string]string{
|
|
|
|
"domain": "alt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test3",
|
|
|
|
Node: "test3",
|
|
|
|
Address: "10.10.1.3",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "api",
|
|
|
|
Address: "10.10.1.3",
|
|
|
|
Port: 8081,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "test4",
|
|
|
|
Node: "test4",
|
|
|
|
Address: "10.10.1.4",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "api",
|
|
|
|
Address: "api.thirddomain",
|
|
|
|
Port: 8081,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has failing instance
|
|
|
|
dbNodes := structs.CheckServiceNodes{
|
|
|
|
structs.CheckServiceNode{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "db",
|
|
|
|
Node: "test4",
|
|
|
|
Address: "10.10.1.4",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "db",
|
|
|
|
Address: "db.mydomain",
|
|
|
|
Port: 8081,
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{Status: "critical"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has passing instance but failing subset
|
|
|
|
cacheNodes := structs.CheckServiceNodes{
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "cache",
|
|
|
|
Node: "test5",
|
|
|
|
Address: "10.10.1.5",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "cache",
|
|
|
|
Address: "cache.mydomain",
|
|
|
|
Port: 8081,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "cache",
|
|
|
|
Node: "test5",
|
|
|
|
Address: "10.10.1.5",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "cache",
|
|
|
|
Address: "cache.mydomain",
|
|
|
|
Port: 8081,
|
|
|
|
Meta: map[string]string{
|
|
|
|
"Env": "prod",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Checks: structs.HealthChecks{
|
|
|
|
{Status: "critical"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-05-24 16:51:52 +00:00
|
|
|
tgtwyServices = append(tgtwyServices,
|
|
|
|
&structs.GatewayService{
|
|
|
|
Service: web,
|
|
|
|
CAFile: "ca.cert.pem",
|
|
|
|
},
|
|
|
|
&structs.GatewayService{
|
|
|
|
Service: api,
|
|
|
|
CAFile: "ca.cert.pem",
|
|
|
|
CertFile: "api.cert.pem",
|
|
|
|
KeyFile: "api.key.pem",
|
|
|
|
},
|
|
|
|
&structs.GatewayService{
|
|
|
|
Service: db,
|
|
|
|
},
|
|
|
|
&structs.GatewayService{
|
|
|
|
Service: cache,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2022-05-20 14:47:40 +00:00
|
|
|
baseEvents = testSpliceEvents(baseEvents, []UpdateEvent{
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
CorrelationID: gatewayServicesWatchID,
|
|
|
|
Result: &structs.IndexedGatewayServices{
|
2022-05-24 16:51:52 +00:00
|
|
|
Services: tgtwyServices,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: externalServiceIDPrefix + web.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: webNodes,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: externalServiceIDPrefix + api.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: apiNodes,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: externalServiceIDPrefix + db.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: dbNodes,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: externalServiceIDPrefix + cache.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: cacheNodes,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// ========
|
|
|
|
// no intentions defined for these services
|
|
|
|
{
|
|
|
|
CorrelationID: serviceIntentionsIDPrefix + web.String(),
|
2023-04-20 16:16:04 +00:00
|
|
|
Result: structs.SimplifiedIntentions{},
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceIntentionsIDPrefix + api.String(),
|
2023-04-20 16:16:04 +00:00
|
|
|
Result: structs.SimplifiedIntentions{},
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceIntentionsIDPrefix + db.String(),
|
2023-04-20 16:16:04 +00:00
|
|
|
Result: structs.SimplifiedIntentions{},
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceIntentionsIDPrefix + cache.String(),
|
2023-04-20 16:16:04 +00:00
|
|
|
Result: structs.SimplifiedIntentions{},
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
// ========
|
|
|
|
{
|
|
|
|
CorrelationID: serviceLeafIDPrefix + web.String(),
|
|
|
|
Result: &structs.IssuedCert{
|
|
|
|
CertPEM: golden(t, "test-leaf-cert"),
|
|
|
|
PrivateKeyPEM: golden(t, "test-leaf-key"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceLeafIDPrefix + api.String(),
|
|
|
|
Result: &structs.IssuedCert{
|
|
|
|
CertPEM: golden(t, "alt-test-leaf-cert"),
|
|
|
|
PrivateKeyPEM: golden(t, "alt-test-leaf-key"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceLeafIDPrefix + db.String(),
|
|
|
|
Result: &structs.IssuedCert{
|
|
|
|
CertPEM: golden(t, "db-test-leaf-cert"),
|
|
|
|
PrivateKeyPEM: golden(t, "db-test-leaf-key"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceLeafIDPrefix + cache.String(),
|
|
|
|
Result: &structs.IssuedCert{
|
|
|
|
CertPEM: golden(t, "cache-test-leaf-cert"),
|
|
|
|
PrivateKeyPEM: golden(t, "cache-test-leaf-key"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// ========
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + web.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "tcp"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + api.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "tcp"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + db.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "tcp"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + cache.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "tcp"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// ========
|
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + web.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
},
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + api.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
},
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + db.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
},
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + cache.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
},
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return testConfigSnapshotFixture(t, &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindTerminatingGateway,
|
|
|
|
Service: "terminating-gateway",
|
|
|
|
Address: "1.2.3.4",
|
|
|
|
Port: 8443,
|
|
|
|
TaggedAddresses: map[string]structs.ServiceAddress{
|
|
|
|
structs.TaggedAddressWAN: {
|
|
|
|
Address: "198.18.0.1",
|
|
|
|
Port: 443,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nsFn, nil, testSpliceEvents(baseEvents, extraUpdates))
|
|
|
|
}
|
|
|
|
|
2022-05-24 16:51:52 +00:00
|
|
|
func TestConfigSnapshotTerminatingGatewayDestinations(t testing.T, populateDestinations bool, extraUpdates []UpdateEvent) *ConfigSnapshot {
|
|
|
|
roots, _ := TestCerts(t)
|
|
|
|
|
|
|
|
var (
|
2022-07-28 19:17:35 +00:00
|
|
|
externalIPTCP = structs.NewServiceName("external-IP-TCP", nil)
|
|
|
|
externalHostnameTCP = structs.NewServiceName("external-hostname-TCP", nil)
|
|
|
|
externalIPHTTP = structs.NewServiceName("external-IP-HTTP", nil)
|
|
|
|
externalHostnameHTTP = structs.NewServiceName("external-hostname-HTTP", nil)
|
|
|
|
externalHostnameWithSNI = structs.NewServiceName("external-hostname-with-SNI", nil)
|
2022-05-24 16:51:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
baseEvents := []UpdateEvent{
|
|
|
|
{
|
|
|
|
CorrelationID: rootsWatchID,
|
|
|
|
Result: roots,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: gatewayServicesWatchID,
|
|
|
|
Result: &structs.IndexedGatewayServices{
|
|
|
|
Services: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
tgtwyServices := []*structs.GatewayService{}
|
|
|
|
|
|
|
|
if populateDestinations {
|
|
|
|
tgtwyServices = append(tgtwyServices,
|
|
|
|
&structs.GatewayService{
|
|
|
|
Service: externalIPTCP,
|
|
|
|
ServiceKind: structs.GatewayServiceKindDestination,
|
|
|
|
},
|
|
|
|
&structs.GatewayService{
|
|
|
|
Service: externalHostnameTCP,
|
|
|
|
ServiceKind: structs.GatewayServiceKindDestination,
|
|
|
|
},
|
2022-07-14 18:45:51 +00:00
|
|
|
&structs.GatewayService{
|
|
|
|
Service: externalIPHTTP,
|
|
|
|
ServiceKind: structs.GatewayServiceKindDestination,
|
|
|
|
},
|
|
|
|
&structs.GatewayService{
|
|
|
|
Service: externalHostnameHTTP,
|
|
|
|
ServiceKind: structs.GatewayServiceKindDestination,
|
|
|
|
},
|
2022-07-28 19:17:35 +00:00
|
|
|
&structs.GatewayService{
|
|
|
|
Service: externalHostnameWithSNI,
|
|
|
|
ServiceKind: structs.GatewayServiceKindDestination,
|
|
|
|
CAFile: "cert.pem",
|
|
|
|
SNI: "api.test.com",
|
|
|
|
},
|
2022-05-24 16:51:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
baseEvents = testSpliceEvents(baseEvents, []UpdateEvent{
|
|
|
|
{
|
|
|
|
CorrelationID: gatewayServicesWatchID,
|
|
|
|
Result: &structs.IndexedGatewayServices{
|
|
|
|
Services: tgtwyServices,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// no intentions defined for these services
|
|
|
|
{
|
|
|
|
CorrelationID: serviceIntentionsIDPrefix + externalIPTCP.String(),
|
2023-04-20 16:16:04 +00:00
|
|
|
Result: structs.SimplifiedIntentions{},
|
2022-05-24 16:51:52 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceIntentionsIDPrefix + externalHostnameTCP.String(),
|
2023-04-20 16:16:04 +00:00
|
|
|
Result: structs.SimplifiedIntentions{},
|
2022-05-24 16:51:52 +00:00
|
|
|
},
|
2022-07-14 18:45:51 +00:00
|
|
|
{
|
|
|
|
CorrelationID: serviceIntentionsIDPrefix + externalIPHTTP.String(),
|
2023-04-20 16:16:04 +00:00
|
|
|
Result: structs.SimplifiedIntentions{},
|
2022-07-14 18:45:51 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceIntentionsIDPrefix + externalHostnameHTTP.String(),
|
2023-04-20 16:16:04 +00:00
|
|
|
Result: structs.SimplifiedIntentions{},
|
2022-07-14 18:45:51 +00:00
|
|
|
},
|
2022-07-28 19:17:35 +00:00
|
|
|
{
|
|
|
|
CorrelationID: serviceIntentionsIDPrefix + externalHostnameWithSNI.String(),
|
2023-04-20 16:16:04 +00:00
|
|
|
Result: structs.SimplifiedIntentions{},
|
2022-07-28 19:17:35 +00:00
|
|
|
},
|
2022-05-24 16:51:52 +00:00
|
|
|
// ========
|
|
|
|
{
|
|
|
|
CorrelationID: serviceLeafIDPrefix + externalIPTCP.String(),
|
|
|
|
Result: &structs.IssuedCert{
|
|
|
|
CertPEM: "placeholder.crt",
|
|
|
|
PrivateKeyPEM: "placeholder.key",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceLeafIDPrefix + externalHostnameTCP.String(),
|
|
|
|
Result: &structs.IssuedCert{
|
|
|
|
CertPEM: "placeholder.crt",
|
|
|
|
PrivateKeyPEM: "placeholder.key",
|
|
|
|
},
|
|
|
|
},
|
2022-07-14 18:45:51 +00:00
|
|
|
{
|
|
|
|
CorrelationID: serviceLeafIDPrefix + externalIPHTTP.String(),
|
|
|
|
Result: &structs.IssuedCert{
|
|
|
|
CertPEM: "placeholder.crt",
|
|
|
|
PrivateKeyPEM: "placeholder.key",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceLeafIDPrefix + externalHostnameHTTP.String(),
|
|
|
|
Result: &structs.IssuedCert{
|
|
|
|
CertPEM: "placeholder.crt",
|
|
|
|
PrivateKeyPEM: "placeholder.key",
|
|
|
|
},
|
|
|
|
},
|
2022-07-28 19:17:35 +00:00
|
|
|
{
|
|
|
|
CorrelationID: serviceLeafIDPrefix + externalHostnameWithSNI.String(),
|
|
|
|
Result: &structs.IssuedCert{
|
|
|
|
CertPEM: "placeholder.crt",
|
|
|
|
PrivateKeyPEM: "placeholder.key",
|
|
|
|
},
|
|
|
|
},
|
2022-05-24 16:51:52 +00:00
|
|
|
// ========
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + externalIPTCP.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
Mode: structs.ProxyModeTransparent,
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "tcp"},
|
|
|
|
Destination: structs.DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{
|
|
|
|
"192.168.0.1",
|
|
|
|
"192.168.0.2",
|
|
|
|
"192.168.0.3",
|
|
|
|
},
|
|
|
|
Port: 80,
|
2022-05-24 16:51:52 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + externalHostnameTCP.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
Mode: structs.ProxyModeTransparent,
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "tcp"},
|
|
|
|
Destination: structs.DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{
|
|
|
|
"api.hashicorp.com",
|
|
|
|
"web.hashicorp.com",
|
|
|
|
},
|
|
|
|
Port: 8089,
|
2022-05-24 16:51:52 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-14 18:45:51 +00:00
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + externalIPHTTP.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
Mode: structs.ProxyModeTransparent,
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
Destination: structs.DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{"192.168.0.2"},
|
|
|
|
Port: 80,
|
2022-07-14 18:45:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + externalHostnameHTTP.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
Mode: structs.ProxyModeTransparent,
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
Destination: structs.DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{"httpbin.org"},
|
|
|
|
Port: 80,
|
2022-07-14 18:45:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-28 19:17:35 +00:00
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + externalHostnameWithSNI.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
Mode: structs.ProxyModeTransparent,
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "tcp"},
|
|
|
|
Destination: structs.DestinationConfig{
|
|
|
|
Addresses: []string{"api.test.com"},
|
|
|
|
Port: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-05-24 16:51:52 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return testConfigSnapshotFixture(t, &structs.NodeService{
|
|
|
|
Kind: structs.ServiceKindTerminatingGateway,
|
|
|
|
Service: "terminating-gateway",
|
|
|
|
Address: "1.2.3.4",
|
|
|
|
Port: 8443,
|
|
|
|
Proxy: structs.ConnectProxyConfig{
|
|
|
|
Mode: structs.ProxyModeTransparent,
|
|
|
|
},
|
|
|
|
TaggedAddresses: map[string]structs.ServiceAddress{
|
|
|
|
structs.TaggedAddressWAN: {
|
|
|
|
Address: "198.18.0.1",
|
|
|
|
Port: 443,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil, nil, testSpliceEvents(baseEvents, extraUpdates))
|
|
|
|
}
|
|
|
|
|
2022-03-07 17:47:14 +00:00
|
|
|
func TestConfigSnapshotTerminatingGatewayServiceSubsets(t testing.T) *ConfigSnapshot {
|
2023-12-11 15:25:11 +00:00
|
|
|
return testConfigSnapshotTerminatingGatewayServiceSubsets(t, false, nil)
|
2022-03-07 17:47:14 +00:00
|
|
|
}
|
2023-12-11 15:25:11 +00:00
|
|
|
func TestConfigSnapshotTerminatingGatewayServiceSubsetsWebAndCache(t testing.T, nsFn func(ns *structs.NodeService)) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotTerminatingGatewayServiceSubsets(t, true, nsFn)
|
2022-03-07 17:47:14 +00:00
|
|
|
}
|
2023-12-11 15:25:11 +00:00
|
|
|
func testConfigSnapshotTerminatingGatewayServiceSubsets(t testing.T, alsoAdjustCache bool, nsFn func(ns *structs.NodeService)) *ConfigSnapshot {
|
2022-03-07 17:47:14 +00:00
|
|
|
var (
|
|
|
|
web = structs.NewServiceName("web", nil)
|
|
|
|
cache = structs.NewServiceName("cache", nil)
|
|
|
|
)
|
|
|
|
|
2022-05-20 14:47:40 +00:00
|
|
|
events := []UpdateEvent{
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + web.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.version == 2",
|
|
|
|
OnlyPassing: true,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + web.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if alsoAdjustCache {
|
2022-05-20 14:47:40 +00:00
|
|
|
events = testSpliceEvents(events, []UpdateEvent{
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + cache.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "cache",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"prod": {
|
|
|
|
Filter: "Service.Meta.Env == prod",
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + web.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-12-11 15:25:11 +00:00
|
|
|
return TestConfigSnapshotTerminatingGateway(t, true, nsFn, events)
|
2022-03-07 17:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotTerminatingGatewayDefaultServiceSubset(t testing.T) *ConfigSnapshot {
|
|
|
|
web := structs.NewServiceName("web", nil)
|
|
|
|
|
2022-05-20 14:47:40 +00:00
|
|
|
return TestConfigSnapshotTerminatingGateway(t, true, nil, []UpdateEvent{
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + web.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
DefaultSubset: "v2",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.version == 2",
|
|
|
|
OnlyPassing: true,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// {
|
|
|
|
// CorrelationID: serviceConfigIDPrefix + web.String(),
|
|
|
|
// Result: &structs.ServiceConfigResponse{
|
|
|
|
// ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotTerminatingGatewayLBConfig(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotTerminatingGatewayLBConfig(t, "default")
|
|
|
|
}
|
|
|
|
func TestConfigSnapshotTerminatingGatewayLBConfigNoHashPolicies(t testing.T) *ConfigSnapshot {
|
|
|
|
return testConfigSnapshotTerminatingGatewayLBConfig(t, "no-hash-policies")
|
|
|
|
}
|
|
|
|
func testConfigSnapshotTerminatingGatewayLBConfig(t testing.T, variant string) *ConfigSnapshot {
|
|
|
|
web := structs.NewServiceName("web", nil)
|
|
|
|
|
|
|
|
entry := &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
DefaultSubset: "v2",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.Version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.Version == 2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
2023-08-03 19:03:02 +00:00
|
|
|
RequestTimeout: 200 * time.Millisecond,
|
2022-03-07 17:47:14 +00:00
|
|
|
LoadBalancer: &structs.LoadBalancer{
|
|
|
|
Policy: "ring_hash",
|
|
|
|
RingHashConfig: &structs.RingHashConfig{
|
|
|
|
MinimumRingSize: 20,
|
|
|
|
MaximumRingSize: 50,
|
|
|
|
},
|
|
|
|
HashPolicies: []structs.HashPolicy{
|
|
|
|
{
|
|
|
|
Field: structs.HashPolicyCookie,
|
|
|
|
FieldValue: "chocolate-chip",
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Field: structs.HashPolicyHeader,
|
|
|
|
FieldValue: "x-user-id",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SourceIP: true,
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
switch variant {
|
|
|
|
case "default":
|
|
|
|
case "no-hash-policies":
|
|
|
|
entry.LoadBalancer.HashPolicies = nil
|
|
|
|
default:
|
|
|
|
t.Fatalf("unknown variant %q", variant)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-20 14:47:40 +00:00
|
|
|
return TestConfigSnapshotTerminatingGateway(t, true, nil, []UpdateEvent{
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + web.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + web.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: entry,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + web.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-31 20:46:14 +00:00
|
|
|
func TestConfigSnapshotTerminatingGatewaySNI(t testing.T) *ConfigSnapshot {
|
2022-05-20 14:47:40 +00:00
|
|
|
return TestConfigSnapshotTerminatingGateway(t, true, nil, []UpdateEvent{
|
2022-03-31 20:46:14 +00:00
|
|
|
{
|
|
|
|
CorrelationID: "gateway-services",
|
|
|
|
Result: &structs.IndexedGatewayServices{
|
|
|
|
Services: []*structs.GatewayService{
|
|
|
|
{
|
|
|
|
Service: structs.NewServiceName("web", nil),
|
|
|
|
CAFile: "ca.cert.pem",
|
|
|
|
SNI: "foo.com",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Service: structs.NewServiceName("api", nil),
|
|
|
|
CAFile: "ca.cert.pem",
|
|
|
|
CertFile: "api.cert.pem",
|
|
|
|
KeyFile: "api.key.pem",
|
|
|
|
SNI: "bar.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-07-08 20:21:05 +00:00
|
|
|
func TestConfigSnapshotTerminatingGatewayHTTP2(t testing.T) *ConfigSnapshot {
|
|
|
|
web := structs.NewServiceName("web", nil)
|
|
|
|
|
|
|
|
return TestConfigSnapshotTerminatingGateway(t, false, nil, []UpdateEvent{
|
|
|
|
{
|
|
|
|
CorrelationID: gatewayServicesWatchID,
|
|
|
|
Result: &structs.IndexedGatewayServices{
|
|
|
|
Services: []*structs.GatewayService{
|
|
|
|
{
|
2022-07-12 23:09:35 +00:00
|
|
|
Service: web,
|
|
|
|
CAFile: "ca.cert.pem",
|
2022-07-08 20:21:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + web.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: externalServiceIDPrefix + web.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: []structs.CheckServiceNode{
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "external",
|
|
|
|
Node: "external",
|
|
|
|
Address: "web.external.service",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "web",
|
|
|
|
Port: 9090,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotTerminatingGatewaySubsetsHTTP2(t testing.T) *ConfigSnapshot {
|
|
|
|
web := structs.NewServiceName("web", nil)
|
|
|
|
|
|
|
|
return TestConfigSnapshotTerminatingGateway(t, false, nil, []UpdateEvent{
|
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + web.String(),
|
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.version == 2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: gatewayServicesWatchID,
|
|
|
|
Result: &structs.IndexedGatewayServices{
|
|
|
|
Services: []*structs.GatewayService{
|
|
|
|
{
|
2022-07-12 23:09:35 +00:00
|
|
|
Service: web,
|
|
|
|
CAFile: "ca.cert.pem",
|
2022-07-08 20:21:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + web.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: externalServiceIDPrefix + web.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: []structs.CheckServiceNode{
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "external",
|
|
|
|
Node: "external",
|
|
|
|
Address: "web.external.service",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "web",
|
|
|
|
Port: 9090,
|
|
|
|
Meta: map[string]string{"version": "1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Node: &structs.Node{
|
|
|
|
ID: "external2",
|
|
|
|
Node: "external2",
|
|
|
|
Address: "web.external2.service",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
Service: &structs.NodeService{
|
|
|
|
Service: "web",
|
|
|
|
Port: 9091,
|
|
|
|
Meta: map[string]string{"version": "2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-07 17:47:14 +00:00
|
|
|
func TestConfigSnapshotTerminatingGatewayHostnameSubsets(t testing.T) *ConfigSnapshot {
|
|
|
|
var (
|
|
|
|
api = structs.NewServiceName("api", nil)
|
|
|
|
cache = structs.NewServiceName("cache", nil)
|
|
|
|
)
|
|
|
|
|
2022-05-20 14:47:40 +00:00
|
|
|
return TestConfigSnapshotTerminatingGateway(t, true, nil, []UpdateEvent{
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + api.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "api",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"alt": {
|
|
|
|
Filter: "Service.Meta.domain == alt",
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + cache.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "cache",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"prod": {
|
|
|
|
Filter: "Service.Meta.Env == prod",
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + api.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + cache.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotTerminatingGatewayIgnoreExtraResolvers(t testing.T) *ConfigSnapshot {
|
|
|
|
var (
|
|
|
|
web = structs.NewServiceName("web", nil)
|
|
|
|
notfound = structs.NewServiceName("notfound", nil)
|
|
|
|
)
|
|
|
|
|
2022-05-20 14:47:40 +00:00
|
|
|
return TestConfigSnapshotTerminatingGateway(t, true, nil, []UpdateEvent{
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + web.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "web",
|
|
|
|
DefaultSubset: "v2",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.Version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.Version == 2",
|
|
|
|
OnlyPassing: true,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceResolverIDPrefix + notfound.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "notfound",
|
|
|
|
DefaultSubset: "v2",
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.Version == 1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.Version == 2",
|
|
|
|
OnlyPassing: true,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: serviceConfigIDPrefix + web.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2022-03-15 14:07:40 +00:00
|
|
|
|
2022-05-20 14:47:40 +00:00
|
|
|
func TestConfigSnapshotTerminatingGatewayWithLambdaService(t testing.T, extraUpdateEvents ...UpdateEvent) *ConfigSnapshot {
|
2022-03-15 14:07:40 +00:00
|
|
|
web := structs.NewServiceName("web", nil)
|
2022-05-20 14:47:40 +00:00
|
|
|
updateEvents := append(extraUpdateEvents, UpdateEvent{
|
2022-04-13 15:45:25 +00:00
|
|
|
CorrelationID: serviceConfigIDPrefix + web.String(),
|
|
|
|
Result: &structs.ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{"protocol": "http"},
|
2022-12-19 20:19:37 +00:00
|
|
|
EnvoyExtensions: []structs.EnvoyExtension{
|
|
|
|
{
|
2023-01-30 21:35:26 +00:00
|
|
|
Name: api.BuiltinAWSLambdaExtension,
|
2022-12-19 20:19:37 +00:00
|
|
|
Arguments: map[string]interface{}{
|
2023-01-26 23:44:52 +00:00
|
|
|
"ARN": "arn:aws:lambda:us-east-1:111111111111:function:lambda-1234",
|
2022-12-19 20:19:37 +00:00
|
|
|
"PayloadPassthrough": true,
|
|
|
|
},
|
|
|
|
},
|
2022-03-15 14:07:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2022-04-13 15:45:25 +00:00
|
|
|
return TestConfigSnapshotTerminatingGateway(t, true, nil, updateEvents)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigSnapshotTerminatingGatewayWithLambdaServiceAndServiceResolvers(t testing.T) *ConfigSnapshot {
|
|
|
|
web := structs.NewServiceName("web", nil)
|
|
|
|
|
|
|
|
return TestConfigSnapshotTerminatingGatewayWithLambdaService(t,
|
2022-05-20 14:47:40 +00:00
|
|
|
UpdateEvent{
|
2022-04-13 15:45:25 +00:00
|
|
|
CorrelationID: serviceResolverIDPrefix + web.String(),
|
2022-05-12 20:34:17 +00:00
|
|
|
Result: &structs.ConfigEntryResponse{
|
|
|
|
Entry: &structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: web.String(),
|
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"canary1": {},
|
|
|
|
"canary2": {},
|
2022-04-13 15:45:25 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2022-03-15 14:07:40 +00:00
|
|
|
}
|