2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-11-16 18:04:01 +00:00
|
|
|
//go:build !consulent
|
2019-12-10 02:26:41 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
2021-07-08 15:03:38 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2022-11-09 17:29:55 +00:00
|
|
|
"net"
|
2021-07-08 15:03:38 +00:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
2023-04-11 19:04:02 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-07-08 15:03:38 +00:00
|
|
|
)
|
|
|
|
|
2020-12-21 17:36:38 +00:00
|
|
|
var testRuntimeConfigSanitizeExpectedFilename = "TestRuntimeConfig_Sanitize.golden"
|
2019-12-18 15:16:35 +00:00
|
|
|
|
2020-08-27 17:15:10 +00:00
|
|
|
func entFullRuntimeConfig(rt *RuntimeConfig) {}
|
2020-04-28 13:45:33 +00:00
|
|
|
|
2020-11-20 22:43:32 +00:00
|
|
|
var enterpriseReadReplicaWarnings = []string{enterpriseConfigKeyError{key: "read_replica (or the deprecated non_voting_server)"}.Error()}
|
|
|
|
|
|
|
|
var enterpriseConfigKeyWarnings = []string{
|
2021-05-10 14:10:39 +00:00
|
|
|
enterpriseConfigKeyError{key: "license_path"}.Error(),
|
2020-11-20 22:43:32 +00:00
|
|
|
enterpriseConfigKeyError{key: "read_replica (or the deprecated non_voting_server)"}.Error(),
|
|
|
|
enterpriseConfigKeyError{key: "autopilot.redundancy_zone_tag"}.Error(),
|
|
|
|
enterpriseConfigKeyError{key: "autopilot.upgrade_version_tag"}.Error(),
|
|
|
|
enterpriseConfigKeyError{key: "autopilot.disable_upgrade_migration"}.Error(),
|
|
|
|
enterpriseConfigKeyError{key: "dns_config.prefer_namespace"}.Error(),
|
|
|
|
enterpriseConfigKeyError{key: "acl.msp_disable_bootstrap"}.Error(),
|
|
|
|
enterpriseConfigKeyError{key: "acl.tokens.managed_service_provider"}.Error(),
|
|
|
|
enterpriseConfigKeyError{key: "audit"}.Error(),
|
2023-04-11 19:04:02 +00:00
|
|
|
enterpriseConfigKeyError{key: "reporting.license.enabled"}.Error(),
|
2020-04-28 13:45:33 +00:00
|
|
|
}
|
2021-07-08 15:03:38 +00:00
|
|
|
|
|
|
|
// OSS-only equivalent of TestConfigFlagsAndEdgecases
|
|
|
|
// used for flags validated in ent-only code
|
|
|
|
func TestLoad_IntegrationWithFlags_OSS(t *testing.T) {
|
|
|
|
dataDir := testutil.TempDir(t, "consul")
|
|
|
|
defer os.RemoveAll(dataDir)
|
|
|
|
|
|
|
|
tests := []testCase{
|
|
|
|
{
|
|
|
|
desc: "partition config on a client",
|
|
|
|
args: []string{
|
|
|
|
`-data-dir=` + dataDir,
|
|
|
|
`-server=false`,
|
|
|
|
},
|
|
|
|
json: []string{`{ "partition": "foo" }`},
|
|
|
|
hcl: []string{`partition = "foo"`},
|
|
|
|
expectedWarnings: []string{
|
|
|
|
`"partition" is a Consul Enterprise configuration and will have no effect`,
|
|
|
|
},
|
|
|
|
expected: func(rt *RuntimeConfig) {
|
|
|
|
rt.DataDir = dataDir
|
|
|
|
rt.ServerMode = false
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "partition config on a server",
|
|
|
|
args: []string{
|
|
|
|
`-data-dir=` + dataDir,
|
|
|
|
`-server`,
|
|
|
|
},
|
|
|
|
json: []string{`{ "partition": "foo" }`},
|
|
|
|
hcl: []string{`partition = "foo"`},
|
|
|
|
expectedWarnings: []string{
|
|
|
|
`"partition" is a Consul Enterprise configuration and will have no effect`,
|
|
|
|
},
|
|
|
|
expected: func(rt *RuntimeConfig) {
|
|
|
|
rt.DataDir = dataDir
|
|
|
|
rt.ServerMode = true
|
2022-09-16 01:12:10 +00:00
|
|
|
rt.TLS.ServerMode = true
|
2021-07-08 15:03:38 +00:00
|
|
|
rt.LeaveOnTerm = false
|
|
|
|
rt.SkipLeaveOnInt = true
|
|
|
|
rt.RPCConfig.EnableStreaming = true
|
2022-11-09 17:29:55 +00:00
|
|
|
rt.GRPCTLSPort = 8503
|
|
|
|
rt.GRPCTLSAddrs = []net.Addr{defaultGrpcTlsAddr}
|
2021-07-08 15:03:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tests {
|
|
|
|
for _, format := range []string{"json", "hcl"} {
|
|
|
|
name := fmt.Sprintf("%v_%v", tc.desc, format)
|
|
|
|
t.Run(name, tc.run(format, dataDir))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-11 19:04:02 +00:00
|
|
|
|
|
|
|
func TestLoad_ReportingConfig(t *testing.T) {
|
|
|
|
dir := testutil.TempDir(t, t.Name())
|
|
|
|
|
|
|
|
t.Run("load from JSON defaults to false", func(t *testing.T) {
|
|
|
|
content := `{
|
|
|
|
"reporting": {}
|
|
|
|
}`
|
|
|
|
|
|
|
|
opts := LoadOpts{
|
|
|
|
FlagValues: FlagValuesTarget{Config: Config{
|
|
|
|
DataDir: &dir,
|
|
|
|
}},
|
|
|
|
Overrides: []Source{
|
|
|
|
FileSource{
|
|
|
|
Name: "reporting.json",
|
|
|
|
Format: "json",
|
|
|
|
Data: content,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
patchLoadOptsShims(&opts)
|
|
|
|
result, err := Load(opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, result.Warnings, 0)
|
|
|
|
require.Equal(t, false, result.RuntimeConfig.Reporting.License.Enabled)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("load from HCL defaults to false", func(t *testing.T) {
|
|
|
|
content := `
|
|
|
|
reporting {}
|
|
|
|
`
|
|
|
|
|
|
|
|
opts := LoadOpts{
|
|
|
|
FlagValues: FlagValuesTarget{Config: Config{
|
|
|
|
DataDir: &dir,
|
|
|
|
}},
|
|
|
|
Overrides: []Source{
|
|
|
|
FileSource{
|
|
|
|
Name: "reporting.hcl",
|
|
|
|
Format: "hcl",
|
|
|
|
Data: content,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
patchLoadOptsShims(&opts)
|
|
|
|
result, err := Load(opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, result.Warnings, 0)
|
|
|
|
require.Equal(t, false, result.RuntimeConfig.Reporting.License.Enabled)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with value set returns warning and defaults to false", func(t *testing.T) {
|
|
|
|
content := `reporting {
|
|
|
|
license {
|
|
|
|
enabled = true
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
|
|
|
|
opts := LoadOpts{
|
|
|
|
FlagValues: FlagValuesTarget{Config: Config{
|
|
|
|
DataDir: &dir,
|
|
|
|
}},
|
|
|
|
Overrides: []Source{
|
|
|
|
FileSource{
|
|
|
|
Name: "reporting.hcl",
|
|
|
|
Format: "hcl",
|
|
|
|
Data: content,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
patchLoadOptsShims(&opts)
|
|
|
|
result, err := Load(opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, result.Warnings, 1)
|
|
|
|
require.Contains(t, result.Warnings[0], "\"reporting.license.enabled\" is a Consul Enterprise configuration and will have no effect")
|
|
|
|
require.Equal(t, false, result.RuntimeConfig.Reporting.License.Enabled)
|
|
|
|
})
|
|
|
|
}
|