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
|
|
|
|
2019-04-30 22:19:19 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
2019-05-02 13:11:33 +00:00
|
|
|
"bytes"
|
2019-07-12 17:20:30 +00:00
|
|
|
"strings"
|
2019-04-30 22:19:19 +00:00
|
|
|
"testing"
|
2019-07-12 17:20:30 +00:00
|
|
|
"time"
|
2019-04-30 22:19:19 +00:00
|
|
|
|
2021-08-27 15:00:07 +00:00
|
|
|
"github.com/google/go-cmp/cmp"
|
2019-07-12 17:20:30 +00:00
|
|
|
"github.com/hashicorp/hcl"
|
2021-08-17 11:27:31 +00:00
|
|
|
"github.com/mitchellh/copystructure"
|
2021-03-11 04:04:13 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-04-30 22:19:19 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-04-15 19:21:44 +00:00
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
"github.com/hashicorp/consul-net-rpc/go-msgpack/codec"
|
|
|
|
|
2021-08-20 22:11:01 +00:00
|
|
|
"github.com/hashicorp/consul/acl"
|
2021-05-14 15:15:48 +00:00
|
|
|
"github.com/hashicorp/consul/agent/cache"
|
2023-01-30 21:35:26 +00:00
|
|
|
"github.com/hashicorp/consul/api"
|
2021-04-15 19:21:44 +00:00
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
2022-01-11 16:46:42 +00:00
|
|
|
"github.com/hashicorp/consul/types"
|
2019-04-30 22:19:19 +00:00
|
|
|
)
|
|
|
|
|
2021-08-20 22:11:01 +00:00
|
|
|
func TestConfigEntries_ACLs(t *testing.T) {
|
|
|
|
type testACL = configEntryTestACL
|
|
|
|
type testcase = configEntryACLTestCase
|
|
|
|
|
|
|
|
newAuthz := func(t *testing.T, src string) acl.Authorizer {
|
2023-02-06 15:35:52 +00:00
|
|
|
policy, err := acl.NewPolicyFromSource(src, nil, nil)
|
2021-08-20 22:11:01 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
authorizer, err := acl.NewPolicyAuthorizerWithDefaults(acl.DenyAll(), []*acl.Policy{policy}, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return authorizer
|
|
|
|
}
|
|
|
|
|
|
|
|
cases := []testcase{
|
|
|
|
// =================== proxy-defaults ===================
|
|
|
|
{
|
|
|
|
name: "proxy-defaults",
|
|
|
|
entry: &ProxyConfigEntry{},
|
|
|
|
expectACLs: []testACL{
|
|
|
|
{
|
|
|
|
name: "no-authz",
|
|
|
|
authorizer: newAuthz(t, ``),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "proxy-defaults: operator deny",
|
|
|
|
authorizer: newAuthz(t, `operator = "deny"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "proxy-defaults: operator read",
|
|
|
|
authorizer: newAuthz(t, `operator = "read"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "proxy-defaults: operator write",
|
|
|
|
authorizer: newAuthz(t, `operator = "write"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "proxy-defaults: mesh deny",
|
|
|
|
authorizer: newAuthz(t, `mesh = "deny"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "proxy-defaults: mesh read",
|
|
|
|
authorizer: newAuthz(t, `mesh = "read"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "proxy-defaults: mesh write",
|
|
|
|
authorizer: newAuthz(t, `mesh = "write"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "proxy-defaults: operator deny and mesh read",
|
|
|
|
authorizer: newAuthz(t, `operator = "deny" mesh = "read"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "proxy-defaults: operator deny and mesh write",
|
|
|
|
authorizer: newAuthz(t, `operator = "deny" mesh = "write"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// =================== mesh ===================
|
|
|
|
{
|
|
|
|
name: "mesh",
|
|
|
|
entry: &MeshConfigEntry{},
|
|
|
|
expectACLs: []testACL{
|
|
|
|
{
|
|
|
|
name: "no-authz",
|
|
|
|
authorizer: newAuthz(t, ``),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh: operator deny",
|
|
|
|
authorizer: newAuthz(t, `operator = "deny"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh: operator read",
|
|
|
|
authorizer: newAuthz(t, `operator = "read"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh: operator write",
|
|
|
|
authorizer: newAuthz(t, `operator = "write"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh: mesh deny",
|
|
|
|
authorizer: newAuthz(t, `mesh = "deny"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh: mesh read",
|
|
|
|
authorizer: newAuthz(t, `mesh = "read"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh: mesh write",
|
|
|
|
authorizer: newAuthz(t, `mesh = "write"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh: operator deny and mesh read",
|
|
|
|
authorizer: newAuthz(t, `operator = "deny" mesh = "read"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh: operator deny and mesh write",
|
|
|
|
authorizer: newAuthz(t, `operator = "deny" mesh = "write"`),
|
|
|
|
canRead: true, // unauthenticated
|
|
|
|
canWrite: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
testConfigEntries_ListRelatedServices_AndACLs(t, cases)
|
|
|
|
}
|
|
|
|
|
|
|
|
type configEntryTestACL struct {
|
|
|
|
name string
|
|
|
|
authorizer acl.Authorizer
|
|
|
|
canRead bool
|
|
|
|
canWrite bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type configEntryACLTestCase struct {
|
|
|
|
name string
|
|
|
|
entry ConfigEntry
|
|
|
|
expectServices []ServiceID // optional
|
|
|
|
expectACLs []configEntryTestACL
|
|
|
|
}
|
|
|
|
|
|
|
|
func testConfigEntries_ListRelatedServices_AndACLs(t *testing.T, cases []configEntryACLTestCase) {
|
2023-02-03 15:51:53 +00:00
|
|
|
|
2021-08-20 22:11:01 +00:00
|
|
|
// This test tests both of these because they are related functions.
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
// verify test inputs
|
|
|
|
require.NoError(t, tc.entry.Normalize())
|
|
|
|
require.NoError(t, tc.entry.Validate())
|
|
|
|
|
|
|
|
if dce, ok := tc.entry.(discoveryChainConfigEntry); ok {
|
|
|
|
got := dce.ListRelatedServices()
|
|
|
|
require.Equal(t, tc.expectServices, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tc.expectACLs) == 1 {
|
|
|
|
a := tc.expectACLs[0]
|
|
|
|
require.Empty(t, a.name)
|
|
|
|
} else {
|
|
|
|
for _, a := range tc.expectACLs {
|
|
|
|
require.NotEmpty(t, a.name)
|
|
|
|
t.Run(a.name, func(t *testing.T) {
|
2022-03-11 21:45:51 +00:00
|
|
|
canRead := tc.entry.CanRead(a.authorizer)
|
|
|
|
if a.canRead {
|
|
|
|
require.Nil(t, canRead)
|
|
|
|
} else {
|
|
|
|
require.Error(t, canRead)
|
|
|
|
require.True(t, acl.IsErrPermissionDenied(canRead))
|
|
|
|
}
|
|
|
|
canWrite := tc.entry.CanWrite(a.authorizer)
|
|
|
|
if a.canWrite {
|
|
|
|
require.Nil(t, canWrite)
|
|
|
|
} else {
|
|
|
|
require.Error(t, canWrite)
|
|
|
|
require.True(t, acl.IsErrPermissionDenied(canWrite))
|
|
|
|
}
|
2021-08-20 22:11:01 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-19 18:11:21 +00:00
|
|
|
func TestDecodeConfigEntry_ServiceDefaults(t *testing.T) {
|
|
|
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
camel string
|
|
|
|
snake string
|
|
|
|
expect ConfigEntry
|
|
|
|
expectErr string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "service-defaults-with-MaxInboundConnections",
|
|
|
|
snake: `
|
|
|
|
kind = "service-defaults"
|
|
|
|
name = "external"
|
|
|
|
protocol = "tcp"
|
|
|
|
destination {
|
|
|
|
addresses = [
|
|
|
|
"api.google.com",
|
|
|
|
"web.google.com"
|
|
|
|
]
|
|
|
|
port = 8080
|
|
|
|
}
|
|
|
|
max_inbound_connections = 14
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "service-defaults"
|
|
|
|
Name = "external"
|
|
|
|
Protocol = "tcp"
|
|
|
|
Destination {
|
|
|
|
Addresses = [
|
|
|
|
"api.google.com",
|
|
|
|
"web.google.com"
|
|
|
|
]
|
|
|
|
Port = 8080
|
|
|
|
}
|
|
|
|
MaxInboundConnections = 14
|
|
|
|
`,
|
|
|
|
expect: &ServiceConfigEntry{
|
|
|
|
Kind: "service-defaults",
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "tcp",
|
|
|
|
Destination: &DestinationConfig{
|
|
|
|
Addresses: []string{
|
|
|
|
"api.google.com",
|
|
|
|
"web.google.com",
|
|
|
|
},
|
|
|
|
Port: 8080,
|
|
|
|
},
|
|
|
|
MaxInboundConnections: 14,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
tc := tc
|
|
|
|
|
|
|
|
testbody := func(t *testing.T, body string) {
|
|
|
|
var raw map[string]interface{}
|
|
|
|
err := hcl.Decode(&raw, body)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
got, err := DecodeConfigEntry(raw)
|
|
|
|
if tc.expectErr != "" {
|
|
|
|
require.Nil(t, got)
|
|
|
|
require.Error(t, err)
|
|
|
|
requireContainsLower(t, err.Error(), tc.expectErr)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, tc.expect, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(tc.name+" (snake case)", func(t *testing.T) {
|
|
|
|
testbody(t, tc.snake)
|
|
|
|
})
|
|
|
|
t.Run(tc.name+" (camel case)", func(t *testing.T) {
|
|
|
|
testbody(t, tc.camel)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 17:20:30 +00:00
|
|
|
// TestDecodeConfigEntry is the 'structs' mirror image of
|
2023-01-18 22:14:34 +00:00
|
|
|
// command/helpers/helpers_test.go:TestParseConfigEntry
|
2019-04-30 22:19:19 +00:00
|
|
|
func TestDecodeConfigEntry(t *testing.T) {
|
|
|
|
|
2019-07-12 17:20:30 +00:00
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
camel string
|
|
|
|
snake string
|
|
|
|
expect ConfigEntry
|
|
|
|
expectErr string
|
|
|
|
}{
|
|
|
|
// TODO(rb): test json?
|
|
|
|
{
|
|
|
|
name: "proxy-defaults: extra fields or typo",
|
|
|
|
snake: `
|
|
|
|
kind = "proxy-defaults"
|
|
|
|
name = "main"
|
|
|
|
cornfig {
|
|
|
|
"foo" = 19
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "proxy-defaults"
|
|
|
|
Name = "main"
|
|
|
|
Cornfig {
|
|
|
|
"foo" = 19
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expectErr: `invalid config key "cornfig"`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "proxy-defaults",
|
|
|
|
snake: `
|
|
|
|
kind = "proxy-defaults"
|
|
|
|
name = "main"
|
2020-09-02 19:10:25 +00:00
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
config {
|
|
|
|
"foo" = 19
|
|
|
|
"bar" = "abc"
|
|
|
|
"moreconfig" {
|
|
|
|
"moar" = "config"
|
|
|
|
}
|
2022-09-26 16:29:06 +00:00
|
|
|
"balance_inbound_connections" = "exact_balance"
|
2019-07-12 17:20:30 +00:00
|
|
|
}
|
|
|
|
mesh_gateway {
|
|
|
|
mode = "remote"
|
|
|
|
}
|
2023-04-19 19:45:00 +00:00
|
|
|
mutual_tls_mode = "permissive"
|
2019-07-12 17:20:30 +00:00
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "proxy-defaults"
|
|
|
|
Name = "main"
|
2020-09-02 19:10:25 +00:00
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
Config {
|
|
|
|
"foo" = 19
|
|
|
|
"bar" = "abc"
|
|
|
|
"moreconfig" {
|
|
|
|
"moar" = "config"
|
|
|
|
}
|
2022-09-26 16:29:06 +00:00
|
|
|
"balance_inbound_connections" = "exact_balance"
|
2019-07-12 17:20:30 +00:00
|
|
|
}
|
|
|
|
MeshGateway {
|
|
|
|
Mode = "remote"
|
|
|
|
}
|
2023-04-19 19:45:00 +00:00
|
|
|
MutualTLSMode = "permissive"
|
2019-07-12 17:20:30 +00:00
|
|
|
`,
|
|
|
|
expect: &ProxyConfigEntry{
|
|
|
|
Kind: "proxy-defaults",
|
|
|
|
Name: "main",
|
2020-09-02 19:10:25 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
2019-04-30 22:19:19 +00:00
|
|
|
Config: map[string]interface{}{
|
2019-07-12 17:20:30 +00:00
|
|
|
"foo": 19,
|
|
|
|
"bar": "abc",
|
|
|
|
"moreconfig": map[string]interface{}{
|
|
|
|
"moar": "config",
|
|
|
|
},
|
2022-09-26 16:29:06 +00:00
|
|
|
"balance_inbound_connections": "exact_balance",
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
MeshGateway: MeshGatewayConfig{
|
|
|
|
Mode: MeshGatewayModeRemote,
|
2019-04-30 22:19:19 +00:00
|
|
|
},
|
2023-04-19 19:45:00 +00:00
|
|
|
MutualTLSMode: MutualTLSModePermissive,
|
2019-04-30 22:19:19 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
{
|
|
|
|
name: "service-defaults",
|
|
|
|
snake: `
|
|
|
|
kind = "service-defaults"
|
|
|
|
name = "main"
|
2020-09-02 19:10:25 +00:00
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
protocol = "http"
|
2019-08-19 17:19:44 +00:00
|
|
|
external_sni = "abc-123"
|
2019-07-12 17:20:30 +00:00
|
|
|
mesh_gateway {
|
|
|
|
mode = "remote"
|
|
|
|
}
|
2023-04-19 19:45:00 +00:00
|
|
|
mutual_tls_mode = "permissive"
|
2022-09-26 16:29:06 +00:00
|
|
|
balance_inbound_connections = "exact_balance"
|
2021-04-15 19:21:44 +00:00
|
|
|
upstream_config {
|
|
|
|
overrides = [
|
|
|
|
{
|
|
|
|
name = "redis"
|
2021-03-09 05:10:27 +00:00
|
|
|
passive_health_check {
|
|
|
|
interval = "2s"
|
|
|
|
max_failures = 3
|
2023-04-26 22:59:48 +00:00
|
|
|
enforcing_consecutive_5xx = 4
|
|
|
|
max_ejection_percent = 5
|
|
|
|
base_ejection_time = "6s"
|
2021-03-09 05:10:27 +00:00
|
|
|
}
|
2021-04-15 19:21:44 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "finance--billing"
|
2021-03-09 05:10:27 +00:00
|
|
|
mesh_gateway {
|
|
|
|
mode = "remote"
|
|
|
|
}
|
2021-04-15 19:21:44 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
defaults {
|
2021-03-09 05:10:27 +00:00
|
|
|
connect_timeout_ms = 5
|
|
|
|
protocol = "http"
|
2022-09-26 16:29:06 +00:00
|
|
|
balance_outbound_connections = "exact_balance"
|
2021-03-15 20:12:57 +00:00
|
|
|
envoy_listener_json = "foo"
|
|
|
|
envoy_cluster_json = "bar"
|
2021-03-09 05:10:27 +00:00
|
|
|
limits {
|
|
|
|
max_connections = 3
|
|
|
|
max_pending_requests = 4
|
|
|
|
max_concurrent_requests = 5
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "service-defaults"
|
|
|
|
Name = "main"
|
2020-09-02 19:10:25 +00:00
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
Protocol = "http"
|
2019-08-19 17:19:44 +00:00
|
|
|
ExternalSNI = "abc-123"
|
2019-07-12 17:20:30 +00:00
|
|
|
MeshGateway {
|
|
|
|
Mode = "remote"
|
|
|
|
}
|
2023-04-19 19:45:00 +00:00
|
|
|
MutualTLSMode = "permissive"
|
2022-09-26 16:29:06 +00:00
|
|
|
BalanceInboundConnections = "exact_balance"
|
2021-04-15 19:21:44 +00:00
|
|
|
UpstreamConfig {
|
|
|
|
Overrides = [
|
|
|
|
{
|
|
|
|
Name = "redis"
|
2021-03-09 05:10:27 +00:00
|
|
|
PassiveHealthCheck {
|
|
|
|
MaxFailures = 3
|
|
|
|
Interval = "2s"
|
2023-04-26 22:59:48 +00:00
|
|
|
EnforcingConsecutive5xx = 4
|
|
|
|
MaxEjectionPercent = 5
|
|
|
|
BaseEjectionTime = "6s"
|
2021-03-09 05:10:27 +00:00
|
|
|
}
|
2021-04-15 19:21:44 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "finance--billing"
|
2021-03-09 05:10:27 +00:00
|
|
|
MeshGateway {
|
|
|
|
Mode = "remote"
|
|
|
|
}
|
2021-04-15 19:21:44 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
Defaults {
|
2021-03-15 20:12:57 +00:00
|
|
|
EnvoyListenerJSON = "foo"
|
|
|
|
EnvoyClusterJSON = "bar"
|
2021-03-09 05:10:27 +00:00
|
|
|
ConnectTimeoutMs = 5
|
|
|
|
Protocol = "http"
|
|
|
|
Limits {
|
|
|
|
MaxConnections = 3
|
|
|
|
MaxPendingRequests = 4
|
|
|
|
MaxConcurrentRequests = 5
|
|
|
|
}
|
2022-09-26 16:29:06 +00:00
|
|
|
BalanceOutboundConnections = "exact_balance"
|
2021-03-09 05:10:27 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
`,
|
|
|
|
expect: &ServiceConfigEntry{
|
2020-09-02 19:10:25 +00:00
|
|
|
Kind: "service-defaults",
|
|
|
|
Name: "main",
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
2019-08-19 17:19:44 +00:00
|
|
|
Protocol: "http",
|
|
|
|
ExternalSNI: "abc-123",
|
2019-07-12 17:20:30 +00:00
|
|
|
MeshGateway: MeshGatewayConfig{
|
|
|
|
Mode: MeshGatewayModeRemote,
|
2019-04-30 22:19:19 +00:00
|
|
|
},
|
2023-04-19 19:45:00 +00:00
|
|
|
MutualTLSMode: MutualTLSModePermissive,
|
2022-09-26 16:29:06 +00:00
|
|
|
BalanceInboundConnections: "exact_balance",
|
2021-04-15 19:21:44 +00:00
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Overrides: []*UpstreamConfig{
|
|
|
|
{
|
|
|
|
Name: "redis",
|
2021-03-11 18:04:40 +00:00
|
|
|
PassiveHealthCheck: &PassiveHealthCheck{
|
2023-04-26 22:59:48 +00:00
|
|
|
MaxFailures: 3,
|
|
|
|
Interval: 2 * time.Second,
|
|
|
|
EnforcingConsecutive5xx: uintPointer(4),
|
|
|
|
MaxEjectionPercent: uintPointer(5),
|
|
|
|
BaseEjectionTime: durationPointer(6 * time.Second),
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
|
|
|
},
|
2021-04-15 19:21:44 +00:00
|
|
|
{
|
|
|
|
Name: "finance--billing",
|
2021-03-09 05:10:27 +00:00
|
|
|
MeshGateway: MeshGatewayConfig{Mode: MeshGatewayModeRemote},
|
|
|
|
},
|
|
|
|
},
|
2021-04-15 19:21:44 +00:00
|
|
|
Defaults: &UpstreamConfig{
|
2021-03-15 20:12:57 +00:00
|
|
|
EnvoyListenerJSON: "foo",
|
|
|
|
EnvoyClusterJSON: "bar",
|
|
|
|
ConnectTimeoutMs: 5,
|
|
|
|
Protocol: "http",
|
2021-03-11 18:04:40 +00:00
|
|
|
Limits: &UpstreamLimits{
|
2021-03-09 05:10:27 +00:00
|
|
|
MaxConnections: intPointer(3),
|
|
|
|
MaxPendingRequests: intPointer(4),
|
|
|
|
MaxConcurrentRequests: intPointer(5),
|
|
|
|
},
|
2022-09-26 16:29:06 +00:00
|
|
|
BalanceOutboundConnections: "exact_balance",
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
|
|
|
},
|
2019-04-30 22:19:19 +00:00
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
2022-05-19 22:15:57 +00:00
|
|
|
{
|
2022-05-31 20:20:12 +00:00
|
|
|
name: "service-defaults-with-destination",
|
2022-05-19 22:15:57 +00:00
|
|
|
snake: `
|
|
|
|
kind = "service-defaults"
|
|
|
|
name = "external"
|
|
|
|
protocol = "tcp"
|
2022-05-31 20:20:12 +00:00
|
|
|
destination {
|
2022-07-18 21:10:06 +00:00
|
|
|
addresses = [
|
|
|
|
"api.google.com",
|
|
|
|
"web.google.com"
|
|
|
|
]
|
2022-05-19 22:15:57 +00:00
|
|
|
port = 8080
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "service-defaults"
|
|
|
|
Name = "external"
|
|
|
|
Protocol = "tcp"
|
2022-05-31 20:20:12 +00:00
|
|
|
Destination {
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses = [
|
|
|
|
"api.google.com",
|
|
|
|
"web.google.com"
|
|
|
|
]
|
2022-05-19 22:15:57 +00:00
|
|
|
Port = 8080
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expect: &ServiceConfigEntry{
|
|
|
|
Kind: "service-defaults",
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "tcp",
|
2022-05-31 20:20:12 +00:00
|
|
|
Destination: &DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{
|
|
|
|
"api.google.com",
|
|
|
|
"web.google.com",
|
|
|
|
},
|
|
|
|
Port: 8080,
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
{
|
|
|
|
name: "service-router: kitchen sink",
|
|
|
|
snake: `
|
|
|
|
kind = "service-router"
|
|
|
|
name = "main"
|
2020-09-02 19:10:25 +00:00
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
routes = [
|
|
|
|
{
|
|
|
|
match {
|
|
|
|
http {
|
|
|
|
path_exact = "/foo"
|
|
|
|
header = [
|
|
|
|
{
|
|
|
|
name = "debug1"
|
|
|
|
present = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "debug2"
|
|
|
|
present = false
|
|
|
|
invert = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "debug3"
|
|
|
|
exact = "1"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "debug4"
|
|
|
|
prefix = "aaa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "debug5"
|
|
|
|
suffix = "bbb"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "debug6"
|
|
|
|
regex = "a.*z"
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
destination {
|
|
|
|
service = "carrot"
|
|
|
|
service_subset = "kale"
|
|
|
|
namespace = "leek"
|
|
|
|
prefix_rewrite = "/alternate"
|
|
|
|
request_timeout = "99s"
|
2022-11-29 22:43:15 +00:00
|
|
|
idle_timeout = "99s"
|
2019-07-12 17:20:30 +00:00
|
|
|
num_retries = 12345
|
|
|
|
retry_on_connect_failure = true
|
|
|
|
retry_on_status_codes = [401, 209]
|
2021-07-13 11:25:59 +00:00
|
|
|
request_headers {
|
|
|
|
add {
|
2021-07-14 16:13:13 +00:00
|
|
|
x-foo = "bar"
|
2021-07-13 11:25:59 +00:00
|
|
|
}
|
|
|
|
set {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
remove = ["qux"]
|
|
|
|
}
|
|
|
|
response_headers {
|
|
|
|
add {
|
2021-07-14 16:13:13 +00:00
|
|
|
x-foo = "bar"
|
2021-07-13 11:25:59 +00:00
|
|
|
}
|
|
|
|
set {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
remove = ["qux"]
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
match {
|
|
|
|
http {
|
|
|
|
path_prefix = "/foo"
|
2019-07-24 01:56:39 +00:00
|
|
|
methods = [ "GET", "DELETE" ]
|
2019-07-12 17:20:30 +00:00
|
|
|
query_param = [
|
|
|
|
{
|
|
|
|
name = "hack1"
|
2019-07-24 01:55:26 +00:00
|
|
|
present = true
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "hack2"
|
2019-07-24 01:55:26 +00:00
|
|
|
exact = "1"
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "hack3"
|
2019-07-24 01:55:26 +00:00
|
|
|
regex = "a.*z"
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
match {
|
|
|
|
http {
|
|
|
|
path_regex = "/foo"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "service-router"
|
|
|
|
Name = "main"
|
2020-09-02 19:10:25 +00:00
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
Routes = [
|
|
|
|
{
|
|
|
|
Match {
|
|
|
|
HTTP {
|
|
|
|
PathExact = "/foo"
|
|
|
|
Header = [
|
|
|
|
{
|
|
|
|
Name = "debug1"
|
|
|
|
Present = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "debug2"
|
|
|
|
Present = false
|
|
|
|
Invert = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "debug3"
|
|
|
|
Exact = "1"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "debug4"
|
|
|
|
Prefix = "aaa"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "debug5"
|
|
|
|
Suffix = "bbb"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "debug6"
|
|
|
|
Regex = "a.*z"
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Destination {
|
|
|
|
Service = "carrot"
|
|
|
|
ServiceSubset = "kale"
|
|
|
|
Namespace = "leek"
|
|
|
|
PrefixRewrite = "/alternate"
|
|
|
|
RequestTimeout = "99s"
|
2022-11-29 22:43:15 +00:00
|
|
|
IdleTimeout = "99s"
|
2019-07-12 17:20:30 +00:00
|
|
|
NumRetries = 12345
|
|
|
|
RetryOnConnectFailure = true
|
|
|
|
RetryOnStatusCodes = [401, 209]
|
2021-07-13 11:25:59 +00:00
|
|
|
RequestHeaders {
|
|
|
|
Add {
|
2021-07-14 16:13:13 +00:00
|
|
|
x-foo = "bar"
|
2021-07-13 11:25:59 +00:00
|
|
|
}
|
|
|
|
Set {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
Remove = ["qux"]
|
|
|
|
}
|
|
|
|
ResponseHeaders {
|
|
|
|
Add {
|
2021-07-14 16:13:13 +00:00
|
|
|
x-foo = "bar"
|
2021-07-13 11:25:59 +00:00
|
|
|
}
|
|
|
|
Set {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
Remove = ["qux"]
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match {
|
|
|
|
HTTP {
|
|
|
|
PathPrefix = "/foo"
|
2019-07-24 01:56:39 +00:00
|
|
|
Methods = [ "GET", "DELETE" ]
|
2019-07-12 17:20:30 +00:00
|
|
|
QueryParam = [
|
|
|
|
{
|
|
|
|
Name = "hack1"
|
2019-07-24 01:55:26 +00:00
|
|
|
Present = true
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "hack2"
|
2019-07-24 01:55:26 +00:00
|
|
|
Exact = "1"
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "hack3"
|
2019-07-24 01:55:26 +00:00
|
|
|
Regex = "a.*z"
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match {
|
|
|
|
HTTP {
|
|
|
|
PathRegex = "/foo"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
|
|
|
`,
|
|
|
|
expect: &ServiceRouterConfigEntry{
|
|
|
|
Kind: "service-router",
|
|
|
|
Name: "main",
|
2020-09-02 19:10:25 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
Routes: []ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &ServiceRouteMatch{
|
|
|
|
HTTP: &ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/foo",
|
|
|
|
Header: []ServiceRouteHTTPMatchHeader{
|
|
|
|
{
|
|
|
|
Name: "debug1",
|
|
|
|
Present: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "debug2",
|
|
|
|
Present: false,
|
|
|
|
Invert: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "debug3",
|
|
|
|
Exact: "1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "debug4",
|
|
|
|
Prefix: "aaa",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "debug5",
|
|
|
|
Suffix: "bbb",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "debug6",
|
|
|
|
Regex: "a.*z",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &ServiceRouteDestination{
|
|
|
|
Service: "carrot",
|
|
|
|
ServiceSubset: "kale",
|
|
|
|
Namespace: "leek",
|
|
|
|
PrefixRewrite: "/alternate",
|
|
|
|
RequestTimeout: 99 * time.Second,
|
2022-11-29 22:43:15 +00:00
|
|
|
IdleTimeout: 99 * time.Second,
|
2019-07-12 17:20:30 +00:00
|
|
|
NumRetries: 12345,
|
|
|
|
RetryOnConnectFailure: true,
|
|
|
|
RetryOnStatusCodes: []uint32{401, 209},
|
2021-07-13 11:25:59 +00:00
|
|
|
RequestHeaders: &HTTPHeaderModifiers{
|
2021-07-14 16:13:13 +00:00
|
|
|
Add: map[string]string{"x-foo": "bar"},
|
2021-07-13 11:25:59 +00:00
|
|
|
Set: map[string]string{"bar": "baz"},
|
|
|
|
Remove: []string{"qux"},
|
|
|
|
},
|
|
|
|
ResponseHeaders: &HTTPHeaderModifiers{
|
2021-07-14 16:13:13 +00:00
|
|
|
Add: map[string]string{"x-foo": "bar"},
|
2021-07-13 11:25:59 +00:00
|
|
|
Set: map[string]string{"bar": "baz"},
|
|
|
|
Remove: []string{"qux"},
|
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: &ServiceRouteMatch{
|
|
|
|
HTTP: &ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/foo",
|
2019-07-24 01:56:39 +00:00
|
|
|
Methods: []string{"GET", "DELETE"},
|
2019-07-12 17:20:30 +00:00
|
|
|
QueryParam: []ServiceRouteHTTPMatchQueryParam{
|
|
|
|
{
|
2019-07-24 01:55:26 +00:00
|
|
|
Name: "hack1",
|
|
|
|
Present: true,
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "hack2",
|
2019-07-24 01:55:26 +00:00
|
|
|
Exact: "1",
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "hack3",
|
2019-07-24 01:55:26 +00:00
|
|
|
Regex: "a.*z",
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: &ServiceRouteMatch{
|
|
|
|
HTTP: &ServiceRouteHTTPMatch{
|
|
|
|
PathRegex: "/foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-04-30 22:19:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
{
|
|
|
|
name: "service-splitter: kitchen sink",
|
|
|
|
snake: `
|
|
|
|
kind = "service-splitter"
|
|
|
|
name = "main"
|
2020-09-02 19:10:25 +00:00
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
splits = [
|
|
|
|
{
|
2021-07-13 11:25:59 +00:00
|
|
|
weight = 99.1
|
|
|
|
service_subset = "v1"
|
|
|
|
request_headers {
|
|
|
|
add {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
remove = ["qux"]
|
|
|
|
}
|
|
|
|
response_headers {
|
|
|
|
add {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
remove = ["qux"]
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-13 11:25:59 +00:00
|
|
|
weight = 0.9
|
|
|
|
service = "other"
|
|
|
|
namespace = "alt"
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "service-splitter"
|
|
|
|
Name = "main"
|
2020-09-02 19:10:25 +00:00
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
Splits = [
|
|
|
|
{
|
2021-07-13 11:25:59 +00:00
|
|
|
Weight = 99.1
|
|
|
|
ServiceSubset = "v1"
|
|
|
|
RequestHeaders {
|
|
|
|
Add {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
Set {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
Remove = ["qux"]
|
|
|
|
}
|
|
|
|
ResponseHeaders {
|
|
|
|
Add {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
Set {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
Remove = ["qux"]
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
{
|
2021-07-13 11:25:59 +00:00
|
|
|
Weight = 0.9
|
|
|
|
Service = "other"
|
|
|
|
Namespace = "alt"
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
`,
|
|
|
|
expect: &ServiceSplitterConfigEntry{
|
|
|
|
Kind: ServiceSplitter,
|
|
|
|
Name: "main",
|
2020-09-02 19:10:25 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
Splits: []ServiceSplit{
|
|
|
|
{
|
|
|
|
Weight: 99.1,
|
|
|
|
ServiceSubset: "v1",
|
2021-07-13 11:25:59 +00:00
|
|
|
RequestHeaders: &HTTPHeaderModifiers{
|
|
|
|
Add: map[string]string{"foo": "bar"},
|
|
|
|
Set: map[string]string{"bar": "baz"},
|
|
|
|
Remove: []string{"qux"},
|
|
|
|
},
|
|
|
|
ResponseHeaders: &HTTPHeaderModifiers{
|
|
|
|
Add: map[string]string{"foo": "bar"},
|
|
|
|
Set: map[string]string{"bar": "baz"},
|
|
|
|
Remove: []string{"qux"},
|
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Weight: 0.9,
|
|
|
|
Service: "other",
|
|
|
|
Namespace: "alt",
|
|
|
|
},
|
2019-04-30 22:19:19 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "service-resolver: subsets with failover",
|
|
|
|
snake: `
|
|
|
|
kind = "service-resolver"
|
|
|
|
name = "main"
|
2020-09-02 19:10:25 +00:00
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
default_subset = "v1"
|
|
|
|
connect_timeout = "15s"
|
|
|
|
subsets = {
|
|
|
|
"v1" = {
|
|
|
|
filter = "Service.Meta.version == v1"
|
|
|
|
},
|
|
|
|
"v2" = {
|
|
|
|
filter = "Service.Meta.version == v2"
|
|
|
|
only_passing = true
|
|
|
|
},
|
|
|
|
}
|
|
|
|
failover = {
|
|
|
|
"v2" = {
|
|
|
|
service = "failcopy"
|
|
|
|
service_subset = "sure"
|
|
|
|
namespace = "neighbor"
|
|
|
|
datacenters = ["dc5", "dc14"]
|
|
|
|
},
|
|
|
|
"*" = {
|
|
|
|
datacenters = ["dc7"]
|
|
|
|
}
|
|
|
|
}`,
|
|
|
|
camel: `
|
|
|
|
Kind = "service-resolver"
|
|
|
|
Name = "main"
|
2020-09-02 19:10:25 +00:00
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
DefaultSubset = "v1"
|
|
|
|
ConnectTimeout = "15s"
|
|
|
|
Subsets = {
|
|
|
|
"v1" = {
|
|
|
|
Filter = "Service.Meta.version == v1"
|
|
|
|
},
|
|
|
|
"v2" = {
|
|
|
|
Filter = "Service.Meta.version == v2"
|
|
|
|
OnlyPassing = true
|
|
|
|
},
|
|
|
|
}
|
|
|
|
Failover = {
|
|
|
|
"v2" = {
|
|
|
|
Service = "failcopy"
|
|
|
|
ServiceSubset = "sure"
|
|
|
|
Namespace = "neighbor"
|
|
|
|
Datacenters = ["dc5", "dc14"]
|
|
|
|
},
|
|
|
|
"*" = {
|
|
|
|
Datacenters = ["dc7"]
|
|
|
|
}
|
|
|
|
}`,
|
|
|
|
expect: &ServiceResolverConfigEntry{
|
2020-09-02 19:10:25 +00:00
|
|
|
Kind: "service-resolver",
|
|
|
|
Name: "main",
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
DefaultSubset: "v1",
|
|
|
|
ConnectTimeout: 15 * time.Second,
|
|
|
|
Subsets: map[string]ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.version == v1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.version == v2",
|
|
|
|
OnlyPassing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Failover: map[string]ServiceResolverFailover{
|
|
|
|
"v2": {
|
2019-08-02 20:34:54 +00:00
|
|
|
Service: "failcopy",
|
|
|
|
ServiceSubset: "sure",
|
|
|
|
Namespace: "neighbor",
|
|
|
|
Datacenters: []string{"dc5", "dc14"},
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
"*": {
|
|
|
|
Datacenters: []string{"dc7"},
|
|
|
|
},
|
|
|
|
},
|
2019-04-30 22:19:19 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
{
|
|
|
|
name: "service-resolver: redirect",
|
|
|
|
snake: `
|
|
|
|
kind = "service-resolver"
|
|
|
|
name = "main"
|
|
|
|
redirect {
|
|
|
|
service = "other"
|
|
|
|
service_subset = "backup"
|
|
|
|
namespace = "alt"
|
|
|
|
datacenter = "dc9"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "service-resolver"
|
|
|
|
Name = "main"
|
|
|
|
Redirect {
|
|
|
|
Service = "other"
|
|
|
|
ServiceSubset = "backup"
|
|
|
|
Namespace = "alt"
|
|
|
|
Datacenter = "dc9"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expect: &ServiceResolverConfigEntry{
|
|
|
|
Kind: "service-resolver",
|
|
|
|
Name: "main",
|
|
|
|
Redirect: &ServiceResolverRedirect{
|
|
|
|
Service: "other",
|
|
|
|
ServiceSubset: "backup",
|
|
|
|
Namespace: "alt",
|
|
|
|
Datacenter: "dc9",
|
2019-04-30 22:19:19 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "service-resolver: default",
|
|
|
|
snake: `
|
|
|
|
kind = "service-resolver"
|
|
|
|
name = "main"
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "service-resolver"
|
|
|
|
Name = "main"
|
|
|
|
`,
|
|
|
|
expect: &ServiceResolverConfigEntry{
|
|
|
|
Kind: "service-resolver",
|
|
|
|
Name: "main",
|
2019-04-30 22:19:19 +00:00
|
|
|
},
|
|
|
|
},
|
2020-09-12 00:34:03 +00:00
|
|
|
{
|
|
|
|
name: "service-resolver: envoy hash lb kitchen sink",
|
|
|
|
snake: `
|
|
|
|
kind = "service-resolver"
|
|
|
|
name = "main"
|
|
|
|
load_balancer = {
|
|
|
|
policy = "ring_hash"
|
|
|
|
ring_hash_config = {
|
|
|
|
minimum_ring_size = 1
|
|
|
|
maximum_ring_size = 2
|
|
|
|
}
|
|
|
|
hash_policies = [
|
|
|
|
{
|
|
|
|
field = "cookie"
|
|
|
|
field_value = "good-cookie"
|
|
|
|
cookie_config = {
|
|
|
|
ttl = "1s"
|
|
|
|
path = "/oven"
|
|
|
|
}
|
|
|
|
terminal = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field = "cookie"
|
|
|
|
field_value = "less-good-cookie"
|
|
|
|
cookie_config = {
|
|
|
|
session = true
|
|
|
|
path = "/toaster"
|
|
|
|
}
|
|
|
|
terminal = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field = "header"
|
|
|
|
field_value = "x-user-id"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
source_ip = true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "service-resolver"
|
|
|
|
Name = "main"
|
|
|
|
LoadBalancer = {
|
|
|
|
Policy = "ring_hash"
|
|
|
|
RingHashConfig = {
|
|
|
|
MinimumRingSize = 1
|
|
|
|
MaximumRingSize = 2
|
|
|
|
}
|
|
|
|
HashPolicies = [
|
|
|
|
{
|
|
|
|
Field = "cookie"
|
|
|
|
FieldValue = "good-cookie"
|
|
|
|
CookieConfig = {
|
|
|
|
TTL = "1s"
|
|
|
|
Path = "/oven"
|
|
|
|
}
|
|
|
|
Terminal = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Field = "cookie"
|
|
|
|
FieldValue = "less-good-cookie"
|
|
|
|
CookieConfig = {
|
|
|
|
Session = true
|
|
|
|
Path = "/toaster"
|
|
|
|
}
|
|
|
|
Terminal = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Field = "header"
|
|
|
|
FieldValue = "x-user-id"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SourceIP = true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expect: &ServiceResolverConfigEntry{
|
|
|
|
Kind: "service-resolver",
|
|
|
|
Name: "main",
|
|
|
|
LoadBalancer: &LoadBalancer{
|
|
|
|
Policy: LBPolicyRingHash,
|
|
|
|
RingHashConfig: &RingHashConfig{
|
|
|
|
MinimumRingSize: 1,
|
|
|
|
MaximumRingSize: 2,
|
|
|
|
},
|
|
|
|
HashPolicies: []HashPolicy{
|
|
|
|
{
|
|
|
|
Field: HashPolicyCookie,
|
|
|
|
FieldValue: "good-cookie",
|
|
|
|
CookieConfig: &CookieConfig{
|
|
|
|
TTL: 1 * time.Second,
|
|
|
|
Path: "/oven",
|
|
|
|
},
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Field: HashPolicyCookie,
|
|
|
|
FieldValue: "less-good-cookie",
|
|
|
|
CookieConfig: &CookieConfig{
|
|
|
|
Session: true,
|
|
|
|
Path: "/toaster",
|
|
|
|
},
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Field: HashPolicyHeader,
|
|
|
|
FieldValue: "x-user-id",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SourceIP: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "service-resolver: envoy least request kitchen sink",
|
|
|
|
snake: `
|
|
|
|
kind = "service-resolver"
|
|
|
|
name = "main"
|
|
|
|
load_balancer = {
|
|
|
|
policy = "least_request"
|
|
|
|
least_request_config = {
|
|
|
|
choice_count = 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "service-resolver"
|
|
|
|
Name = "main"
|
|
|
|
LoadBalancer = {
|
|
|
|
Policy = "least_request"
|
|
|
|
LeastRequestConfig = {
|
|
|
|
ChoiceCount = 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expect: &ServiceResolverConfigEntry{
|
|
|
|
Kind: "service-resolver",
|
|
|
|
Name: "main",
|
|
|
|
LoadBalancer: &LoadBalancer{
|
|
|
|
Policy: LBPolicyLeastRequest,
|
|
|
|
LeastRequestConfig: &LeastRequestConfig{
|
|
|
|
ChoiceCount: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-03-31 16:59:10 +00:00
|
|
|
{
|
2022-01-11 16:46:42 +00:00
|
|
|
// TODO(rb): test SDS stuff here in both places (global/service)
|
2020-03-31 16:59:10 +00:00
|
|
|
name: "ingress-gateway: kitchen sink",
|
|
|
|
snake: `
|
|
|
|
kind = "ingress-gateway"
|
|
|
|
name = "ingress-web"
|
2020-09-02 19:10:25 +00:00
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2020-03-31 16:59:10 +00:00
|
|
|
|
2020-04-27 23:36:20 +00:00
|
|
|
tls {
|
|
|
|
enabled = true
|
2022-01-11 16:46:42 +00:00
|
|
|
tls_min_version = "TLSv1_1"
|
|
|
|
tls_max_version = "TLSv1_2"
|
|
|
|
cipher_suites = [
|
|
|
|
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
|
|
|
|
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
|
|
|
|
]
|
2020-04-27 23:36:20 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 16:59:10 +00:00
|
|
|
listeners = [
|
|
|
|
{
|
|
|
|
port = 8080
|
|
|
|
protocol = "http"
|
|
|
|
services = [
|
|
|
|
{
|
|
|
|
name = "web"
|
2020-04-23 15:06:19 +00:00
|
|
|
hosts = ["test.example.com", "test2.example.com"]
|
2020-03-31 16:59:10 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "db"
|
2021-07-13 11:13:18 +00:00
|
|
|
request_headers {
|
|
|
|
add {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
remove = ["qux"]
|
|
|
|
}
|
|
|
|
response_headers {
|
|
|
|
add {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
remove = ["qux"]
|
|
|
|
}
|
2020-03-31 16:59:10 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
port = 9999
|
|
|
|
protocol = "tcp"
|
|
|
|
services = [
|
|
|
|
{
|
|
|
|
name = "mysql"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
port = 2234
|
|
|
|
protocol = "tcp"
|
|
|
|
services = [
|
|
|
|
{
|
|
|
|
name = "postgres"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "ingress-gateway"
|
|
|
|
Name = "ingress-web"
|
2020-09-02 19:10:25 +00:00
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2020-04-27 23:36:20 +00:00
|
|
|
TLS {
|
|
|
|
Enabled = true
|
2022-01-11 16:46:42 +00:00
|
|
|
TLSMinVersion = "TLSv1_1"
|
|
|
|
TLSMaxVersion = "TLSv1_2"
|
|
|
|
CipherSuites = [
|
|
|
|
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
|
|
|
|
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
|
|
|
|
]
|
2020-04-27 23:36:20 +00:00
|
|
|
}
|
2020-03-31 16:59:10 +00:00
|
|
|
Listeners = [
|
|
|
|
{
|
|
|
|
Port = 8080
|
|
|
|
Protocol = "http"
|
|
|
|
Services = [
|
|
|
|
{
|
|
|
|
Name = "web"
|
2020-04-23 15:06:19 +00:00
|
|
|
Hosts = ["test.example.com", "test2.example.com"]
|
2020-03-31 16:59:10 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "db"
|
2021-07-13 11:13:18 +00:00
|
|
|
RequestHeaders {
|
|
|
|
Add {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
Set {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
Remove = ["qux"]
|
|
|
|
}
|
|
|
|
ResponseHeaders {
|
|
|
|
Add {
|
|
|
|
foo = "bar"
|
|
|
|
}
|
|
|
|
Set {
|
|
|
|
bar = "baz"
|
|
|
|
}
|
|
|
|
Remove = ["qux"]
|
|
|
|
}
|
2020-03-31 16:59:10 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port = 9999
|
|
|
|
Protocol = "tcp"
|
|
|
|
Services = [
|
|
|
|
{
|
|
|
|
Name = "mysql"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port = 2234
|
|
|
|
Protocol = "tcp"
|
|
|
|
Services = [
|
|
|
|
{
|
|
|
|
Name = "postgres"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
`,
|
|
|
|
expect: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
2020-09-02 19:10:25 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
2020-04-27 23:36:20 +00:00
|
|
|
TLS: GatewayTLSConfig{
|
2022-01-11 16:46:42 +00:00
|
|
|
Enabled: true,
|
|
|
|
TLSMinVersion: types.TLSv1_1,
|
|
|
|
TLSMaxVersion: types.TLSv1_2,
|
|
|
|
CipherSuites: []types.TLSCipherSuite{
|
|
|
|
types.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
types.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
},
|
2020-04-27 23:36:20 +00:00
|
|
|
},
|
2020-03-31 16:59:10 +00:00
|
|
|
Listeners: []IngressListener{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2020-03-31 16:59:10 +00:00
|
|
|
Port: 8080,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2020-04-23 15:06:19 +00:00
|
|
|
Name: "web",
|
|
|
|
Hosts: []string{"test.example.com", "test2.example.com"},
|
2020-03-31 16:59:10 +00:00
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2020-03-31 16:59:10 +00:00
|
|
|
Name: "db",
|
2021-07-13 11:13:18 +00:00
|
|
|
RequestHeaders: &HTTPHeaderModifiers{
|
|
|
|
Add: map[string]string{"foo": "bar"},
|
|
|
|
Set: map[string]string{"bar": "baz"},
|
|
|
|
Remove: []string{"qux"},
|
|
|
|
},
|
|
|
|
ResponseHeaders: &HTTPHeaderModifiers{
|
|
|
|
Add: map[string]string{"foo": "bar"},
|
|
|
|
Set: map[string]string{"bar": "baz"},
|
|
|
|
Remove: []string{"qux"},
|
|
|
|
},
|
2020-03-31 16:59:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2020-03-31 16:59:10 +00:00
|
|
|
Port: 9999,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2020-03-31 16:59:10 +00:00
|
|
|
Name: "mysql",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2020-03-31 16:59:10 +00:00
|
|
|
Port: 2234,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2020-04-23 14:33:33 +00:00
|
|
|
Name: "postgres",
|
2020-03-31 16:59:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-03-31 19:27:32 +00:00
|
|
|
{
|
|
|
|
name: "terminating-gateway: kitchen sink",
|
|
|
|
snake: `
|
|
|
|
kind = "terminating-gateway"
|
|
|
|
name = "terminating-gw-west"
|
2020-09-02 19:10:25 +00:00
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2020-03-31 19:27:32 +00:00
|
|
|
services = [
|
|
|
|
{
|
|
|
|
name = "payments",
|
|
|
|
ca_file = "/etc/payments/ca.pem",
|
|
|
|
cert_file = "/etc/payments/cert.pem",
|
|
|
|
key_file = "/etc/payments/tls.key",
|
2020-04-27 22:25:37 +00:00
|
|
|
sni = "mydomain",
|
2020-03-31 19:27:32 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "*",
|
|
|
|
ca_file = "/etc/all/ca.pem",
|
|
|
|
cert_file = "/etc/all/cert.pem",
|
|
|
|
key_file = "/etc/all/tls.key",
|
2020-04-27 22:25:37 +00:00
|
|
|
sni = "my-alt-domain",
|
2020-03-31 19:27:32 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "terminating-gateway"
|
|
|
|
Name = "terminating-gw-west"
|
2020-09-02 19:10:25 +00:00
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
2020-03-31 19:27:32 +00:00
|
|
|
Services = [
|
|
|
|
{
|
|
|
|
Name = "payments",
|
|
|
|
CAFile = "/etc/payments/ca.pem",
|
|
|
|
CertFile = "/etc/payments/cert.pem",
|
|
|
|
KeyFile = "/etc/payments/tls.key",
|
2020-04-27 22:25:37 +00:00
|
|
|
SNI = "mydomain",
|
2020-03-31 19:27:32 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "*",
|
|
|
|
CAFile = "/etc/all/ca.pem",
|
|
|
|
CertFile = "/etc/all/cert.pem",
|
|
|
|
KeyFile = "/etc/all/tls.key",
|
2020-04-27 22:25:37 +00:00
|
|
|
SNI = "my-alt-domain",
|
2020-03-31 19:27:32 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
`,
|
|
|
|
expect: &TerminatingGatewayConfigEntry{
|
|
|
|
Kind: "terminating-gateway",
|
|
|
|
Name: "terminating-gw-west",
|
2020-09-02 19:10:25 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
2020-03-31 19:27:32 +00:00
|
|
|
Services: []LinkedService{
|
|
|
|
{
|
|
|
|
Name: "payments",
|
|
|
|
CAFile: "/etc/payments/ca.pem",
|
|
|
|
CertFile: "/etc/payments/cert.pem",
|
|
|
|
KeyFile: "/etc/payments/tls.key",
|
2020-04-27 22:25:37 +00:00
|
|
|
SNI: "mydomain",
|
2020-03-31 19:27:32 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "*",
|
|
|
|
CAFile: "/etc/all/ca.pem",
|
|
|
|
CertFile: "/etc/all/cert.pem",
|
|
|
|
KeyFile: "/etc/all/tls.key",
|
2020-04-27 22:25:37 +00:00
|
|
|
SNI: "my-alt-domain",
|
2020-03-31 19:27:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-10-06 18:24:05 +00:00
|
|
|
{
|
|
|
|
name: "service-intentions: kitchen sink",
|
|
|
|
snake: `
|
|
|
|
kind = "service-intentions"
|
|
|
|
name = "web"
|
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
sources = [
|
|
|
|
{
|
|
|
|
name = "foo"
|
|
|
|
action = "deny"
|
|
|
|
type = "consul"
|
|
|
|
description = "foo desc"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "bar"
|
|
|
|
action = "allow"
|
|
|
|
description = "bar desc"
|
2020-10-06 22:09:13 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "l7"
|
|
|
|
permissions = [
|
|
|
|
{
|
|
|
|
action = "deny"
|
|
|
|
http {
|
|
|
|
path_exact = "/admin"
|
|
|
|
header = [
|
|
|
|
{
|
|
|
|
name = "hdr-present"
|
|
|
|
present = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "hdr-exact"
|
|
|
|
exact = "exact"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "hdr-prefix"
|
|
|
|
prefix = "prefix"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "hdr-suffix"
|
|
|
|
suffix = "suffix"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "hdr-regex"
|
|
|
|
regex = "regex"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "hdr-absent"
|
|
|
|
present = true
|
|
|
|
invert = true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action = "allow"
|
|
|
|
http {
|
|
|
|
path_prefix = "/v3/"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action = "allow"
|
|
|
|
http {
|
|
|
|
path_regex = "/v[12]/.*"
|
|
|
|
methods = ["GET", "POST"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2020-10-06 18:24:05 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
sources {
|
|
|
|
name = "*"
|
|
|
|
action = "deny"
|
|
|
|
description = "wild desc"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "service-intentions"
|
|
|
|
Name = "web"
|
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
Sources = [
|
|
|
|
{
|
|
|
|
Name = "foo"
|
|
|
|
Action = "deny"
|
|
|
|
Type = "consul"
|
|
|
|
Description = "foo desc"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "bar"
|
|
|
|
Action = "allow"
|
|
|
|
Description = "bar desc"
|
2020-10-06 22:09:13 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "l7"
|
|
|
|
Permissions = [
|
|
|
|
{
|
|
|
|
Action = "deny"
|
|
|
|
HTTP {
|
|
|
|
PathExact = "/admin"
|
|
|
|
Header = [
|
|
|
|
{
|
|
|
|
Name = "hdr-present"
|
|
|
|
Present = true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "hdr-exact"
|
|
|
|
Exact = "exact"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "hdr-prefix"
|
|
|
|
Prefix = "prefix"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "hdr-suffix"
|
|
|
|
Suffix = "suffix"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "hdr-regex"
|
|
|
|
Regex = "regex"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "hdr-absent"
|
|
|
|
Present = true
|
|
|
|
Invert = true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action = "allow"
|
|
|
|
HTTP {
|
|
|
|
PathPrefix = "/v3/"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action = "allow"
|
|
|
|
HTTP {
|
|
|
|
PathRegex = "/v[12]/.*"
|
|
|
|
Methods = ["GET", "POST"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2020-10-06 18:24:05 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
Sources {
|
|
|
|
Name = "*"
|
|
|
|
Action = "deny"
|
|
|
|
Description = "wild desc"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expect: &ServiceIntentionsConfigEntry{
|
|
|
|
Kind: "service-intentions",
|
|
|
|
Name: "web",
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
|
|
|
Sources: []*SourceIntention{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Action: "deny",
|
|
|
|
Type: "consul",
|
|
|
|
Description: "foo desc",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Action: "allow",
|
|
|
|
Description: "bar desc",
|
|
|
|
},
|
2020-10-06 22:09:13 +00:00
|
|
|
{
|
|
|
|
Name: "l7",
|
|
|
|
Permissions: []*IntentionPermission{
|
|
|
|
{
|
|
|
|
Action: "deny",
|
|
|
|
HTTP: &IntentionHTTPPermission{
|
|
|
|
PathExact: "/admin",
|
|
|
|
Header: []IntentionHTTPHeaderPermission{
|
|
|
|
{
|
|
|
|
Name: "hdr-present",
|
|
|
|
Present: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "hdr-exact",
|
|
|
|
Exact: "exact",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "hdr-prefix",
|
|
|
|
Prefix: "prefix",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "hdr-suffix",
|
|
|
|
Suffix: "suffix",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "hdr-regex",
|
|
|
|
Regex: "regex",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "hdr-absent",
|
|
|
|
Present: true,
|
|
|
|
Invert: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action: "allow",
|
|
|
|
HTTP: &IntentionHTTPPermission{
|
|
|
|
PathPrefix: "/v3/",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action: "allow",
|
|
|
|
HTTP: &IntentionHTTPPermission{
|
|
|
|
PathRegex: "/v[12]/.*",
|
|
|
|
Methods: []string{"GET", "POST"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-10-06 18:24:05 +00:00
|
|
|
{
|
|
|
|
Name: "*",
|
|
|
|
Action: "deny",
|
|
|
|
Description: "wild desc",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "service-intentions: wildcard destination",
|
|
|
|
snake: `
|
|
|
|
kind = "service-intentions"
|
|
|
|
name = "*"
|
|
|
|
sources {
|
|
|
|
name = "foo"
|
|
|
|
action = "deny"
|
|
|
|
# should be parsed, but we'll ignore it later
|
|
|
|
precedence = 6
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "service-intentions"
|
|
|
|
Name = "*"
|
|
|
|
Sources {
|
|
|
|
Name = "foo"
|
|
|
|
Action = "deny"
|
|
|
|
# should be parsed, but we'll ignore it later
|
|
|
|
Precedence = 6
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expect: &ServiceIntentionsConfigEntry{
|
|
|
|
Kind: "service-intentions",
|
|
|
|
Name: "*",
|
|
|
|
Sources: []*SourceIntention{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Action: "deny",
|
|
|
|
Precedence: 6,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-06 18:19:59 +00:00
|
|
|
{
|
2021-04-28 22:13:29 +00:00
|
|
|
name: "mesh",
|
2021-04-06 18:19:59 +00:00
|
|
|
snake: `
|
2021-04-28 22:13:29 +00:00
|
|
|
kind = "mesh"
|
2021-04-06 18:19:59 +00:00
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
transparent_proxy {
|
2021-06-14 20:15:09 +00:00
|
|
|
mesh_destinations_only = true
|
2021-04-06 18:19:59 +00:00
|
|
|
}
|
2023-04-19 19:45:00 +00:00
|
|
|
allow_enabling_permissive_mutual_tls = true
|
2022-03-30 18:43:59 +00:00
|
|
|
tls {
|
|
|
|
incoming {
|
|
|
|
tls_min_version = "TLSv1_1"
|
|
|
|
tls_max_version = "TLSv1_2"
|
|
|
|
cipher_suites = [
|
|
|
|
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
|
|
|
|
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
outgoing {
|
|
|
|
tls_min_version = "TLSv1_1"
|
|
|
|
tls_max_version = "TLSv1_2"
|
|
|
|
cipher_suites = [
|
|
|
|
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
|
|
|
|
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2022-05-03 20:29:45 +00:00
|
|
|
http {
|
|
|
|
sanitize_x_forwarded_client_cert = true
|
|
|
|
}
|
2022-09-02 20:52:11 +00:00
|
|
|
peering {
|
|
|
|
peer_through_mesh_gateways = true
|
|
|
|
}
|
2021-04-06 18:19:59 +00:00
|
|
|
`,
|
|
|
|
camel: `
|
2021-04-28 22:13:29 +00:00
|
|
|
Kind = "mesh"
|
2021-04-06 18:19:59 +00:00
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
TransparentProxy {
|
2021-06-14 20:15:09 +00:00
|
|
|
MeshDestinationsOnly = true
|
2021-04-06 18:19:59 +00:00
|
|
|
}
|
2023-04-19 19:45:00 +00:00
|
|
|
AllowEnablingPermissiveMutualTLS = true
|
2022-03-30 18:43:59 +00:00
|
|
|
TLS {
|
|
|
|
Incoming {
|
|
|
|
TLSMinVersion = "TLSv1_1"
|
|
|
|
TLSMaxVersion = "TLSv1_2"
|
|
|
|
CipherSuites = [
|
|
|
|
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
|
|
|
|
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
Outgoing {
|
|
|
|
TLSMinVersion = "TLSv1_1"
|
|
|
|
TLSMaxVersion = "TLSv1_2"
|
|
|
|
CipherSuites = [
|
|
|
|
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
|
|
|
|
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2022-05-03 20:29:45 +00:00
|
|
|
HTTP {
|
|
|
|
SanitizeXForwardedClientCert = true
|
2022-09-02 20:52:11 +00:00
|
|
|
}
|
|
|
|
Peering {
|
|
|
|
PeerThroughMeshGateways = true
|
|
|
|
}
|
2021-04-06 18:19:59 +00:00
|
|
|
`,
|
2021-04-28 22:13:29 +00:00
|
|
|
expect: &MeshConfigEntry{
|
2021-04-06 18:19:59 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
2021-04-28 22:13:29 +00:00
|
|
|
TransparentProxy: TransparentProxyMeshConfig{
|
2021-06-14 20:15:09 +00:00
|
|
|
MeshDestinationsOnly: true,
|
2021-04-06 18:19:59 +00:00
|
|
|
},
|
2023-04-19 19:45:00 +00:00
|
|
|
AllowEnablingPermissiveMutualTLS: true,
|
2022-03-30 18:43:59 +00:00
|
|
|
TLS: &MeshTLSConfig{
|
|
|
|
Incoming: &MeshDirectionalTLSConfig{
|
|
|
|
TLSMinVersion: types.TLSv1_1,
|
|
|
|
TLSMaxVersion: types.TLSv1_2,
|
|
|
|
CipherSuites: []types.TLSCipherSuite{
|
|
|
|
types.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
types.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Outgoing: &MeshDirectionalTLSConfig{
|
|
|
|
TLSMinVersion: types.TLSv1_1,
|
|
|
|
TLSMaxVersion: types.TLSv1_2,
|
|
|
|
CipherSuites: []types.TLSCipherSuite{
|
|
|
|
types.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
types.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-05-03 20:29:45 +00:00
|
|
|
HTTP: &MeshHTTPConfig{
|
|
|
|
SanitizeXForwardedClientCert: true,
|
|
|
|
},
|
2022-09-02 20:52:11 +00:00
|
|
|
Peering: &PeeringMeshConfig{
|
|
|
|
PeerThroughMeshGateways: true,
|
|
|
|
},
|
2021-04-06 18:19:59 +00:00
|
|
|
},
|
|
|
|
},
|
2023-01-18 22:14:34 +00:00
|
|
|
{
|
|
|
|
name: "api-gateway",
|
|
|
|
snake: `
|
|
|
|
kind = "api-gateway"
|
|
|
|
name = "foo"
|
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "api-gateway"
|
|
|
|
Name = "foo"
|
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expect: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "foo",
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "inline-certificate",
|
|
|
|
snake: `
|
|
|
|
kind = "inline-certificate"
|
|
|
|
name = "foo"
|
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "inline-certificate"
|
|
|
|
Name = "foo"
|
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expect: &InlineCertificateConfigEntry{
|
|
|
|
Kind: "inline-certificate",
|
|
|
|
Name: "foo",
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "http-route",
|
|
|
|
snake: `
|
|
|
|
kind = "http-route"
|
|
|
|
name = "foo"
|
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "http-route"
|
|
|
|
Name = "foo"
|
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expect: &HTTPRouteConfigEntry{
|
|
|
|
Kind: "http-route",
|
|
|
|
Name: "foo",
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "tcp-route",
|
|
|
|
snake: `
|
|
|
|
kind = "tcp-route"
|
|
|
|
name = "foo"
|
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
camel: `
|
|
|
|
Kind = "tcp-route"
|
|
|
|
Name = "foo"
|
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
expect: &TCPRouteConfigEntry{
|
|
|
|
Kind: "tcp-route",
|
|
|
|
Name: "foo",
|
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-20 19:24:18 +00:00
|
|
|
{
|
2021-12-03 06:50:38 +00:00
|
|
|
name: "exported-services",
|
2021-10-20 19:24:18 +00:00
|
|
|
snake: `
|
2021-12-03 06:50:38 +00:00
|
|
|
kind = "exported-services"
|
2021-10-26 00:15:24 +00:00
|
|
|
name = "foo"
|
2021-10-20 19:24:18 +00:00
|
|
|
meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
services = [
|
|
|
|
{
|
|
|
|
name = "web"
|
|
|
|
namespace = "foo"
|
|
|
|
consumers = [
|
|
|
|
{
|
|
|
|
partition = "bar"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
partition = "baz"
|
2022-04-27 15:27:21 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
peer_name = "flarm"
|
2021-10-20 19:24:18 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = "db"
|
|
|
|
namespace = "bar"
|
|
|
|
consumers = [
|
|
|
|
{
|
|
|
|
partition = "zoo"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
`,
|
|
|
|
camel: `
|
2021-12-03 06:50:38 +00:00
|
|
|
Kind = "exported-services"
|
2021-10-26 00:15:24 +00:00
|
|
|
Name = "foo"
|
2021-10-20 19:24:18 +00:00
|
|
|
Meta {
|
|
|
|
"foo" = "bar"
|
|
|
|
"gir" = "zim"
|
|
|
|
}
|
|
|
|
Services = [
|
|
|
|
{
|
|
|
|
Name = "web"
|
|
|
|
Namespace = "foo"
|
|
|
|
Consumers = [
|
|
|
|
{
|
|
|
|
Partition = "bar"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Partition = "baz"
|
2022-04-27 15:27:21 +00:00
|
|
|
},
|
|
|
|
{
|
2022-10-04 18:46:15 +00:00
|
|
|
Peer = "flarm"
|
2021-10-20 19:24:18 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name = "db"
|
|
|
|
Namespace = "bar"
|
|
|
|
Consumers = [
|
|
|
|
{
|
|
|
|
Partition = "zoo"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
`,
|
2021-12-03 06:50:38 +00:00
|
|
|
expect: &ExportedServicesConfigEntry{
|
2021-10-26 00:15:24 +00:00
|
|
|
Name: "foo",
|
2021-10-20 19:24:18 +00:00
|
|
|
Meta: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
|
|
|
Services: []ExportedService{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
Namespace: "foo",
|
|
|
|
Consumers: []ServiceConsumer{
|
|
|
|
{
|
|
|
|
Partition: "bar",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Partition: "baz",
|
|
|
|
},
|
2022-04-27 15:27:21 +00:00
|
|
|
{
|
2022-10-04 18:46:15 +00:00
|
|
|
Peer: "flarm",
|
2022-04-27 15:27:21 +00:00
|
|
|
},
|
2021-10-20 19:24:18 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
Namespace: "bar",
|
|
|
|
Consumers: []ServiceConsumer{
|
|
|
|
{
|
|
|
|
Partition: "zoo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-12 17:20:30 +00:00
|
|
|
} {
|
|
|
|
tc := tc
|
2019-04-30 22:19:19 +00:00
|
|
|
|
2019-07-12 17:20:30 +00:00
|
|
|
testbody := func(t *testing.T, body string) {
|
|
|
|
var raw map[string]interface{}
|
|
|
|
err := hcl.Decode(&raw, body)
|
|
|
|
require.NoError(t, err)
|
2019-04-30 22:19:19 +00:00
|
|
|
|
2019-07-12 17:20:30 +00:00
|
|
|
got, err := DecodeConfigEntry(raw)
|
|
|
|
if tc.expectErr != "" {
|
|
|
|
require.Nil(t, got)
|
2019-04-30 22:19:19 +00:00
|
|
|
require.Error(t, err)
|
2019-07-12 17:20:30 +00:00
|
|
|
requireContainsLower(t, err.Error(), tc.expectErr)
|
2019-04-30 22:19:19 +00:00
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
2019-07-12 17:20:30 +00:00
|
|
|
require.Equal(t, tc.expect, got)
|
2019-04-30 22:19:19 +00:00
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(tc.name+" (snake case)", func(t *testing.T) {
|
|
|
|
testbody(t, tc.snake)
|
|
|
|
})
|
|
|
|
t.Run(tc.name+" (camel case)", func(t *testing.T) {
|
|
|
|
testbody(t, tc.camel)
|
2019-04-30 22:19:19 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-05-02 13:11:33 +00:00
|
|
|
|
2021-05-14 15:15:48 +00:00
|
|
|
func TestServiceConfigRequest(t *testing.T) {
|
2023-02-03 15:51:53 +00:00
|
|
|
|
2021-05-14 15:15:48 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
req ServiceConfigRequest
|
|
|
|
mutate func(req *ServiceConfigRequest)
|
|
|
|
want *cache.RequestInfo
|
|
|
|
wantSame bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "basic params",
|
|
|
|
req: ServiceConfigRequest{
|
|
|
|
QueryOptions: QueryOptions{Token: "foo"},
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
want: &cache.RequestInfo{
|
|
|
|
Token: "foo",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
wantSame: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "name should be considered",
|
|
|
|
req: ServiceConfigRequest{
|
|
|
|
Name: "web",
|
|
|
|
},
|
|
|
|
mutate: func(req *ServiceConfigRequest) {
|
|
|
|
req.Name = "db"
|
|
|
|
},
|
|
|
|
wantSame: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "upstreams should be different",
|
|
|
|
req: ServiceConfigRequest{
|
|
|
|
Name: "web",
|
2023-04-11 15:20:33 +00:00
|
|
|
UpstreamServiceNames: []PeeredServiceName{
|
|
|
|
{ServiceName: NewServiceName("foo", nil)},
|
2021-05-14 15:15:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
mutate: func(req *ServiceConfigRequest) {
|
2023-04-11 15:20:33 +00:00
|
|
|
req.UpstreamServiceNames = []PeeredServiceName{
|
|
|
|
{ServiceName: NewServiceName("foo", nil)},
|
|
|
|
{ServiceName: NewServiceName("bar", nil)},
|
2021-05-14 15:15:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
wantSame: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "upstreams should not depend on order",
|
|
|
|
req: ServiceConfigRequest{
|
|
|
|
Name: "web",
|
2023-04-11 15:20:33 +00:00
|
|
|
UpstreamServiceNames: []PeeredServiceName{
|
|
|
|
{ServiceName: NewServiceName("foo", nil)},
|
|
|
|
{ServiceName: NewServiceName("bar", nil)},
|
2021-05-14 15:15:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
mutate: func(req *ServiceConfigRequest) {
|
2023-04-11 15:20:33 +00:00
|
|
|
req.UpstreamServiceNames = []PeeredServiceName{
|
|
|
|
{ServiceName: NewServiceName("foo", nil)},
|
|
|
|
{ServiceName: NewServiceName("bar", nil)},
|
2021-05-14 15:15:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
wantSame: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tests {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
info := tc.req.CacheInfo()
|
|
|
|
if tc.mutate != nil {
|
|
|
|
tc.mutate(&tc.req)
|
|
|
|
}
|
|
|
|
afterInfo := tc.req.CacheInfo()
|
|
|
|
|
|
|
|
// Check key matches or not
|
|
|
|
if tc.wantSame {
|
|
|
|
require.Equal(t, info, afterInfo)
|
|
|
|
} else {
|
|
|
|
require.NotEqual(t, info, afterInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
if tc.want != nil {
|
|
|
|
// Reset key since we don't care about the actual hash value as long as
|
|
|
|
// it does/doesn't change appropriately (asserted with wantSame above).
|
|
|
|
info.Key = ""
|
|
|
|
require.Equal(t, *tc.want, info)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 13:11:33 +00:00
|
|
|
func TestServiceConfigResponse_MsgPack(t *testing.T) {
|
|
|
|
a := ServiceConfigResponse{
|
|
|
|
ProxyConfig: map[string]interface{}{
|
|
|
|
"string": "foo",
|
2023-02-03 15:51:53 +00:00
|
|
|
"map": map[string]interface{}{
|
|
|
|
"baz": "bar",
|
|
|
|
},
|
2019-05-02 13:11:33 +00:00
|
|
|
},
|
2023-02-03 15:51:53 +00:00
|
|
|
UpstreamConfigs: []OpaqueUpstreamConfig{
|
|
|
|
{
|
|
|
|
Upstream: PeeredServiceName{
|
|
|
|
ServiceName: NewServiceName("a", acl.DefaultEnterpriseMeta()),
|
|
|
|
},
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"string": "aaaa",
|
|
|
|
"map": map[string]interface{}{
|
|
|
|
"baz": "aa",
|
|
|
|
},
|
|
|
|
},
|
2019-05-02 13:11:33 +00:00
|
|
|
},
|
2023-02-03 15:51:53 +00:00
|
|
|
{
|
|
|
|
Upstream: PeeredServiceName{
|
|
|
|
ServiceName: NewServiceName("b", acl.DefaultEnterpriseMeta()),
|
|
|
|
},
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"string": "bbbb",
|
|
|
|
"map": map[string]interface{}{
|
|
|
|
"baz": "bb",
|
|
|
|
},
|
|
|
|
},
|
2019-05-02 13:11:33 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
|
|
|
// Encode as msgPack using a regular handle i.e. NOT one with RawAsString
|
|
|
|
// since our RPC codec doesn't use that.
|
2020-02-07 21:50:24 +00:00
|
|
|
enc := codec.NewEncoder(&buf, MsgpackHandle)
|
2019-05-02 13:11:33 +00:00
|
|
|
require.NoError(t, enc.Encode(&a))
|
|
|
|
|
|
|
|
var b ServiceConfigResponse
|
|
|
|
|
2020-02-07 21:50:24 +00:00
|
|
|
dec := codec.NewDecoder(&buf, MsgpackHandle)
|
2019-05-02 13:11:33 +00:00
|
|
|
require.NoError(t, dec.Decode(&b))
|
|
|
|
|
|
|
|
require.Equal(t, a, b)
|
|
|
|
}
|
2019-05-02 19:25:29 +00:00
|
|
|
|
|
|
|
func TestConfigEntryResponseMarshalling(t *testing.T) {
|
|
|
|
|
|
|
|
cases := map[string]ConfigEntryResponse{
|
2020-06-16 17:19:31 +00:00
|
|
|
"nil entry": {},
|
|
|
|
"proxy-default entry": {
|
2019-05-02 19:25:29 +00:00
|
|
|
Entry: &ProxyConfigEntry{
|
|
|
|
Kind: ProxyDefaults,
|
|
|
|
Name: ProxyConfigGlobal,
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"service-default entry": {
|
2019-05-02 19:25:29 +00:00
|
|
|
Entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "foo",
|
|
|
|
Protocol: "tcp",
|
|
|
|
// Connect: ConnectConfiguration{SideCarProxy: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tcase := range cases {
|
|
|
|
name := name
|
|
|
|
tcase := tcase
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
|
|
|
data, err := tcase.MarshalBinary()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, data)
|
|
|
|
|
|
|
|
var resp ConfigEntryResponse
|
|
|
|
require.NoError(t, resp.UnmarshalBinary(data))
|
|
|
|
|
|
|
|
require.Equal(t, tcase, resp)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-07-12 17:20:30 +00:00
|
|
|
|
2021-03-09 05:10:27 +00:00
|
|
|
func TestPassiveHealthCheck_Validate(t *testing.T) {
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
input PassiveHealthCheck
|
|
|
|
wantErr bool
|
|
|
|
wantMsg string
|
|
|
|
}{
|
|
|
|
{
|
2021-04-12 16:05:03 +00:00
|
|
|
name: "valid interval",
|
|
|
|
input: PassiveHealthCheck{Interval: 0 * time.Second},
|
2021-03-09 05:10:27 +00:00
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
2021-04-12 16:05:03 +00:00
|
|
|
name: "negative interval",
|
2021-03-09 05:10:27 +00:00
|
|
|
input: PassiveHealthCheck{Interval: -1 * time.Second},
|
|
|
|
wantErr: true,
|
2021-04-12 16:05:03 +00:00
|
|
|
wantMsg: "cannot be negative",
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
2023-04-26 22:59:48 +00:00
|
|
|
{
|
|
|
|
name: "valid enforcing_consecutive_5xx",
|
|
|
|
input: PassiveHealthCheck{EnforcingConsecutive5xx: uintPointer(100)},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid enforcing_consecutive_5xx",
|
|
|
|
input: PassiveHealthCheck{EnforcingConsecutive5xx: uintPointer(101)},
|
|
|
|
wantErr: true,
|
|
|
|
wantMsg: "must be a percentage",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "valid max_ejection_percent",
|
|
|
|
input: PassiveHealthCheck{MaxEjectionPercent: uintPointer(100)},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "invalid max_ejection_percent",
|
|
|
|
input: PassiveHealthCheck{MaxEjectionPercent: uintPointer(101)},
|
|
|
|
wantErr: true,
|
|
|
|
wantMsg: "must be a percentage",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "valid base_ejection_time",
|
|
|
|
input: PassiveHealthCheck{BaseEjectionTime: durationPointer(0 * time.Second)},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "negative base_ejection_time",
|
|
|
|
input: PassiveHealthCheck{BaseEjectionTime: durationPointer(-1 * time.Second)},
|
|
|
|
wantErr: true,
|
|
|
|
wantMsg: "cannot be negative",
|
|
|
|
},
|
2021-03-09 05:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
err := tc.input.Validate()
|
|
|
|
if err == nil {
|
|
|
|
require.False(t, tc.wantErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.Contains(t, err.Error(), tc.wantMsg)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpstreamLimits_Validate(t *testing.T) {
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
input UpstreamLimits
|
|
|
|
wantErr bool
|
|
|
|
wantMsg string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "valid-max-conns",
|
|
|
|
input: UpstreamLimits{MaxConnections: intPointer(0)},
|
2021-04-12 16:05:03 +00:00
|
|
|
wantErr: false,
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "negative-max-conns",
|
|
|
|
input: UpstreamLimits{MaxConnections: intPointer(-1)},
|
|
|
|
wantErr: true,
|
2021-04-12 16:05:03 +00:00
|
|
|
wantMsg: "cannot be negative",
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "valid-max-concurrent",
|
|
|
|
input: UpstreamLimits{MaxConcurrentRequests: intPointer(0)},
|
2021-04-12 16:05:03 +00:00
|
|
|
wantErr: false,
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "negative-max-concurrent",
|
|
|
|
input: UpstreamLimits{MaxConcurrentRequests: intPointer(-1)},
|
|
|
|
wantErr: true,
|
2021-04-12 16:05:03 +00:00
|
|
|
wantMsg: "cannot be negative",
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "valid-max-pending",
|
|
|
|
input: UpstreamLimits{MaxPendingRequests: intPointer(0)},
|
2021-04-12 16:05:03 +00:00
|
|
|
wantErr: false,
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "negative-max-pending",
|
|
|
|
input: UpstreamLimits{MaxPendingRequests: intPointer(-1)},
|
|
|
|
wantErr: true,
|
2021-04-12 16:05:03 +00:00
|
|
|
wantMsg: "cannot be negative",
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
err := tc.input.Validate()
|
|
|
|
if err == nil {
|
|
|
|
require.False(t, tc.wantErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.Contains(t, err.Error(), tc.wantMsg)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-23 19:11:23 +00:00
|
|
|
func TestServiceConfigEntry(t *testing.T) {
|
|
|
|
cases := map[string]configEntryTestcase{
|
|
|
|
"normalize: upstream config override no name": {
|
2021-04-15 19:21:44 +00:00
|
|
|
// This will do nothing to normalization, but it will fail at validation later
|
2021-06-23 19:11:23 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
2021-04-15 19:21:44 +00:00
|
|
|
Name: "web",
|
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Overrides: []*UpstreamConfig{
|
|
|
|
{
|
|
|
|
Name: "good",
|
|
|
|
Protocol: "grpc",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Protocol: "http2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "also-good",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
expected: &ServiceConfigEntry{
|
2021-04-15 19:21:44 +00:00
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "web",
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-04-15 19:21:44 +00:00
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Overrides: []*UpstreamConfig{
|
|
|
|
{
|
|
|
|
Name: "good",
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-04-15 19:21:44 +00:00
|
|
|
Protocol: "grpc",
|
|
|
|
},
|
|
|
|
{
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-04-15 19:21:44 +00:00
|
|
|
Protocol: "http2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "also-good",
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-04-15 19:21:44 +00:00
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
normalizeOnly: true,
|
2021-04-15 19:21:44 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"normalize: upstream config defaults with name": {
|
2021-04-15 19:21:44 +00:00
|
|
|
// This will do nothing to normalization, but it will fail at validation later
|
2021-06-23 19:11:23 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
2021-04-15 19:21:44 +00:00
|
|
|
Name: "web",
|
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Defaults: &UpstreamConfig{
|
|
|
|
Name: "also-good",
|
|
|
|
Protocol: "http2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
expected: &ServiceConfigEntry{
|
2021-04-15 19:21:44 +00:00
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "web",
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-04-15 19:21:44 +00:00
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Defaults: &UpstreamConfig{
|
|
|
|
Name: "also-good",
|
|
|
|
Protocol: "http2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
normalizeOnly: true,
|
2021-04-15 19:21:44 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"normalize: fill-in-kind": {
|
|
|
|
entry: &ServiceConfigEntry{
|
2021-03-09 05:10:27 +00:00
|
|
|
Name: "web",
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
expected: &ServiceConfigEntry{
|
2021-03-18 05:05:00 +00:00
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "web",
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
normalizeOnly: true,
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"normalize: lowercase-protocol": {
|
|
|
|
entry: &ServiceConfigEntry{
|
2021-03-09 05:10:27 +00:00
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
Protocol: "PrOtoCoL",
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
expected: &ServiceConfigEntry{
|
2021-03-18 05:05:00 +00:00
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
Protocol: "protocol",
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
normalizeOnly: true,
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"normalize: connect-kitchen-sink": {
|
|
|
|
entry: &ServiceConfigEntry{
|
2021-03-09 05:10:27 +00:00
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "web",
|
2021-04-15 19:21:44 +00:00
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Overrides: []*UpstreamConfig{
|
|
|
|
{
|
|
|
|
Name: "redis",
|
2021-03-09 05:10:27 +00:00
|
|
|
Protocol: "TcP",
|
|
|
|
},
|
2021-04-15 19:21:44 +00:00
|
|
|
{
|
|
|
|
Name: "memcached",
|
2021-03-09 05:10:27 +00:00
|
|
|
ConnectTimeoutMs: -1,
|
|
|
|
},
|
|
|
|
},
|
2021-04-15 19:21:44 +00:00
|
|
|
Defaults: &UpstreamConfig{ConnectTimeoutMs: -20},
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
expected: &ServiceConfigEntry{
|
2021-03-09 05:10:27 +00:00
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "web",
|
2021-04-15 19:21:44 +00:00
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Overrides: []*UpstreamConfig{
|
|
|
|
{
|
|
|
|
Name: "redis",
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-03-09 05:10:27 +00:00
|
|
|
Protocol: "tcp",
|
2021-03-18 03:37:55 +00:00
|
|
|
ConnectTimeoutMs: 0,
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
2021-04-15 19:21:44 +00:00
|
|
|
{
|
|
|
|
Name: "memcached",
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-03-18 03:37:55 +00:00
|
|
|
ConnectTimeoutMs: 0,
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
|
|
|
},
|
2021-04-15 19:21:44 +00:00
|
|
|
Defaults: &UpstreamConfig{
|
2021-03-18 03:37:55 +00:00
|
|
|
ConnectTimeoutMs: 0,
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
|
|
|
},
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
normalizeOnly: true,
|
2021-03-09 05:10:27 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"wildcard name is not allowed": {
|
|
|
|
entry: &ServiceConfigEntry{
|
2021-04-19 20:23:01 +00:00
|
|
|
Name: WildcardSpecifier,
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: `must be the name of a service, and not a wildcard`,
|
2021-04-19 20:23:01 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"upstream config override no name": {
|
|
|
|
entry: &ServiceConfigEntry{
|
2021-04-15 19:21:44 +00:00
|
|
|
Name: "web",
|
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Overrides: []*UpstreamConfig{
|
|
|
|
{
|
|
|
|
Name: "good",
|
|
|
|
Protocol: "grpc",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Protocol: "http2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "also-good",
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: `Name is required`,
|
2021-04-15 19:21:44 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"upstream config defaults with name": {
|
|
|
|
entry: &ServiceConfigEntry{
|
2021-04-15 19:21:44 +00:00
|
|
|
Name: "web",
|
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Defaults: &UpstreamConfig{
|
|
|
|
Name: "also-good",
|
|
|
|
Protocol: "http2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: `error in upstream defaults: Name must be empty`,
|
2021-04-15 19:21:44 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"connect-kitchen-sink": {
|
|
|
|
entry: &ServiceConfigEntry{
|
2021-04-15 19:21:44 +00:00
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Overrides: []*UpstreamConfig{
|
|
|
|
{
|
|
|
|
Name: "redis",
|
|
|
|
Protocol: "TcP",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "memcached",
|
|
|
|
ConnectTimeoutMs: -1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Defaults: &UpstreamConfig{ConnectTimeoutMs: -20},
|
|
|
|
},
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-04-15 19:21:44 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
expected: &ServiceConfigEntry{
|
2021-04-15 19:21:44 +00:00
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Overrides: []*UpstreamConfig{
|
|
|
|
{
|
|
|
|
Name: "redis",
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-04-15 19:21:44 +00:00
|
|
|
Protocol: "tcp",
|
|
|
|
ConnectTimeoutMs: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "memcached",
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-04-15 19:21:44 +00:00
|
|
|
ConnectTimeoutMs: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Defaults: &UpstreamConfig{ConnectTimeoutMs: 0},
|
|
|
|
},
|
2021-07-22 18:20:45 +00:00
|
|
|
EnterpriseMeta: *DefaultEnterpriseMetaInDefaultPartition(),
|
2021-04-15 19:21:44 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
"validate: nil destination address": {
|
2022-05-19 22:15:57 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "tcp",
|
2022-05-31 20:20:12 +00:00
|
|
|
Destination: &DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: nil,
|
|
|
|
Port: 443,
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
validateErr: "must contain at least one valid address",
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
"validate: empty destination address": {
|
2022-05-19 22:15:57 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "tcp",
|
2022-05-31 20:20:12 +00:00
|
|
|
Destination: &DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{},
|
|
|
|
Port: 443,
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
validateErr: "must contain at least one valid address",
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
"validate: destination ipv4 address": {
|
2022-05-19 22:15:57 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "tcp",
|
2022-05-31 20:20:12 +00:00
|
|
|
Destination: &DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{"1.2.3.4"},
|
|
|
|
Port: 443,
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-05-31 20:20:12 +00:00
|
|
|
"validate: destination ipv6 address": {
|
2022-05-19 22:15:57 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "tcp",
|
2022-05-31 20:20:12 +00:00
|
|
|
Destination: &DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{"2001:0db8:0000:8a2e:0370:7334:1234:5678"},
|
|
|
|
Port: 443,
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-05-31 20:20:12 +00:00
|
|
|
"valid destination shortened ipv6 address": {
|
2022-05-19 22:15:57 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "tcp",
|
2022-05-31 20:20:12 +00:00
|
|
|
Destination: &DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{"2001:db8::8a2e:370:7334"},
|
|
|
|
Port: 443,
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
"validate: invalid destination port": {
|
2022-05-19 22:15:57 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "tcp",
|
2022-05-31 20:20:12 +00:00
|
|
|
Destination: &DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{"2001:db8::8a2e:370:7334"},
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
validateErr: "Invalid Port number",
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
"validate: invalid hostname 1": {
|
2022-05-19 22:15:57 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "tcp",
|
2022-05-31 20:20:12 +00:00
|
|
|
Destination: &DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{"*external.com"},
|
|
|
|
Port: 443,
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
validateErr: "Could not validate address",
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
"validate: invalid hostname 2": {
|
2022-05-19 22:15:57 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "tcp",
|
2022-05-31 20:20:12 +00:00
|
|
|
Destination: &DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{"..hello."},
|
|
|
|
Port: 443,
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "Could not validate address",
|
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
"validate: all web traffic allowed": {
|
2022-05-19 22:15:57 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
2022-07-18 21:10:06 +00:00
|
|
|
Protocol: "http",
|
2022-05-31 20:20:12 +00:00
|
|
|
Destination: &DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{"*"},
|
|
|
|
Port: 443,
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "Could not validate address",
|
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
"validate: multiple hostnames": {
|
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "http",
|
|
|
|
Destination: &DestinationConfig{
|
|
|
|
Addresses: []string{
|
|
|
|
"api.google.com",
|
|
|
|
"web.google.com",
|
|
|
|
},
|
|
|
|
Port: 443,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"validate: duplicate addresses not allowed": {
|
2022-05-19 22:15:57 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "http",
|
2022-05-31 20:20:12 +00:00
|
|
|
Destination: &DestinationConfig{
|
2022-07-18 21:10:06 +00:00
|
|
|
Addresses: []string{
|
|
|
|
"api.google.com",
|
|
|
|
"api.google.com",
|
|
|
|
},
|
|
|
|
Port: 443,
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
|
|
|
},
|
2022-07-18 21:10:06 +00:00
|
|
|
validateErr: "Duplicate address",
|
2022-05-19 22:15:57 +00:00
|
|
|
},
|
2022-09-26 16:29:06 +00:00
|
|
|
"validate: invalid inbound connection balance": {
|
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "http",
|
|
|
|
BalanceInboundConnections: "invalid",
|
|
|
|
},
|
|
|
|
validateErr: "invalid value for balance_inbound_connections",
|
|
|
|
},
|
|
|
|
"validate: invalid default outbound connection balance": {
|
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "http",
|
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Defaults: &UpstreamConfig{
|
|
|
|
BalanceOutboundConnections: "invalid",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "invalid value for balance_outbound_connections",
|
|
|
|
},
|
|
|
|
"validate: invalid override outbound connection balance": {
|
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "http",
|
|
|
|
UpstreamConfig: &UpstreamConfiguration{
|
|
|
|
Overrides: []*UpstreamConfig{
|
|
|
|
{
|
|
|
|
Name: "upstream",
|
|
|
|
BalanceOutboundConnections: "invalid",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "invalid value for balance_outbound_connections",
|
|
|
|
},
|
2022-12-19 20:19:37 +00:00
|
|
|
"validate: invalid extension": {
|
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "http",
|
|
|
|
EnvoyExtensions: []EnvoyExtension{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "invalid EnvoyExtensions[0]: Name is required",
|
|
|
|
},
|
|
|
|
"validate: invalid extension name": {
|
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "http",
|
|
|
|
EnvoyExtensions: []EnvoyExtension{
|
|
|
|
{
|
|
|
|
Name: "not-a-builtin",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-01-30 21:35:26 +00:00
|
|
|
validateErr: `name "not-a-builtin" is not a built-in extension`,
|
2022-12-19 20:19:37 +00:00
|
|
|
},
|
2023-01-30 21:35:26 +00:00
|
|
|
"validate: valid extension": {
|
2022-12-19 20:19:37 +00:00
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "external",
|
|
|
|
Protocol: "http",
|
|
|
|
EnvoyExtensions: []EnvoyExtension{
|
|
|
|
{
|
2023-01-30 21:35:26 +00:00
|
|
|
Name: api.BuiltinAWSLambdaExtension,
|
|
|
|
Arguments: map[string]interface{}{
|
|
|
|
"ARN": "some-arn",
|
|
|
|
},
|
2022-12-19 20:19:37 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-04-19 19:45:00 +00:00
|
|
|
"validate: invalid MutualTLSMode in service-defaults": {
|
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ServiceDefaults,
|
|
|
|
Name: "web",
|
|
|
|
MutualTLSMode: MutualTLSMode("invalid-mtls-mode"),
|
|
|
|
},
|
|
|
|
validateErr: `Invalid MutualTLSMode "invalid-mtls-mode". Must be one of "", "strict", or "permissive".`,
|
|
|
|
},
|
|
|
|
"validate: invalid MutualTLSMode in proxy-defaults": {
|
|
|
|
entry: &ServiceConfigEntry{
|
|
|
|
Kind: ProxyDefaults,
|
|
|
|
Name: ProxyConfigGlobal,
|
|
|
|
MutualTLSMode: MutualTLSMode("invalid-mtls-mode"),
|
|
|
|
},
|
|
|
|
validateErr: `Invalid MutualTLSMode "invalid-mtls-mode". Must be one of "", "strict", or "permissive".`,
|
|
|
|
},
|
2021-04-15 19:21:44 +00:00
|
|
|
}
|
2021-06-23 19:11:23 +00:00
|
|
|
testConfigEntryNormalizeAndValidate(t, cases)
|
2021-04-15 19:21:44 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 04:04:13 +00:00
|
|
|
func TestUpstreamConfig_MergeInto(t *testing.T) {
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
source UpstreamConfig
|
|
|
|
destination map[string]interface{}
|
|
|
|
want map[string]interface{}
|
|
|
|
}{
|
|
|
|
{
|
2021-03-15 20:12:57 +00:00
|
|
|
name: "kitchen sink",
|
2021-03-11 04:04:13 +00:00
|
|
|
source: UpstreamConfig{
|
2022-09-26 16:29:06 +00:00
|
|
|
BalanceOutboundConnections: "exact_balance",
|
|
|
|
EnvoyListenerJSON: "foo",
|
|
|
|
EnvoyClusterJSON: "bar",
|
|
|
|
ConnectTimeoutMs: 5,
|
|
|
|
Protocol: "http",
|
2021-03-11 18:04:40 +00:00
|
|
|
Limits: &UpstreamLimits{
|
2021-03-11 04:04:13 +00:00
|
|
|
MaxConnections: intPointer(3),
|
|
|
|
MaxPendingRequests: intPointer(4),
|
|
|
|
MaxConcurrentRequests: intPointer(5),
|
|
|
|
},
|
2021-03-11 18:04:40 +00:00
|
|
|
PassiveHealthCheck: &PassiveHealthCheck{
|
2023-04-26 22:59:48 +00:00
|
|
|
Interval: 2 * time.Second,
|
|
|
|
MaxFailures: 3,
|
|
|
|
EnforcingConsecutive5xx: uintPointer(4),
|
|
|
|
MaxEjectionPercent: uintPointer(5),
|
|
|
|
BaseEjectionTime: durationPointer(6 * time.Second),
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
MeshGateway: MeshGatewayConfig{Mode: MeshGatewayModeRemote},
|
|
|
|
},
|
|
|
|
destination: make(map[string]interface{}),
|
|
|
|
want: map[string]interface{}{
|
2022-09-26 16:29:06 +00:00
|
|
|
"balance_outbound_connections": "exact_balance",
|
|
|
|
"envoy_listener_json": "foo",
|
|
|
|
"envoy_cluster_json": "bar",
|
|
|
|
"connect_timeout_ms": 5,
|
|
|
|
"protocol": "http",
|
2021-03-11 18:04:40 +00:00
|
|
|
"limits": &UpstreamLimits{
|
2021-03-11 04:04:13 +00:00
|
|
|
MaxConnections: intPointer(3),
|
|
|
|
MaxPendingRequests: intPointer(4),
|
|
|
|
MaxConcurrentRequests: intPointer(5),
|
|
|
|
},
|
2021-03-11 18:04:40 +00:00
|
|
|
"passive_health_check": &PassiveHealthCheck{
|
2023-04-26 22:59:48 +00:00
|
|
|
Interval: 2 * time.Second,
|
|
|
|
MaxFailures: 3,
|
|
|
|
EnforcingConsecutive5xx: uintPointer(4),
|
|
|
|
MaxEjectionPercent: uintPointer(5),
|
|
|
|
BaseEjectionTime: durationPointer(6 * time.Second),
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
"mesh_gateway": MeshGatewayConfig{Mode: MeshGatewayModeRemote},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-03-15 20:12:57 +00:00
|
|
|
name: "kitchen sink override of destination",
|
2021-03-11 04:04:13 +00:00
|
|
|
source: UpstreamConfig{
|
2022-09-26 16:29:06 +00:00
|
|
|
BalanceOutboundConnections: "exact_balance",
|
|
|
|
EnvoyListenerJSON: "foo",
|
|
|
|
EnvoyClusterJSON: "bar",
|
|
|
|
ConnectTimeoutMs: 5,
|
|
|
|
Protocol: "http",
|
2021-03-11 18:04:40 +00:00
|
|
|
Limits: &UpstreamLimits{
|
2021-03-11 04:04:13 +00:00
|
|
|
MaxConnections: intPointer(3),
|
|
|
|
MaxPendingRequests: intPointer(4),
|
|
|
|
MaxConcurrentRequests: intPointer(5),
|
|
|
|
},
|
2021-03-11 18:04:40 +00:00
|
|
|
PassiveHealthCheck: &PassiveHealthCheck{
|
2023-04-26 22:59:48 +00:00
|
|
|
Interval: 2 * time.Second,
|
|
|
|
MaxFailures: 3,
|
|
|
|
EnforcingConsecutive5xx: uintPointer(4),
|
|
|
|
MaxEjectionPercent: uintPointer(5),
|
|
|
|
BaseEjectionTime: durationPointer(6 * time.Second),
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
MeshGateway: MeshGatewayConfig{Mode: MeshGatewayModeRemote},
|
|
|
|
},
|
|
|
|
destination: map[string]interface{}{
|
2022-09-26 16:29:06 +00:00
|
|
|
"balance_outbound_connections": "",
|
|
|
|
"envoy_listener_json": "zip",
|
|
|
|
"envoy_cluster_json": "zap",
|
|
|
|
"connect_timeout_ms": 10,
|
|
|
|
"protocol": "grpc",
|
2021-03-11 18:04:40 +00:00
|
|
|
"limits": &UpstreamLimits{
|
2021-03-11 04:04:13 +00:00
|
|
|
MaxConnections: intPointer(10),
|
|
|
|
MaxPendingRequests: intPointer(11),
|
|
|
|
MaxConcurrentRequests: intPointer(12),
|
|
|
|
},
|
2021-03-11 18:04:40 +00:00
|
|
|
"passive_health_check": &PassiveHealthCheck{
|
2023-04-26 22:59:48 +00:00
|
|
|
MaxFailures: 13,
|
|
|
|
Interval: 14 * time.Second,
|
|
|
|
EnforcingConsecutive5xx: uintPointer(15),
|
|
|
|
MaxEjectionPercent: uintPointer(16),
|
|
|
|
BaseEjectionTime: durationPointer(17 * time.Second),
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
"mesh_gateway": MeshGatewayConfig{Mode: MeshGatewayModeLocal},
|
|
|
|
},
|
|
|
|
want: map[string]interface{}{
|
2022-09-26 16:29:06 +00:00
|
|
|
"balance_outbound_connections": "exact_balance",
|
|
|
|
"envoy_listener_json": "foo",
|
|
|
|
"envoy_cluster_json": "bar",
|
|
|
|
"connect_timeout_ms": 5,
|
|
|
|
"protocol": "http",
|
2021-03-11 18:04:40 +00:00
|
|
|
"limits": &UpstreamLimits{
|
2021-03-11 04:04:13 +00:00
|
|
|
MaxConnections: intPointer(3),
|
|
|
|
MaxPendingRequests: intPointer(4),
|
|
|
|
MaxConcurrentRequests: intPointer(5),
|
|
|
|
},
|
2021-03-11 18:04:40 +00:00
|
|
|
"passive_health_check": &PassiveHealthCheck{
|
2023-04-26 22:59:48 +00:00
|
|
|
Interval: 2 * time.Second,
|
|
|
|
MaxFailures: 3,
|
|
|
|
EnforcingConsecutive5xx: uintPointer(4),
|
|
|
|
MaxEjectionPercent: uintPointer(5),
|
|
|
|
BaseEjectionTime: durationPointer(6 * time.Second),
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
"mesh_gateway": MeshGatewayConfig{Mode: MeshGatewayModeRemote},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty source leaves destination intact",
|
|
|
|
source: UpstreamConfig{},
|
|
|
|
destination: map[string]interface{}{
|
2022-09-26 16:29:06 +00:00
|
|
|
"balance_outbound_connections": "exact_balance",
|
|
|
|
"envoy_listener_json": "zip",
|
|
|
|
"envoy_cluster_json": "zap",
|
|
|
|
"connect_timeout_ms": 10,
|
|
|
|
"protocol": "grpc",
|
2021-03-11 18:04:40 +00:00
|
|
|
"limits": &UpstreamLimits{
|
2021-03-11 04:04:13 +00:00
|
|
|
MaxConnections: intPointer(10),
|
|
|
|
MaxPendingRequests: intPointer(11),
|
|
|
|
MaxConcurrentRequests: intPointer(12),
|
|
|
|
},
|
2021-03-11 18:04:40 +00:00
|
|
|
"passive_health_check": &PassiveHealthCheck{
|
2022-09-01 16:59:11 +00:00
|
|
|
MaxFailures: 13,
|
|
|
|
Interval: 14 * time.Second,
|
2023-04-26 22:59:48 +00:00
|
|
|
EnforcingConsecutive5xx: uintPointer(15),
|
|
|
|
MaxEjectionPercent: uintPointer(16),
|
|
|
|
BaseEjectionTime: durationPointer(17 * time.Second),
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
"mesh_gateway": MeshGatewayConfig{Mode: MeshGatewayModeLocal},
|
|
|
|
},
|
|
|
|
want: map[string]interface{}{
|
2022-09-26 16:29:06 +00:00
|
|
|
"balance_outbound_connections": "exact_balance",
|
|
|
|
"envoy_listener_json": "zip",
|
|
|
|
"envoy_cluster_json": "zap",
|
|
|
|
"connect_timeout_ms": 10,
|
|
|
|
"protocol": "grpc",
|
2021-03-11 18:04:40 +00:00
|
|
|
"limits": &UpstreamLimits{
|
2021-03-11 04:04:13 +00:00
|
|
|
MaxConnections: intPointer(10),
|
|
|
|
MaxPendingRequests: intPointer(11),
|
|
|
|
MaxConcurrentRequests: intPointer(12),
|
|
|
|
},
|
2021-03-11 18:04:40 +00:00
|
|
|
"passive_health_check": &PassiveHealthCheck{
|
2022-09-01 16:59:11 +00:00
|
|
|
MaxFailures: 13,
|
|
|
|
Interval: 14 * time.Second,
|
2023-04-26 22:59:48 +00:00
|
|
|
EnforcingConsecutive5xx: uintPointer(15),
|
|
|
|
MaxEjectionPercent: uintPointer(16),
|
|
|
|
BaseEjectionTime: durationPointer(17 * time.Second),
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
"mesh_gateway": MeshGatewayConfig{Mode: MeshGatewayModeLocal},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty source and destination is a noop",
|
|
|
|
source: UpstreamConfig{},
|
|
|
|
destination: make(map[string]interface{}),
|
|
|
|
want: map[string]interface{}{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range tt {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2021-03-15 20:12:57 +00:00
|
|
|
tc.source.MergeInto(tc.destination)
|
2021-03-11 04:04:13 +00:00
|
|
|
assert.Equal(t, tc.want, tc.destination)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseUpstreamConfig(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
input map[string]interface{}
|
|
|
|
want UpstreamConfig
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "defaults - nil",
|
|
|
|
input: nil,
|
|
|
|
want: UpstreamConfig{
|
|
|
|
ConnectTimeoutMs: 5000,
|
2021-03-18 03:37:55 +00:00
|
|
|
Protocol: "tcp",
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "defaults - empty",
|
|
|
|
input: map[string]interface{}{},
|
|
|
|
want: UpstreamConfig{
|
|
|
|
ConnectTimeoutMs: 5000,
|
2021-03-18 03:37:55 +00:00
|
|
|
Protocol: "tcp",
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "defaults - other stuff",
|
|
|
|
input: map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
"envoy_foo": "envoy_bar",
|
|
|
|
},
|
|
|
|
want: UpstreamConfig{
|
|
|
|
ConnectTimeoutMs: 5000,
|
2021-03-18 03:37:55 +00:00
|
|
|
Protocol: "tcp",
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "protocol override",
|
|
|
|
input: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
want: UpstreamConfig{
|
|
|
|
ConnectTimeoutMs: 5000,
|
|
|
|
Protocol: "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect timeout override, string",
|
|
|
|
input: map[string]interface{}{
|
|
|
|
"connect_timeout_ms": "1000",
|
|
|
|
},
|
|
|
|
want: UpstreamConfig{
|
|
|
|
ConnectTimeoutMs: 1000,
|
2021-03-18 03:37:55 +00:00
|
|
|
Protocol: "tcp",
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect timeout override, float ",
|
|
|
|
input: map[string]interface{}{
|
|
|
|
"connect_timeout_ms": float64(1000.0),
|
|
|
|
},
|
|
|
|
want: UpstreamConfig{
|
|
|
|
ConnectTimeoutMs: 1000,
|
2021-03-18 03:37:55 +00:00
|
|
|
Protocol: "tcp",
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect timeout override, int ",
|
|
|
|
input: map[string]interface{}{
|
|
|
|
"connect_timeout_ms": 1000,
|
|
|
|
},
|
|
|
|
want: UpstreamConfig{
|
|
|
|
ConnectTimeoutMs: 1000,
|
2021-03-18 03:37:55 +00:00
|
|
|
Protocol: "tcp",
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect limits map",
|
|
|
|
input: map[string]interface{}{
|
|
|
|
"limits": map[string]interface{}{
|
|
|
|
"max_connections": 50,
|
|
|
|
"max_pending_requests": 60,
|
|
|
|
"max_concurrent_requests": 70,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: UpstreamConfig{
|
|
|
|
ConnectTimeoutMs: 5000,
|
2021-03-11 18:04:40 +00:00
|
|
|
Limits: &UpstreamLimits{
|
2021-03-11 04:04:13 +00:00
|
|
|
MaxConnections: intPointer(50),
|
|
|
|
MaxPendingRequests: intPointer(60),
|
|
|
|
MaxConcurrentRequests: intPointer(70),
|
|
|
|
},
|
2021-03-18 03:37:55 +00:00
|
|
|
Protocol: "tcp",
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "connect limits map zero",
|
|
|
|
input: map[string]interface{}{
|
|
|
|
"limits": map[string]interface{}{
|
|
|
|
"max_connections": 0,
|
|
|
|
"max_pending_requests": 0,
|
|
|
|
"max_concurrent_requests": 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: UpstreamConfig{
|
|
|
|
ConnectTimeoutMs: 5000,
|
2021-03-11 18:04:40 +00:00
|
|
|
Limits: &UpstreamLimits{
|
2021-03-11 04:04:13 +00:00
|
|
|
MaxConnections: intPointer(0),
|
|
|
|
MaxPendingRequests: intPointer(0),
|
|
|
|
MaxConcurrentRequests: intPointer(0),
|
|
|
|
},
|
2021-03-18 03:37:55 +00:00
|
|
|
Protocol: "tcp",
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "passive health check map",
|
|
|
|
input: map[string]interface{}{
|
|
|
|
"passive_health_check": map[string]interface{}{
|
2023-04-26 22:59:48 +00:00
|
|
|
"interval": "22s",
|
|
|
|
"max_failures": 7,
|
|
|
|
"enforcing_consecutive_5xx": 8,
|
|
|
|
"max_ejection_percent": 9,
|
|
|
|
"base_ejection_time": "10s",
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
want: UpstreamConfig{
|
|
|
|
ConnectTimeoutMs: 5000,
|
2021-03-11 18:04:40 +00:00
|
|
|
PassiveHealthCheck: &PassiveHealthCheck{
|
2023-04-26 22:59:48 +00:00
|
|
|
Interval: 22 * time.Second,
|
|
|
|
MaxFailures: 7,
|
|
|
|
EnforcingConsecutive5xx: uintPointer(8),
|
|
|
|
MaxEjectionPercent: uintPointer(9),
|
|
|
|
BaseEjectionTime: durationPointer(10 * time.Second),
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
2021-03-18 03:37:55 +00:00
|
|
|
Protocol: "tcp",
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mesh gateway map",
|
|
|
|
input: map[string]interface{}{
|
|
|
|
"mesh_gateway": map[string]interface{}{
|
|
|
|
"Mode": "remote",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: UpstreamConfig{
|
|
|
|
ConnectTimeoutMs: 5000,
|
|
|
|
MeshGateway: MeshGatewayConfig{
|
|
|
|
Mode: MeshGatewayModeRemote,
|
|
|
|
},
|
2021-03-18 03:37:55 +00:00
|
|
|
Protocol: "tcp",
|
2021-03-11 04:04:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
got, err := ParseUpstreamConfig(tt.input)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, tt.want, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-31 20:03:38 +00:00
|
|
|
func TestProxyConfigEntry(t *testing.T) {
|
|
|
|
cases := map[string]configEntryTestcase{
|
|
|
|
"proxy config name provided is not global": {
|
|
|
|
entry: &ProxyConfigEntry{
|
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
normalizeErr: `invalid name ("foo"), only "global" is supported`,
|
|
|
|
},
|
|
|
|
"proxy config has no name": {
|
|
|
|
entry: &ProxyConfigEntry{
|
|
|
|
Name: "",
|
|
|
|
},
|
|
|
|
expected: &ProxyConfigEntry{
|
2022-09-01 18:37:47 +00:00
|
|
|
Name: ProxyConfigGlobal,
|
|
|
|
Kind: ProxyDefaults,
|
|
|
|
EnterpriseMeta: *acl.DefaultEnterpriseMeta(),
|
2022-08-31 20:03:38 +00:00
|
|
|
},
|
|
|
|
},
|
2023-05-09 18:20:26 +00:00
|
|
|
"proxy config entry has invalid opaque config": {
|
|
|
|
entry: &ProxyConfigEntry{
|
|
|
|
Name: "global",
|
|
|
|
Config: map[string]interface{}{
|
|
|
|
"envoy_hcp_metrics_bind_socket_dir": "/Consul/is/a/networking/platform/that/enables/securing/your/networking/",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "Config: envoy_hcp_metrics_bind_socket_dir length 71 exceeds max",
|
|
|
|
},
|
2023-03-03 16:12:38 +00:00
|
|
|
"proxy config has invalid failover policy": {
|
|
|
|
entry: &ProxyConfigEntry{
|
|
|
|
Name: "global",
|
|
|
|
FailoverPolicy: &ServiceResolverFailoverPolicy{Mode: "bad"},
|
|
|
|
},
|
2023-04-14 20:42:54 +00:00
|
|
|
validateErr: `Failover-policy mode must be one of '', 'sequential', or 'order-by-locality'`,
|
2023-03-03 16:12:38 +00:00
|
|
|
},
|
|
|
|
"proxy config with valid failover policy": {
|
|
|
|
entry: &ProxyConfigEntry{
|
|
|
|
Name: "global",
|
|
|
|
FailoverPolicy: &ServiceResolverFailoverPolicy{Mode: "order-by-locality"},
|
|
|
|
},
|
|
|
|
expected: &ProxyConfigEntry{
|
|
|
|
Name: ProxyConfigGlobal,
|
|
|
|
Kind: ProxyDefaults,
|
|
|
|
FailoverPolicy: &ServiceResolverFailoverPolicy{Mode: "order-by-locality"},
|
|
|
|
EnterpriseMeta: *acl.DefaultEnterpriseMeta(),
|
|
|
|
},
|
|
|
|
},
|
2022-12-13 19:52:18 +00:00
|
|
|
"proxy config has invalid access log type": {
|
|
|
|
entry: &ProxyConfigEntry{
|
|
|
|
Name: "global",
|
|
|
|
AccessLogs: AccessLogsConfig{
|
|
|
|
Enabled: true,
|
|
|
|
Type: "stdin",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "invalid access log type: stdin",
|
|
|
|
},
|
|
|
|
"proxy config has invalid access log config - both text and json formats": {
|
|
|
|
entry: &ProxyConfigEntry{
|
|
|
|
Name: "global",
|
|
|
|
AccessLogs: AccessLogsConfig{
|
|
|
|
Enabled: true,
|
|
|
|
JSONFormat: "[%START_TIME%]",
|
|
|
|
TextFormat: "{\"start_time\": \"[%START_TIME%]\"}",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "cannot specify both access log JSONFormat and TextFormat",
|
|
|
|
},
|
|
|
|
"proxy config has invalid access log config - file path with wrong type": {
|
|
|
|
entry: &ProxyConfigEntry{
|
|
|
|
Name: "global",
|
|
|
|
AccessLogs: AccessLogsConfig{
|
|
|
|
Enabled: true,
|
|
|
|
Path: "/tmp/logs.txt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "path is only valid for file type access logs",
|
|
|
|
},
|
|
|
|
"proxy config has invalid access log config - no file path specified": {
|
|
|
|
entry: &ProxyConfigEntry{
|
|
|
|
Name: "global",
|
|
|
|
AccessLogs: AccessLogsConfig{
|
|
|
|
Enabled: true,
|
|
|
|
Type: FileLogSinkType,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "path must be specified when using file type access logs",
|
|
|
|
},
|
|
|
|
"proxy config has invalid access log JSON format": {
|
|
|
|
entry: &ProxyConfigEntry{
|
|
|
|
Name: "global",
|
|
|
|
AccessLogs: AccessLogsConfig{
|
|
|
|
Enabled: true,
|
|
|
|
JSONFormat: "{\"start_time\": \"[%START_TIME%]\"", // Missing trailing brace
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "invalid access log json for JSON format",
|
|
|
|
},
|
2022-08-31 20:03:38 +00:00
|
|
|
}
|
|
|
|
testConfigEntryNormalizeAndValidate(t, cases)
|
|
|
|
}
|
|
|
|
|
2019-07-12 17:20:30 +00:00
|
|
|
func requireContainsLower(t *testing.T, haystack, needle string) {
|
|
|
|
t.Helper()
|
|
|
|
require.Contains(t, strings.ToLower(haystack), strings.ToLower(needle))
|
|
|
|
}
|
2021-03-09 05:10:27 +00:00
|
|
|
|
2021-01-13 00:20:20 +00:00
|
|
|
func TestConfigEntryQuery_CacheInfoKey(t *testing.T) {
|
2021-05-21 17:31:18 +00:00
|
|
|
assertCacheInfoKeyIsComplete(t, &ConfigEntryQuery{})
|
2021-01-13 00:20:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestServiceConfigRequest_CacheInfoKey(t *testing.T) {
|
2021-05-31 21:22:16 +00:00
|
|
|
assertCacheInfoKeyIsComplete(t, &ServiceConfigRequest{})
|
2021-01-13 00:20:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDiscoveryChainRequest_CacheInfoKey(t *testing.T) {
|
2021-05-31 21:22:16 +00:00
|
|
|
assertCacheInfoKeyIsComplete(t, &DiscoveryChainRequest{})
|
2021-01-13 00:20:20 +00:00
|
|
|
}
|
2021-06-23 19:11:23 +00:00
|
|
|
|
|
|
|
type configEntryTestcase struct {
|
|
|
|
entry ConfigEntry
|
|
|
|
normalizeOnly bool
|
|
|
|
|
|
|
|
normalizeErr string
|
|
|
|
validateErr string
|
|
|
|
|
2021-08-17 11:27:31 +00:00
|
|
|
// Only one of expected, expectUnchanged or check can be set.
|
|
|
|
expected ConfigEntry
|
|
|
|
expectUnchanged bool
|
2021-06-23 19:11:23 +00:00
|
|
|
// check is called between normalize and validate
|
|
|
|
check func(t *testing.T, entry ConfigEntry)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testConfigEntryNormalizeAndValidate(t *testing.T, cases map[string]configEntryTestcase) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
for name, tc := range cases {
|
|
|
|
tc := tc
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2021-08-17 11:27:31 +00:00
|
|
|
beforeNormalize, err := copystructure.Copy(tc.entry)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = tc.entry.Normalize()
|
2021-06-23 19:11:23 +00:00
|
|
|
if tc.normalizeErr != "" {
|
|
|
|
testutil.RequireErrorContains(t, err, tc.normalizeErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-08-17 11:27:31 +00:00
|
|
|
checkMethods := 0
|
|
|
|
if tc.expected != nil {
|
|
|
|
checkMethods++
|
|
|
|
}
|
|
|
|
if tc.expectUnchanged {
|
|
|
|
checkMethods++
|
|
|
|
}
|
|
|
|
if tc.check != nil {
|
|
|
|
checkMethods++
|
|
|
|
}
|
|
|
|
|
|
|
|
if checkMethods > 1 {
|
|
|
|
t.Fatal("cannot set more than one of 'expected', 'expectUnchanged' and 'check' test case fields")
|
2021-06-23 19:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if tc.expected != nil {
|
|
|
|
require.Equal(t, tc.expected, tc.entry)
|
|
|
|
}
|
|
|
|
|
2021-08-17 11:27:31 +00:00
|
|
|
if tc.expectUnchanged {
|
2021-08-27 15:00:07 +00:00
|
|
|
// EnterpriseMeta.Normalize behaves differently in Ent and OSS which
|
|
|
|
// causes an exact comparison to fail. It's still useful to assert that
|
|
|
|
// nothing else changes though during Normalize. So we ignore
|
|
|
|
// EnterpriseMeta Defaults.
|
|
|
|
opts := cmp.Options{
|
2022-03-13 03:55:53 +00:00
|
|
|
cmp.Comparer(func(a, b acl.EnterpriseMeta) bool {
|
2021-08-27 15:00:07 +00:00
|
|
|
return a.IsSame(&b)
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(beforeNormalize, tc.entry, opts); diff != "" {
|
|
|
|
t.Fatalf("expect unchanged after Normalize, got diff:\n%s", diff)
|
|
|
|
}
|
2021-08-17 11:27:31 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 19:11:23 +00:00
|
|
|
if tc.check != nil {
|
|
|
|
tc.check(t, tc.entry)
|
|
|
|
}
|
|
|
|
|
|
|
|
if tc.normalizeOnly {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = tc.entry.Validate()
|
|
|
|
if tc.validateErr != "" {
|
|
|
|
testutil.RequireErrorContains(t, err, tc.validateErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-09-01 16:59:11 +00:00
|
|
|
|
2023-04-26 22:59:48 +00:00
|
|
|
func intPointer(i int) *int {
|
|
|
|
return &i
|
|
|
|
}
|
|
|
|
|
2022-09-01 16:59:11 +00:00
|
|
|
func uintPointer(v uint32) *uint32 {
|
|
|
|
return &v
|
|
|
|
}
|
2023-04-26 22:59:48 +00:00
|
|
|
|
|
|
|
func durationPointer(d time.Duration) *time.Duration {
|
|
|
|
return &d
|
|
|
|
}
|
2023-05-09 18:20:26 +00:00
|
|
|
|
|
|
|
func TestValidateOpaqueConfigMap(t *testing.T) {
|
|
|
|
tt := map[string]struct {
|
|
|
|
input map[string]interface{}
|
|
|
|
expectErr string
|
|
|
|
}{
|
|
|
|
"hcp metrics socket dir is valid": {
|
|
|
|
input: map[string]interface{}{
|
|
|
|
"envoy_hcp_metrics_bind_socket_dir": "/etc/consul.d/hcp"},
|
|
|
|
expectErr: "",
|
|
|
|
},
|
|
|
|
"hcp metrics socket dir is too long": {
|
|
|
|
input: map[string]interface{}{
|
|
|
|
"envoy_hcp_metrics_bind_socket_dir": "/Consul/is/a/networking/platform/that/enables/securing/your/networking/",
|
|
|
|
},
|
|
|
|
expectErr: "envoy_hcp_metrics_bind_socket_dir length 71 exceeds max 70",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range tt {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
err := validateOpaqueProxyConfig(tc.input)
|
|
|
|
if tc.expectErr != "" {
|
|
|
|
require.ErrorContains(t, err, tc.expectErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|