consul/agent/config/builder_oss_test.go
Matt Keeler 0242dcc5d2
Add ability to load a license from the configuration/environment (#10441)
This is mainly for forward compatibility with 1.10 where licensing requirements are changing.

For older releases we are adding the ability to load the license from a configuration/environment to facilitate a smoother upgrade process. For servers, we will allow the configuration to be set but it will not be used (a warning log is emitted saying as much). For client agents it will actually cause the license to be used in place of the auto-retrieval process.

Unlike with 1.10, client agents will not be able to update the license loaded via config with a reload. It is expected that this configuration is only used while on the path to upgrading to 1.10 and therefore the ability to reload the license should not be necessary.
2021-06-21 15:00:46 -04:00

139 lines
3.2 KiB
Go

// +build !consulent
package config
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestValidateEnterpriseConfigKeys(t *testing.T) {
// 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{
"read_replica": {
config: Config{
ReadReplica: &boolVal,
},
badKeys: []string{"read_replica (or the deprecated non_voting_server)"},
},
"segment": {
config: Config{
SegmentName: &stringVal,
},
badKeys: []string{"segment"},
},
"segments": {
config: Config{
Segments: []Segment{{Name: &stringVal}},
},
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{
Autopilot: Autopilot{DisableUpgradeMigration: &boolVal},
},
badKeys: []string{"autopilot.disable_upgrade_migration"},
},
"dns_config.prefer_namespace": {
config: Config{
DNS: DNS{PreferNamespace: &boolVal},
},
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{
ACL: ACL{MSPDisableBootstrap: &boolVal},
},
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)
},
},
"license_path": {
config: Config{
LicensePath: &stringVal,
},
badKeys: []string{"license_path"},
check: func(t *testing.T, c *Config) {
require.Empty(t, c.LicensePath)
},
},
"multi": {
config: Config{
ReadReplica: &boolVal,
SegmentName: &stringVal,
ACL: ACL{Tokens: Tokens{AgentMaster: &stringVal}},
},
badKeys: []string{"read_replica (or the deprecated non_voting_server)", "segment"},
},
}
for name, tcase := range cases {
t.Run(name, func(t *testing.T) {
errs := validateEnterpriseConfigKeys(&tcase.config)
if len(tcase.badKeys) == 0 {
require.Len(t, errs, 0)
return
}
var expected []error
for _, k := range tcase.badKeys {
expected = append(expected, enterpriseConfigKeyError{key: k})
}
require.ElementsMatch(t, expected, errs)
if tcase.check != nil {
tcase.check(t, &tcase.config)
}
})
}
}