05c7373a28
set -euo pipefail unset CDPATH cd "$(dirname "$0")" for f in $(git grep '\brequire := require\.New(' | cut -d':' -f1 | sort -u); do echo "=== require: $f ===" sed -i '/require := require.New(t)/d' $f # require.XXX(blah) but not require.XXX(tblah) or require.XXX(rblah) sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\([^tr]\)/require.\1(t,\2/g' $f # require.XXX(tblah) but not require.XXX(t, blah) sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/require.\1(t,\2/g' $f # require.XXX(rblah) but not require.XXX(r, blah) sed -i 's/\brequire\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/require.\1(t,\2/g' $f gofmt -s -w $f done for f in $(git grep '\bassert := assert\.New(' | cut -d':' -f1 | sort -u); do echo "=== assert: $f ===" sed -i '/assert := assert.New(t)/d' $f # assert.XXX(blah) but not assert.XXX(tblah) or assert.XXX(rblah) sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\([^tr]\)/assert.\1(t,\2/g' $f # assert.XXX(tblah) but not assert.XXX(t, blah) sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(t[^,]\)/assert.\1(t,\2/g' $f # assert.XXX(rblah) but not assert.XXX(r, blah) sed -i 's/\bassert\.\([a-zA-Z0-9_]*\)(\(r[^,]\)/assert.\1(t,\2/g' $f gofmt -s -w $f done
173 lines
4.5 KiB
Go
173 lines
4.5 KiB
Go
package config
|
|
|
|
import (
|
|
"sort"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestLoad_DeprecatedConfig(t *testing.T) {
|
|
opts := LoadOpts{
|
|
HCL: []string{`
|
|
data_dir = "/foo"
|
|
|
|
acl_datacenter = "dcone"
|
|
|
|
acl_agent_token = "token1"
|
|
acl_token = "token2"
|
|
|
|
acl_replication_token = "token3"
|
|
|
|
acl_default_policy = "deny"
|
|
acl_down_policy = "async-cache"
|
|
|
|
acl_ttl = "3h"
|
|
acl_enable_key_list_policy = true
|
|
|
|
`},
|
|
}
|
|
patchLoadOptsShims(&opts)
|
|
result, err := Load(opts)
|
|
require.NoError(t, err)
|
|
|
|
expectWarns := []string{
|
|
deprecationWarning("acl_agent_token", "acl.tokens.agent"),
|
|
deprecationWarning("acl_datacenter", "primary_datacenter"),
|
|
deprecationWarning("acl_default_policy", "acl.default_policy"),
|
|
deprecationWarning("acl_down_policy", "acl.down_policy"),
|
|
deprecationWarning("acl_enable_key_list_policy", "acl.enable_key_list_policy"),
|
|
deprecationWarning("acl_replication_token", "acl.tokens.replication"),
|
|
deprecationWarning("acl_token", "acl.tokens.default"),
|
|
deprecationWarning("acl_ttl", "acl.token_ttl"),
|
|
}
|
|
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)
|
|
require.Equal(t, "token1", rt.ACLTokens.ACLAgentToken)
|
|
require.Equal(t, "token2", rt.ACLTokens.ACLDefaultToken)
|
|
require.Equal(t, "token3", rt.ACLTokens.ACLReplicationToken)
|
|
require.Equal(t, "deny", rt.ACLResolverSettings.ACLDefaultPolicy)
|
|
require.Equal(t, "async-cache", rt.ACLResolverSettings.ACLDownPolicy)
|
|
require.Equal(t, 3*time.Hour, rt.ACLResolverSettings.ACLTokenTTL)
|
|
require.Equal(t, true, rt.ACLEnableKeyListPolicy)
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
func TestLoad_DeprecatedConfig_ACLMasterTokens(t *testing.T) {
|
|
t.Run("top-level fields", func(t *testing.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(t, err)
|
|
|
|
expectWarns := []string{
|
|
deprecationWarning("acl_master_token", "acl.tokens.initial_management"),
|
|
deprecationWarning("acl_agent_master_token", "acl.tokens.agent_recovery"),
|
|
}
|
|
require.ElementsMatch(t, expectWarns, result.Warnings)
|
|
|
|
rt := result.RuntimeConfig
|
|
require.Equal(t, "token1", rt.ACLInitialManagementToken)
|
|
require.Equal(t, "token2", rt.ACLTokens.ACLAgentRecoveryToken)
|
|
})
|
|
|
|
t.Run("embedded in tokens struct", func(t *testing.T) {
|
|
|
|
opts := LoadOpts{
|
|
HCL: []string{`
|
|
data_dir = "/foo"
|
|
|
|
acl {
|
|
tokens {
|
|
master = "token1"
|
|
agent_master = "token2"
|
|
}
|
|
}
|
|
`},
|
|
}
|
|
patchLoadOptsShims(&opts)
|
|
|
|
result, err := Load(opts)
|
|
require.NoError(t, err)
|
|
|
|
expectWarns := []string{
|
|
deprecationWarning("acl.tokens.master", "acl.tokens.initial_management"),
|
|
deprecationWarning("acl.tokens.agent_master", "acl.tokens.agent_recovery"),
|
|
}
|
|
require.ElementsMatch(t, expectWarns, result.Warnings)
|
|
|
|
rt := result.RuntimeConfig
|
|
require.Equal(t, "token1", rt.ACLInitialManagementToken)
|
|
require.Equal(t, "token2", rt.ACLTokens.ACLAgentRecoveryToken)
|
|
})
|
|
|
|
t.Run("both", func(t *testing.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(t, err)
|
|
|
|
rt := result.RuntimeConfig
|
|
require.Equal(t, "token3", rt.ACLInitialManagementToken)
|
|
require.Equal(t, "token4", rt.ACLTokens.ACLAgentRecoveryToken)
|
|
})
|
|
}
|