Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Always use the type when verifying storage and seals. We'll also update
an older test that didn't use real storage types during migration to use
real storage types.

Signed-off-by: Ryan Cragun <[email protected]>
  • Loading branch information
ryancragun committed Dec 18, 2024
1 parent fdb05f9 commit 477e93b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
25 changes: 13 additions & 12 deletions command/operator_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

"github.com/go-test/deep"

log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-secure-stdlib/base62"
"github.com/hashicorp/vault/command/server"
Expand Down Expand Up @@ -190,23 +191,23 @@ func TestMigration(t *testing.T) {
cmd := new(OperatorMigrateCommand)
cfgName := filepath.Join(t.TempDir(), "migrator")
os.WriteFile(cfgName, []byte(`
storage_source "src_type" {
storage_source "consul" {
path = "src_path"
}
storage_destination "dest_type" {
storage_destination "raft" {
path = "dest_path"
}`), 0o644)

expCfg := &migratorConfig{
StorageSource: &server.Storage{
Type: "src_type",
Type: "consul",
Config: map[string]string{
"path": "src_path",
},
},
StorageDestination: &server.Storage{
Type: "dest_type",
Type: "raft",
Config: map[string]string{
"path": "dest_path",
},
Expand All @@ -230,41 +231,41 @@ storage_destination "dest_type" {

// missing source
verifyBad(`
storage_destination "dest_type" {
storage_destination "raft" {
path = "dest_path"
}`)

// missing destination
verifyBad(`
storage_source "src_type" {
storage_source "consul" {
path = "src_path"
}`)

// duplicate source
verifyBad(`
storage_source "src_type" {
storage_source "consul" {
path = "src_path"
}
storage_source "src_type2" {
storage_source "raft" {
path = "src_path"
}
storage_destination "dest_type" {
storage_destination "raft" {
path = "dest_path"
}`)

// duplicate destination
verifyBad(`
storage_source "src_type" {
storage_source "consul" {
path = "src_path"
}
storage_destination "dest_type" {
storage_destination "raft" {
path = "dest_path"
}
storage_destination "dest_type2" {
storage_destination "consul" {
path = "dest_path"
}`)
})
Expand Down
50 changes: 27 additions & 23 deletions command/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,29 +1022,33 @@ func ParseStorage(result *Config, list *ast.ObjectList, name string) error {
// config. Physical storage types which don't contain such keys should include
// an empty array.
var storageAddressKeys = map[string][]string{
"aerospike": {"hostname"},
"alicloudoss": {"endpoint"},
"azure": {"arm_endpoint"},
"cassandra": {"hosts"},
"cockroachdb": {"connection_url"},
"consul": {"address", "service_address"},
"couchdb": {"endpoint"},
"dynamodb": {"endpoint"},
"etcd": {"address", "discovery_srv"},
"filesystem": {},
"foundationdb": {},
"gcs": {},
"inmem": {},
"manta": {"url"},
"mssql": {"server"},
"mysql": {"address"},
"oci": {},
"postgresql": {"connection_url"},
"raft": {}, // retry_join is handled separately in normalizeRaftRetryJoin()
"s3": {"endpoint"},
"spanner": {},
"swift": {"auth_url", "storage_url"},
"zookeeper": {"address"},
"aerospike": {"hostname"},
"alicloudoss": {"endpoint"},
"azure": {"arm_endpoint"},
"cassandra": {"hosts"},
"cockroachdb": {"connection_url"},
"consul": {"address", "service_address"},
"couchdb": {"endpoint"},
"dynamodb": {"endpoint"},
"etcd": {"address", "discovery_srv"},
"file": {},
"filesystem": {},
"foundationdb": {},
"gcs": {},
"inmem": {},
"inmem_ha": {},
"inmem_transactional": {},
"inmem_transactional_ha": {},
"manta": {"url"},
"mssql": {"server"},
"mysql": {"address"},
"oci": {},
"postgresql": {"connection_url"},
"raft": {}, // retry_join is handled separately in normalizeRaftRetryJoin()
"s3": {"endpoint"},
"spanner": {},
"swift": {"auth_url", "storage_url"},
"zookeeper": {"address"},
}

// normalizeStorageConfigAddresses takes a storage name, a configuration key
Expand Down
3 changes: 1 addition & 2 deletions internalshared/configutil/kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func parseKMS(result *[]*KMS, list *ast.ObjectList, blockName string, maxKMS int
if err != nil {
return multierror.Prefix(err, fmt.Sprintf("%s.%s:", blockName, key))
}
strMap[k], err = normalizeKMSSealConfigAddrs(name, k, s)
strMap[k], err = normalizeKMSSealConfigAddrs(key, k, s)
if err != nil {
return multierror.Prefix(err, fmt.Sprintf("%s.%s:", blockName, key))
}
Expand Down Expand Up @@ -231,7 +231,6 @@ var kmsSealAddressKeys = map[string][]string{
wrapping.WrapperTypeOciKms.String(): {"key_id", "crypto_endpoint", "management_endpoint"},
wrapping.WrapperTypePkcs11.String(): {},
wrapping.WrapperTypeTransit.String(): {"address"},
"pkcs11-disabled": {}, // only used in tests
}

// normalizeKMSSealConfigAddrs takes a kms seal type, a config key, and its
Expand Down

0 comments on commit 477e93b

Please sign in to comment.