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
|
|
|
|
2021-11-16 18:04:01 +00:00
|
|
|
//go:build !consulent
|
2020-04-28 13:45:33 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-11-20 22:43:32 +00:00
|
|
|
func TestValidateEnterpriseConfigKeys(t *testing.T) {
|
2020-04-28 13:45:33 +00:00
|
|
|
// ensure that all the enterprise configurations
|
|
|
|
type testCase struct {
|
|
|
|
config Config
|
|
|
|
badKeys []string
|
|
|
|
check func(t *testing.T, c *Config)
|
|
|
|
}
|
|
|
|
|
|
|
|
boolVal := true
|
|
|
|
stringVal := "string"
|
|
|
|
|
|
|
|
cases := map[string]testCase{
|
2020-11-17 15:53:57 +00:00
|
|
|
"read_replica": {
|
|
|
|
config: Config{
|
|
|
|
ReadReplica: &boolVal,
|
|
|
|
},
|
2020-11-20 22:43:32 +00:00
|
|
|
badKeys: []string{"read_replica (or the deprecated non_voting_server)"},
|
2020-11-17 15:53:57 +00:00
|
|
|
},
|
2020-04-28 13:45:33 +00:00
|
|
|
"segment": {
|
|
|
|
config: Config{
|
|
|
|
SegmentName: &stringVal,
|
|
|
|
},
|
|
|
|
badKeys: []string{"segment"},
|
|
|
|
},
|
|
|
|
"segments": {
|
|
|
|
config: Config{
|
2020-11-20 22:43:32 +00:00
|
|
|
Segments: []Segment{{Name: &stringVal}},
|
2020-04-28 13:45:33 +00:00
|
|
|
},
|
|
|
|
badKeys: []string{"segments"},
|
|
|
|
},
|
|
|
|
"autopilot.redundancy_zone_tag": {
|
|
|
|
config: Config{
|
|
|
|
Autopilot: Autopilot{
|
|
|
|
RedundancyZoneTag: &stringVal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
badKeys: []string{"autopilot.redundancy_zone_tag"},
|
|
|
|
},
|
|
|
|
"autopilot.upgrade_version_tag": {
|
|
|
|
config: Config{
|
|
|
|
Autopilot: Autopilot{
|
|
|
|
UpgradeVersionTag: &stringVal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
badKeys: []string{"autopilot.upgrade_version_tag"},
|
|
|
|
},
|
|
|
|
"autopilot.disable_upgrade_migration": {
|
|
|
|
config: Config{
|
2020-11-20 22:43:32 +00:00
|
|
|
Autopilot: Autopilot{DisableUpgradeMigration: &boolVal},
|
2020-04-28 13:45:33 +00:00
|
|
|
},
|
|
|
|
badKeys: []string{"autopilot.disable_upgrade_migration"},
|
|
|
|
},
|
|
|
|
"dns_config.prefer_namespace": {
|
|
|
|
config: Config{
|
2020-11-20 22:43:32 +00:00
|
|
|
DNS: DNS{PreferNamespace: &boolVal},
|
2020-04-28 13:45:33 +00:00
|
|
|
},
|
|
|
|
badKeys: []string{"dns_config.prefer_namespace"},
|
|
|
|
check: func(t *testing.T, c *Config) {
|
|
|
|
require.Nil(t, c.DNS.PreferNamespace)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"acl.msp_disable_bootstrap": {
|
|
|
|
config: Config{
|
2020-11-20 22:43:32 +00:00
|
|
|
ACL: ACL{MSPDisableBootstrap: &boolVal},
|
2020-04-28 13:45:33 +00:00
|
|
|
},
|
|
|
|
badKeys: []string{"acl.msp_disable_bootstrap"},
|
|
|
|
check: func(t *testing.T, c *Config) {
|
|
|
|
require.Nil(t, c.ACL.MSPDisableBootstrap)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"acl.tokens.managed_service_provider": {
|
|
|
|
config: Config{
|
|
|
|
ACL: ACL{
|
|
|
|
Tokens: Tokens{
|
|
|
|
ManagedServiceProvider: []ServiceProviderToken{
|
|
|
|
{
|
|
|
|
AccessorID: &stringVal,
|
|
|
|
SecretID: &stringVal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
badKeys: []string{"acl.tokens.managed_service_provider"},
|
|
|
|
check: func(t *testing.T, c *Config) {
|
|
|
|
require.Empty(t, c.ACL.Tokens.ManagedServiceProvider)
|
|
|
|
require.Nil(t, c.ACL.Tokens.ManagedServiceProvider)
|
|
|
|
},
|
|
|
|
},
|
2021-05-10 14:10:39 +00:00
|
|
|
"license_path": {
|
|
|
|
config: Config{
|
|
|
|
LicensePath: &stringVal,
|
|
|
|
},
|
|
|
|
badKeys: []string{"license_path"},
|
|
|
|
check: func(t *testing.T, c *Config) {
|
|
|
|
require.Empty(t, c.LicensePath)
|
|
|
|
},
|
|
|
|
},
|
2023-04-11 19:04:02 +00:00
|
|
|
"reporting.license.enabled": {
|
|
|
|
config: Config{
|
|
|
|
Reporting: Reporting{
|
|
|
|
License: License{
|
|
|
|
Enabled: &boolVal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
badKeys: []string{"reporting.license.enabled"},
|
|
|
|
check: func(t *testing.T, c *Config) {
|
|
|
|
require.Nil(t, c.Reporting.License.Enabled)
|
|
|
|
},
|
|
|
|
},
|
2020-04-28 13:45:33 +00:00
|
|
|
"multi": {
|
|
|
|
config: Config{
|
2020-11-17 15:53:57 +00:00
|
|
|
ReadReplica: &boolVal,
|
|
|
|
SegmentName: &stringVal,
|
2021-12-01 21:08:14 +00:00
|
|
|
ACL: ACL{
|
|
|
|
Tokens: Tokens{
|
|
|
|
DeprecatedTokens: DeprecatedTokens{AgentMaster: &stringVal},
|
|
|
|
},
|
|
|
|
},
|
2020-04-28 13:45:33 +00:00
|
|
|
},
|
2020-11-20 22:43:32 +00:00
|
|
|
badKeys: []string{"read_replica (or the deprecated non_voting_server)", "segment"},
|
2020-04-28 13:45:33 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tcase := range cases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2020-11-20 22:43:32 +00:00
|
|
|
errs := validateEnterpriseConfigKeys(&tcase.config)
|
|
|
|
if len(tcase.badKeys) == 0 {
|
|
|
|
require.Len(t, errs, 0)
|
|
|
|
return
|
|
|
|
}
|
2020-04-28 13:45:33 +00:00
|
|
|
|
2020-11-20 22:43:32 +00:00
|
|
|
var expected []error
|
|
|
|
for _, k := range tcase.badKeys {
|
|
|
|
expected = append(expected, enterpriseConfigKeyError{key: k})
|
|
|
|
}
|
|
|
|
require.ElementsMatch(t, expected, errs)
|
2020-04-28 13:45:33 +00:00
|
|
|
|
2020-11-20 22:43:32 +00:00
|
|
|
if tcase.check != nil {
|
|
|
|
tcase.check(t, &tcase.config)
|
2020-04-28 13:45:33 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|