Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Vault Client panic when given nonexistant role #2648

Merged
merged 1 commit into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nomad/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,9 @@ func (v *vaultClient) validateRole(role string) error {
if err != nil {
return fmt.Errorf("failed to lookup role %q: %v", role, err)
}
if rsecret == nil {
return fmt.Errorf("Role %q does not exist", role)
}

// Read and parse the fields
var data struct {
Expand Down
39 changes: 39 additions & 0 deletions nomad/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,45 @@ func TestVaultClient_ValidateRole(t *testing.T) {
}
}

func TestVaultClient_ValidateRole_NonExistant(t *testing.T) {
v := testutil.NewTestVault(t).Start()
defer v.Stop()

v.Config.Token = defaultTestVaultWhitelistRoleAndToken(v, t, 5)
v.Config.Token = v.RootToken
logger := log.New(os.Stderr, "", log.LstdFlags)
v.Config.ConnectionRetryIntv = 100 * time.Millisecond
v.Config.Role = "test-nonexistant"
client, err := NewVaultClient(v.Config, logger, nil)
if err != nil {
t.Fatalf("failed to build vault client: %v", err)
}
defer client.Stop()

// Wait for an error
var conn bool
var connErr error
testutil.WaitForResult(func() (bool, error) {
conn, connErr = client.ConnectionEstablished()
if conn {
return false, fmt.Errorf("Should not connect")
}

if connErr == nil {
return false, fmt.Errorf("expect an error")
}

return true, nil
}, func(err error) {
t.Fatalf("bad: %v", err)
})

errStr := connErr.Error()
if !strings.Contains(errStr, "does not exist") {
t.Fatalf("Expect orphan error")
}
}

func TestVaultClient_ValidateToken(t *testing.T) {
v := testutil.NewTestVault(t).Start()
defer v.Stop()
Expand Down