This commit is contained in:
Alex Dadgar
2016-10-11 13:28:18 -07:00
parent 9ff2bf0bff
commit 7daa4706a6
6 changed files with 28 additions and 15 deletions

View File

@@ -36,9 +36,11 @@ func getPort() int {
}
func testServer(t *testing.T, cb func(*nomad.Config)) (*nomad.Server, string) {
f := false
// Setup the default settings
config := nomad.DefaultConfig()
config.VaultConfig.Enabled = false
config.VaultConfig.Enabled = &f
config.Build = "unittest"
config.DevMode = true
config.RPCAddr = &net.TCPAddr{
@@ -84,8 +86,10 @@ func testServer(t *testing.T, cb func(*nomad.Config)) (*nomad.Server, string) {
}
func testClient(t *testing.T, cb func(c *config.Config)) *Client {
f := false
conf := config.DefaultConfig()
conf.VaultConfig.Enabled = false
conf.VaultConfig.Enabled = &f
conf.DevMode = true
if cb != nil {
cb(conf)

View File

@@ -90,8 +90,9 @@ func TestVaultClient_TokenRenewals(t *testing.T) {
}
func TestVaultClient_Heap(t *testing.T) {
tr := true
conf := config.DefaultConfig()
conf.VaultConfig.Enabled = true
conf.VaultConfig.Enabled = &tr
conf.VaultConfig.Token = "testvaulttoken"
conf.VaultConfig.TaskTokenTTL = "10s"

View File

@@ -364,7 +364,8 @@ func TestJobEndpoint_Register_EnforceIndex(t *testing.T) {
func TestJobEndpoint_Register_Vault_Disabled(t *testing.T) {
s1 := testServer(t, func(c *Config) {
c.NumSchedulers = 0 // Prevent automatic dequeue
c.VaultConfig.Enabled = false
f := false
c.VaultConfig.Enabled = &f
})
defer s1.Shutdown()
codec := rpcClient(t, s1)
@@ -395,8 +396,9 @@ func TestJobEndpoint_Register_Vault_AllowUnauthenticated(t *testing.T) {
testutil.WaitForLeader(t, s1.RPC)
// Enable vault and allow authenticated
s1.config.VaultConfig.Enabled = true
s1.config.VaultConfig.AllowUnauthenticated = true
tr := true
s1.config.VaultConfig.Enabled = &tr
s1.config.VaultConfig.AllowUnauthenticated = &tr
// Replace the Vault Client on the server
s1.vault = &TestVaultClient{}
@@ -439,8 +441,9 @@ func TestJobEndpoint_Register_Vault_NoToken(t *testing.T) {
testutil.WaitForLeader(t, s1.RPC)
// Enable vault
s1.config.VaultConfig.Enabled = true
s1.config.VaultConfig.AllowUnauthenticated = false
tr, f := true, false
s1.config.VaultConfig.Enabled = &tr
s1.config.VaultConfig.AllowUnauthenticated = &f
// Replace the Vault Client on the server
s1.vault = &TestVaultClient{}
@@ -471,8 +474,9 @@ func TestJobEndpoint_Register_Vault_Policies(t *testing.T) {
testutil.WaitForLeader(t, s1.RPC)
// Enable vault
s1.config.VaultConfig.Enabled = true
s1.config.VaultConfig.AllowUnauthenticated = false
tr, f := true, false
s1.config.VaultConfig.Enabled = &tr
s1.config.VaultConfig.AllowUnauthenticated = &f
// Replace the Vault Client on the server
tvc := &TestVaultClient{}

View File

@@ -1869,8 +1869,9 @@ func TestClientEndpoint_DeriveVaultToken(t *testing.T) {
testutil.WaitForLeader(t, s1.RPC)
// Enable vault and allow authenticated
s1.config.VaultConfig.Enabled = true
s1.config.VaultConfig.AllowUnauthenticated = true
tr := true
s1.config.VaultConfig.Enabled = &tr
s1.config.VaultConfig.AllowUnauthenticated = &tr
// Replace the Vault Client on the server
tvc := &TestVaultClient{}

View File

@@ -58,7 +58,8 @@ func testServer(t *testing.T, cb func(*Config)) *Server {
config.RaftTimeout = 500 * time.Millisecond
// Disable Vault
config.VaultConfig.Enabled = false
f := false
config.VaultConfig.Enabled = &f
// Invoke the callback if any
if cb != nil {

View File

@@ -36,7 +36,8 @@ func TestVaultClient_BadConfig(t *testing.T) {
t.Fatalf("expected config error: %v", err)
}
conf.Enabled = true
tr := true
conf.Enabled = &tr
_, err = NewVaultClient(conf, logger, nil)
if err == nil || !strings.Contains(err.Error(), "token must be set") {
t.Fatalf("Expected token unset error: %v", err)
@@ -229,8 +230,9 @@ func parseTTLFromLookup(s *vapi.Secret, t *testing.T) int64 {
}
func TestVaultClient_LookupToken_Invalid(t *testing.T) {
tr := true
conf := &config.VaultConfig{
Enabled: true,
Enabled: &tr,
Addr: "http://foobar:12345",
Token: structs.GenerateUUID(),
}