mirror of https://github.com/status-im/consul.git
fix a panic in the CLI when deleting an acl policy with an unknown name (#19679)
* fix a panic in the CLI when deleting an acl policy with an unknown name * add changelog
This commit is contained in:
parent
415491ff2b
commit
f027d61014
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
CLI: fix a panic when deleting a non existing policy by name.
|
||||
```
|
|
@ -105,6 +105,10 @@ func GetPolicyIDByName(client *api.Client, name string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
if policy == nil {
|
||||
return "", fmt.Errorf("No such policy with name: %s", name)
|
||||
}
|
||||
|
||||
return policy.ID, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,36 @@ func Test_GetPolicyIDByName_Builtins(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_GetPolicyIDByName_NotFound(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
a := agent.StartTestAgent(t,
|
||||
agent.TestAgent{
|
||||
LogOutput: io.Discard,
|
||||
HCL: `
|
||||
primary_datacenter = "dc1"
|
||||
acl {
|
||||
enabled = true
|
||||
tokens {
|
||||
initial_management = "root"
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
)
|
||||
|
||||
defer a.Shutdown()
|
||||
testrpc.WaitForTestAgent(t, a.RPC, "dc1", testrpc.WithToken("root"))
|
||||
|
||||
client := a.Client()
|
||||
client.AddHeader("X-Consul-Token", "root")
|
||||
|
||||
id, err := GetPolicyIDByName(client, "not_found")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, "", id)
|
||||
|
||||
}
|
||||
|
||||
func Test_GetPolicyIDFromPartial_Builtins(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
Loading…
Reference in New Issue