Co-authored-by: James Rasell <jrasell@users.noreply.github.com>
This commit is contained in:
parent
a532f3c321
commit
c96ca6f81c
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/hashicorp/nomad/helper/pointer"
|
"github.com/hashicorp/nomad/helper/pointer"
|
||||||
"github.com/hashicorp/nomad/helper/testlog"
|
"github.com/hashicorp/nomad/helper/testlog"
|
||||||
"github.com/hashicorp/nomad/helper/useragent"
|
"github.com/hashicorp/nomad/helper/useragent"
|
||||||
|
"github.com/hashicorp/nomad/nomad/structs"
|
||||||
"github.com/hashicorp/nomad/testutil"
|
"github.com/hashicorp/nomad/testutil"
|
||||||
vaultapi "github.com/hashicorp/vault/api"
|
vaultapi "github.com/hashicorp/vault/api"
|
||||||
"github.com/shoenig/test/must"
|
"github.com/shoenig/test/must"
|
||||||
|
@ -20,8 +21,6 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
const vaultNamespaceHeaderName = "X-Vault-Namespace"
|
|
||||||
|
|
||||||
func TestVaultClient_TokenRenewals(t *testing.T) {
|
func TestVaultClient_TokenRenewals(t *testing.T) {
|
||||||
ci.Parallel(t)
|
ci.Parallel(t)
|
||||||
|
|
||||||
|
@ -126,7 +125,7 @@ func TestVaultClient_NamespaceSupport(t *testing.T) {
|
||||||
conf.VaultConfig.Namespace = testNs
|
conf.VaultConfig.Namespace = testNs
|
||||||
c, err := NewVaultClient(conf.VaultConfig, logger, nil)
|
c, err := NewVaultClient(conf.VaultConfig, logger, nil)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
require.Equal(testNs, c.client.Headers().Get(vaultNamespaceHeaderName))
|
require.Equal(testNs, c.client.Headers().Get(structs.VaultNamespaceHeaderName))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVaultClient_Heap(t *testing.T) {
|
func TestVaultClient_Heap(t *testing.T) {
|
||||||
|
|
|
@ -11,6 +11,13 @@ import (
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// VaultNamespaceHeaderName is the header set to specify which namespace
|
||||||
|
// the request is indented for. This is defined within Nomad, so we do not
|
||||||
|
// need to import the entire Vault SDK package.
|
||||||
|
VaultNamespaceHeaderName = "X-Vault-Namespace"
|
||||||
|
)
|
||||||
|
|
||||||
// VaultTokenData represents some of the fields returned in the Data map of the
|
// VaultTokenData represents some of the fields returned in the Data map of the
|
||||||
// sercret returned by the Vault API when doing a token lookup request.
|
// sercret returned by the Vault API when doing a token lookup request.
|
||||||
type VaultTokenData struct {
|
type VaultTokenData struct {
|
||||||
|
|
|
@ -71,8 +71,6 @@ path "secret/*" {
|
||||||
capabilities = ["create", "read", "update", "delete", "list"]
|
capabilities = ["create", "read", "update", "delete", "list"]
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
vaultNamespaceHeaderName = "X-Vault-Namespace"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// defaultTestVaultAllowlistRoleAndToken creates a test Vault role and returns a token
|
// defaultTestVaultAllowlistRoleAndToken creates a test Vault role and returns a token
|
||||||
|
@ -202,8 +200,8 @@ func TestVaultClient_WithNamespaceSupport(t *testing.T) {
|
||||||
t.Fatalf("failed to build vault client: %v", err)
|
t.Fatalf("failed to build vault client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equal(testNs, c.client.Headers().Get(vaultNamespaceHeaderName))
|
require.Equal(testNs, c.client.Headers().Get(structs.VaultNamespaceHeaderName))
|
||||||
require.Equal("", c.clientSys.Headers().Get(vaultNamespaceHeaderName))
|
require.Equal("", c.clientSys.Headers().Get(structs.VaultNamespaceHeaderName))
|
||||||
require.NotEqual(c.clientSys, c.client)
|
require.NotEqual(c.clientSys, c.client)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,8 +225,8 @@ func TestVaultClient_WithoutNamespaceSupport(t *testing.T) {
|
||||||
t.Fatalf("failed to build vault client: %v", err)
|
t.Fatalf("failed to build vault client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equal("", c.client.Headers().Get(vaultNamespaceHeaderName))
|
require.Equal("", c.client.Headers().Get(structs.VaultNamespaceHeaderName))
|
||||||
require.Equal("", c.clientSys.Headers().Get(vaultNamespaceHeaderName))
|
require.Equal("", c.clientSys.Headers().Get(structs.VaultNamespaceHeaderName))
|
||||||
require.Equal(c.clientSys, c.client)
|
require.Equal(c.clientSys, c.client)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue