Remove CE-only warning from shared tests (#26052)

* Remove CE-only warning from shared tests

* Add tests for all warnings emitted during raft config parsing

* Unmark warnings as CE only that are universal
This commit is contained in:
Paul Banks
2024-03-20 17:08:33 +00:00
committed by GitHub
parent f706c20084
commit fc0abf2d9f
3 changed files with 34 additions and 3 deletions

View File

@@ -238,7 +238,7 @@ func parseRaftBackendConfig(conf map[string]string, logger log.Logger) (*RaftBac
} }
c.AutopilotRedundancyZone = conf["autopilot_redundancy_zone"] c.AutopilotRedundancyZone = conf["autopilot_redundancy_zone"]
if c.AutopilotRedundancyZone == "" { if c.AutopilotRedundancyZone != "" {
emitEntWarning(logger, "autopilot_redundancy_zone") emitEntWarning(logger, "autopilot_redundancy_zone")
} }

View File

@@ -9,9 +9,17 @@ import (
"time" "time"
"github.com/hashicorp/go-hclog" "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/helper/constants"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func ceOnlyWarnings(warns ...string) []string {
if !constants.IsEnterprise {
return warns
}
return nil
}
func TestRaft_ParseConfig(t *testing.T) { func TestRaft_ParseConfig(t *testing.T) {
// Note some of these can be parallel tests but since we need to setEnv in // Note some of these can be parallel tests but since we need to setEnv in
// some we can't make them all parallel so it's don inside the loop. We assume // some we can't make them all parallel so it's don inside the loop. We assume
@@ -50,6 +58,7 @@ func TestRaft_ParseConfig(t *testing.T) {
cfg.RaftLogVerifierEnabled = true cfg.RaftLogVerifierEnabled = true
cfg.RaftLogVerificationInterval = defaultRaftLogVerificationInterval cfg.RaftLogVerificationInterval = defaultRaftLogVerificationInterval
}, },
wantWarns: []string{"raft_log_verification_interval is less than the minimum allowed"},
}, },
{ {
name: "WAL verifier interval, one", name: "WAL verifier interval, one",
@@ -63,6 +72,7 @@ func TestRaft_ParseConfig(t *testing.T) {
// Below min so should get default // Below min so should get default
cfg.RaftLogVerificationInterval = defaultRaftLogVerificationInterval cfg.RaftLogVerificationInterval = defaultRaftLogVerificationInterval
}, },
wantWarns: []string{"raft_log_verification_interval is less than the minimum allowed"},
}, },
{ {
name: "WAL verifier interval, nothing", name: "WAL verifier interval, nothing",
@@ -74,6 +84,7 @@ func TestRaft_ParseConfig(t *testing.T) {
cfg.RaftLogVerifierEnabled = true cfg.RaftLogVerifierEnabled = true
cfg.RaftLogVerificationInterval = defaultRaftLogVerificationInterval cfg.RaftLogVerificationInterval = defaultRaftLogVerificationInterval
}, },
wantWarns: []string{"raft_log_verification_interval is less than the minimum allowed"},
}, },
{ {
name: "WAL verifier interval, valid", name: "WAL verifier interval, valid",
@@ -104,6 +115,18 @@ func TestRaft_ParseConfig(t *testing.T) {
wantErr: "does not parse", wantErr: "does not parse",
}, },
// AUTOPILOT Redundancy Zone ---------------------------------------------
{
name: "Autopilot redundancy zone, ok",
conf: map[string]string{
"autopilot_redundancy_zone": "us-east-1a",
},
wantMutation: func(cfg *RaftBackendConfig) {
cfg.AutopilotRedundancyZone = "us-east-1a"
},
wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=autopilot_redundancy_zone"),
},
// Non-voter config ------------------------------------------------------ // Non-voter config ------------------------------------------------------
{ {
name: "non-voter, no retry-join, valid false", name: "non-voter, no retry-join, valid false",
@@ -113,7 +136,6 @@ func TestRaft_ParseConfig(t *testing.T) {
wantMutation: func(cfg *RaftBackendConfig) { wantMutation: func(cfg *RaftBackendConfig) {
// Should be default // Should be default
}, },
wantWarns: []string{"is configuration for a Vault Enterprise feature and has been ignored"},
}, },
{ {
name: "non-voter, retry-join, valid false", name: "non-voter, retry-join, valid false",
@@ -142,6 +164,7 @@ func TestRaft_ParseConfig(t *testing.T) {
cfg.RetryJoin = "not-empty" cfg.RetryJoin = "not-empty"
cfg.RaftNonVoter = true cfg.RaftNonVoter = true
}, },
wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=retry_join_as_non_voter"),
}, },
{ {
name: "non-voter, no retry-join, invalid empty", name: "non-voter, no retry-join, invalid empty",
@@ -209,6 +232,7 @@ func TestRaft_ParseConfig(t *testing.T) {
cfg.RetryJoin = "not-empty" cfg.RetryJoin = "not-empty"
cfg.RaftNonVoter = true // Any non-empty value is true cfg.RaftNonVoter = true // Any non-empty value is true
}, },
wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=retry_join_as_non_voter"),
}, },
{ {
name: "non-voter, no retry-join, valid env true", name: "non-voter, no retry-join, valid env true",
@@ -229,6 +253,7 @@ func TestRaft_ParseConfig(t *testing.T) {
cfg.RetryJoin = "not-empty" cfg.RetryJoin = "not-empty"
cfg.RaftNonVoter = true cfg.RaftNonVoter = true
}, },
wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=retry_join_as_non_voter"),
}, },
{ {
name: "non-voter, no retry-join, valid env not-boolean", name: "non-voter, no retry-join, valid env not-boolean",
@@ -249,6 +274,7 @@ func TestRaft_ParseConfig(t *testing.T) {
cfg.RetryJoin = "not-empty" cfg.RetryJoin = "not-empty"
cfg.RaftNonVoter = true cfg.RaftNonVoter = true
}, },
wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=retry_join_as_non_voter"),
}, },
{ {
name: "non-voter, no retry-join, valid env empty", name: "non-voter, no retry-join, valid env empty",
@@ -294,6 +320,7 @@ func TestRaft_ParseConfig(t *testing.T) {
cfg.RetryJoin = "not-empty" cfg.RetryJoin = "not-empty"
cfg.RaftNonVoter = true // Env should win cfg.RaftNonVoter = true // Env should win
}, },
wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=retry_join_as_non_voter"),
}, },
// Entry Size Limits ----------------------------------------------------- // Entry Size Limits -----------------------------------------------------
@@ -307,6 +334,7 @@ func TestRaft_ParseConfig(t *testing.T) {
cfg.MaxEntrySize = 123456 cfg.MaxEntrySize = 123456
cfg.MaxMountAndNamespaceTableEntrySize = 654321 cfg.MaxMountAndNamespaceTableEntrySize = 654321
}, },
wantWarns: ceOnlyWarnings("configuration for a Vault Enterprise feature has been ignored: field=max_mount_and_namespace_table_entry_size"),
}, },
{ {
name: "entry size, junk entry size", name: "entry size, junk entry size",
@@ -394,6 +422,9 @@ func TestRaft_ParseConfig(t *testing.T) {
for _, warn := range tc.wantWarns { for _, warn := range tc.wantWarns {
require.Contains(t, allLogs, warn) require.Contains(t, allLogs, warn)
} }
if len(tc.wantWarns) == 0 {
require.NotContains(t, allLogs, "[WARN]", "no warnings expected")
}
}) })
} }
} }

View File

@@ -14,5 +14,5 @@ func (b *RaftBackend) entrySizeLimitForPath(path string) uint64 {
} }
func emitEntWarning(logger hclog.Logger, field string) { func emitEntWarning(logger hclog.Logger, field string) {
logger.Warn("%s is configuration for a Vault Enterprise feature and has been ignored.", field) logger.Warn("configuration for a Vault Enterprise feature has been ignored", "field", field)
} }