2021-09-03 21:12:30 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"testing"
|
2021-09-22 17:38:40 +00:00
|
|
|
"time"
|
2021-09-03 21:12:30 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoad_DeprecatedConfig(t *testing.T) {
|
|
|
|
opts := LoadOpts{
|
|
|
|
HCL: []string{`
|
|
|
|
data_dir = "/foo"
|
|
|
|
|
|
|
|
acl_datacenter = "dcone"
|
|
|
|
|
2021-12-01 21:08:14 +00:00
|
|
|
acl_agent_token = "token1"
|
|
|
|
acl_token = "token2"
|
2021-09-03 21:12:30 +00:00
|
|
|
|
2021-12-01 21:08:14 +00:00
|
|
|
acl_replication_token = "token3"
|
2021-09-03 21:33:20 +00:00
|
|
|
|
2021-09-03 22:00:28 +00:00
|
|
|
acl_default_policy = "deny"
|
|
|
|
acl_down_policy = "async-cache"
|
|
|
|
|
2021-09-22 17:38:40 +00:00
|
|
|
acl_ttl = "3h"
|
2021-09-22 21:22:52 +00:00
|
|
|
acl_enable_key_list_policy = true
|
2021-09-22 17:38:40 +00:00
|
|
|
|
2021-09-03 21:12:30 +00:00
|
|
|
`},
|
|
|
|
}
|
|
|
|
patchLoadOptsShims(&opts)
|
|
|
|
result, err := Load(opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
expectWarns := []string{
|
|
|
|
deprecationWarning("acl_agent_token", "acl.tokens.agent"),
|
|
|
|
deprecationWarning("acl_datacenter", "primary_datacenter"),
|
2021-09-03 22:00:28 +00:00
|
|
|
deprecationWarning("acl_default_policy", "acl.default_policy"),
|
|
|
|
deprecationWarning("acl_down_policy", "acl.down_policy"),
|
2021-09-22 21:22:52 +00:00
|
|
|
deprecationWarning("acl_enable_key_list_policy", "acl.enable_key_list_policy"),
|
2021-09-03 21:33:20 +00:00
|
|
|
deprecationWarning("acl_replication_token", "acl.tokens.replication"),
|
2021-09-03 21:12:30 +00:00
|
|
|
deprecationWarning("acl_token", "acl.tokens.default"),
|
2021-09-22 17:38:40 +00:00
|
|
|
deprecationWarning("acl_ttl", "acl.token_ttl"),
|
2021-09-03 21:12:30 +00:00
|
|
|
}
|
|
|
|
sort.Strings(result.Warnings)
|
|
|
|
require.Equal(t, expectWarns, result.Warnings)
|
|
|
|
// Ideally this would compare against the entire result.RuntimeConfig, but
|
|
|
|
// we have so many non-zero defaults in that response that the noise of those
|
|
|
|
// defaults makes this test difficult to read. So as a workaround, compare
|
|
|
|
// specific values.
|
|
|
|
rt := result.RuntimeConfig
|
|
|
|
require.Equal(t, true, rt.ACLsEnabled)
|
|
|
|
require.Equal(t, "dcone", rt.PrimaryDatacenter)
|
2021-12-01 21:08:14 +00:00
|
|
|
require.Equal(t, "token1", rt.ACLTokens.ACLAgentToken)
|
|
|
|
require.Equal(t, "token2", rt.ACLTokens.ACLDefaultToken)
|
|
|
|
require.Equal(t, "token3", rt.ACLTokens.ACLReplicationToken)
|
2021-09-03 22:00:28 +00:00
|
|
|
require.Equal(t, "deny", rt.ACLResolverSettings.ACLDefaultPolicy)
|
|
|
|
require.Equal(t, "async-cache", rt.ACLResolverSettings.ACLDownPolicy)
|
2021-09-22 17:38:40 +00:00
|
|
|
require.Equal(t, 3*time.Hour, rt.ACLResolverSettings.ACLTokenTTL)
|
2021-09-22 21:22:52 +00:00
|
|
|
require.Equal(t, true, rt.ACLEnableKeyListPolicy)
|
2021-09-03 21:12:30 +00:00
|
|
|
}
|
2021-09-03 21:42:52 +00:00
|
|
|
|
|
|
|
func TestLoad_DeprecatedConfig_ACLReplication(t *testing.T) {
|
|
|
|
opts := LoadOpts{
|
|
|
|
HCL: []string{`
|
|
|
|
data_dir = "/foo"
|
|
|
|
|
|
|
|
enable_acl_replication = true
|
|
|
|
|
|
|
|
`},
|
|
|
|
}
|
|
|
|
patchLoadOptsShims(&opts)
|
|
|
|
result, err := Load(opts)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
expectWarns := []string{
|
|
|
|
deprecationWarning("enable_acl_replication", "acl.enable_token_replication"),
|
|
|
|
}
|
|
|
|
sort.Strings(result.Warnings)
|
|
|
|
require.Equal(t, expectWarns, result.Warnings)
|
|
|
|
// Ideally this would compare against the entire result.RuntimeConfig, but
|
|
|
|
// we have so many non-zero defaults in that response that the noise of those
|
|
|
|
// defaults makes this test difficult to read. So as a workaround, compare
|
|
|
|
// specific values.
|
|
|
|
rt := result.RuntimeConfig
|
|
|
|
require.Equal(t, true, rt.ACLTokenReplication)
|
|
|
|
}
|
2021-12-01 21:08:14 +00:00
|
|
|
|
|
|
|
func TestLoad_DeprecatedConfig_ACLMasterTokens(t *testing.T) {
|
|
|
|
t.Run("top-level fields", func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
opts := LoadOpts{
|
|
|
|
HCL: []string{`
|
|
|
|
data_dir = "/foo"
|
|
|
|
|
|
|
|
acl_master_token = "token1"
|
|
|
|
acl_agent_master_token = "token2"
|
|
|
|
`},
|
|
|
|
}
|
|
|
|
patchLoadOptsShims(&opts)
|
|
|
|
|
|
|
|
result, err := Load(opts)
|
|
|
|
require.NoError(err)
|
|
|
|
|
|
|
|
expectWarns := []string{
|
|
|
|
deprecationWarning("acl_master_token", "acl.tokens.initial_management"),
|
|
|
|
deprecationWarning("acl_agent_master_token", "acl.tokens.agent_recovery"),
|
|
|
|
}
|
|
|
|
require.ElementsMatch(expectWarns, result.Warnings)
|
|
|
|
|
|
|
|
rt := result.RuntimeConfig
|
2021-12-07 12:39:28 +00:00
|
|
|
require.Equal("token1", rt.ACLInitialManagementToken)
|
2021-12-07 12:12:47 +00:00
|
|
|
require.Equal("token2", rt.ACLTokens.ACLAgentRecoveryToken)
|
2021-12-01 21:08:14 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("embedded in tokens struct", func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
opts := LoadOpts{
|
|
|
|
HCL: []string{`
|
|
|
|
data_dir = "/foo"
|
|
|
|
|
|
|
|
acl {
|
|
|
|
tokens {
|
|
|
|
master = "token1"
|
|
|
|
agent_master = "token2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`},
|
|
|
|
}
|
|
|
|
patchLoadOptsShims(&opts)
|
|
|
|
|
|
|
|
result, err := Load(opts)
|
|
|
|
require.NoError(err)
|
|
|
|
|
|
|
|
expectWarns := []string{
|
|
|
|
deprecationWarning("acl.tokens.master", "acl.tokens.initial_management"),
|
|
|
|
deprecationWarning("acl.tokens.agent_master", "acl.tokens.agent_recovery"),
|
|
|
|
}
|
|
|
|
require.ElementsMatch(expectWarns, result.Warnings)
|
|
|
|
|
|
|
|
rt := result.RuntimeConfig
|
2021-12-07 12:39:28 +00:00
|
|
|
require.Equal("token1", rt.ACLInitialManagementToken)
|
2021-12-07 12:12:47 +00:00
|
|
|
require.Equal("token2", rt.ACLTokens.ACLAgentRecoveryToken)
|
2021-12-01 21:08:14 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("both", func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
opts := LoadOpts{
|
|
|
|
HCL: []string{`
|
|
|
|
data_dir = "/foo"
|
|
|
|
|
|
|
|
acl_master_token = "token1"
|
|
|
|
acl_agent_master_token = "token2"
|
|
|
|
|
|
|
|
acl {
|
|
|
|
tokens {
|
|
|
|
master = "token3"
|
|
|
|
agent_master = "token4"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`},
|
|
|
|
}
|
|
|
|
patchLoadOptsShims(&opts)
|
|
|
|
|
|
|
|
result, err := Load(opts)
|
|
|
|
require.NoError(err)
|
|
|
|
|
|
|
|
rt := result.RuntimeConfig
|
2021-12-07 12:39:28 +00:00
|
|
|
require.Equal("token3", rt.ACLInitialManagementToken)
|
2021-12-07 12:12:47 +00:00
|
|
|
require.Equal("token4", rt.ACLTokens.ACLAgentRecoveryToken)
|
2021-12-01 21:08:14 +00:00
|
|
|
})
|
|
|
|
}
|