mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-05 20:36:26 +02:00
Fix panic when running capabilities CLI command with multiple paths (#4553)
* Fix panic using 'vault token capabilities' with more than one path Fixes #4552 * Add test
This commit is contained in:
parent
e80234b4a7
commit
cb54688f59
@ -34,8 +34,14 @@ func (c *Sys) Capabilities(token, path string) ([]string, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result["capabilities"] == nil {
|
||||
return nil, nil
|
||||
}
|
||||
var capabilities []string
|
||||
capabilitiesRaw := result["capabilities"].([]interface{})
|
||||
capabilitiesRaw, ok := result["capabilities"].([]interface{})
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("error interpreting returned capabilities")
|
||||
}
|
||||
for _, capability := range capabilitiesRaw {
|
||||
capabilities = append(capabilities, capability.(string))
|
||||
}
|
||||
|
||||
@ -93,6 +93,10 @@ func (c *TokenCapabilitiesCommand) Run(args []string) int {
|
||||
c.UI.Error(fmt.Sprintf("Error listing capabilities: %s", err))
|
||||
return 2
|
||||
}
|
||||
if capabilities == nil {
|
||||
c.UI.Error(fmt.Sprintf("No capabilities found"))
|
||||
return 1
|
||||
}
|
||||
|
||||
switch Format(c.UI) {
|
||||
case "table":
|
||||
|
||||
@ -165,6 +165,23 @@ func TestTokenCapabilitiesCommand_Run(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("multiple_paths", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client, closer := testVaultServer(t)
|
||||
defer closer()
|
||||
|
||||
_, cmd := testTokenCapabilitiesCommand(t)
|
||||
cmd.client = client
|
||||
|
||||
code := cmd.Run([]string{
|
||||
"secret/foo,secret/bar",
|
||||
})
|
||||
if exp := 1; code != exp {
|
||||
t.Errorf("expected %d to be %d", code, exp)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("no_tabs", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user