From 4a1cfea32571981b8d15b68316cbcbc7ea693201 Mon Sep 17 00:00:00 2001 From: Donovan Brown Date: Wed, 28 Apr 2021 14:23:17 -0500 Subject: [PATCH] Fixed bug where default vaultaddr is never used. (#791) * Fixed bug where default vaultaddr is never used. * Fixing vault tests on Windows. Co-authored-by: Phil Kedy --- secretstores/hashicorp/vault/vault.go | 2 +- secretstores/hashicorp/vault/vault_test.go | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/secretstores/hashicorp/vault/vault.go b/secretstores/hashicorp/vault/vault.go index d57464871..2a1c8de1a 100644 --- a/secretstores/hashicorp/vault/vault.go +++ b/secretstores/hashicorp/vault/vault.go @@ -87,7 +87,7 @@ func (v *vaultSecretStore) Init(metadata secretstores.Metadata) error { // Get Vault address address := props[componentVaultAddress] if address == "" { - v.vaultAddress = defaultVaultAddress + address = defaultVaultAddress } v.vaultAddress = address diff --git a/secretstores/hashicorp/vault/vault_test.go b/secretstores/hashicorp/vault/vault_test.go index d60f68d7e..95189fdd5 100644 --- a/secretstores/hashicorp/vault/vault_test.go +++ b/secretstores/hashicorp/vault/vault_test.go @@ -84,6 +84,31 @@ func TestVaultTLSConfig(t *testing.T) { }) } +func TestDefaultVaultAddress(t *testing.T) { + t.Run("with blank vaultAddr", func(t *testing.T) { + properties := map[string]string{ + "vaultTokenMountPath": "./vault.txt", + } + + m := secretstores.Metadata{ + Properties: properties, + } + + target := &vaultSecretStore{ + client: nil, + logger: nil, + } + + // This call will throw an error on Windows systems because of the of + // the call x509.SystemCertPool() because system root pool is not + // available on Windows so ignore the error for when the tests are run + // on the Windows platform during CI + _ = target.Init(m) + + assert.Equal(t, defaultVaultAddress, target.vaultAddress, "default was not set") + }) +} + func getCertificate() []byte { certificateBytes, _ := base64.StdEncoding.DecodeString(certificate)