mirror of https://github.com/hashicorp/consul
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
4.5 KiB
170 lines
4.5 KiB
2 years ago
|
// Copyright (c) HashiCorp, Inc.
|
||
1 year ago
|
// SPDX-License-Identifier: BUSL-1.1
|
||
2 years ago
|
|
||
3 years ago
|
//go:build !consulent
|
||
5 years ago
|
|
||
|
package config
|
||
|
|
||
3 years ago
|
import (
|
||
|
"fmt"
|
||
2 years ago
|
"net"
|
||
3 years ago
|
"os"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/hashicorp/consul/sdk/testutil"
|
||
2 years ago
|
"github.com/stretchr/testify/require"
|
||
3 years ago
|
)
|
||
|
|
||
4 years ago
|
var testRuntimeConfigSanitizeExpectedFilename = "TestRuntimeConfig_Sanitize.golden"
|
||
5 years ago
|
|
||
4 years ago
|
func entFullRuntimeConfig(rt *RuntimeConfig) {}
|
||
5 years ago
|
|
||
4 years ago
|
var enterpriseReadReplicaWarnings = []string{enterpriseConfigKeyError{key: "read_replica (or the deprecated non_voting_server)"}.Error()}
|
||
|
|
||
|
var enterpriseConfigKeyWarnings = []string{
|
||
4 years ago
|
enterpriseConfigKeyError{key: "license_path"}.Error(),
|
||
4 years ago
|
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(),
|
||
2 years ago
|
enterpriseConfigKeyError{key: "reporting.license.enabled"}.Error(),
|
||
5 years ago
|
}
|
||
3 years ago
|
|
||
1 year ago
|
// CE-only equivalent of TestConfigFlagsAndEdgecases
|
||
3 years ago
|
// used for flags validated in ent-only code
|
||
1 year ago
|
func TestLoad_IntegrationWithFlags_CE(t *testing.T) {
|
||
3 years ago
|
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
|
||
2 years ago
|
rt.TLS.ServerMode = true
|
||
3 years ago
|
rt.LeaveOnTerm = false
|
||
|
rt.SkipLeaveOnInt = true
|
||
|
rt.RPCConfig.EnableStreaming = true
|
||
2 years ago
|
rt.GRPCTLSPort = 8503
|
||
|
rt.GRPCTLSAddrs = []net.Addr{defaultGrpcTlsAddr}
|
||
3 years ago
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
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))
|
||
|
}
|
||
|
}
|
||
|
}
|
||
2 years ago
|
|
||
|
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)
|
||
|
})
|
||
|
}
|