mirror of https://github.com/hashicorp/consul
Merge pull request #2635 from hashicorp/kv-put-crash
cli: Fix panic on empty data argument to `kv put`pull/2613/head^2
commit
66f3a0f1c3
|
@ -236,6 +236,11 @@ func (c *KVPutCommand) dataFromArgs(args []string) (string, string, error) {
|
|||
key := args[0]
|
||||
data := args[1]
|
||||
|
||||
// Handle empty quoted shell parameters
|
||||
if len(data) == 0 {
|
||||
return key, "", nil
|
||||
}
|
||||
|
||||
switch data[0] {
|
||||
case '@':
|
||||
data, err := ioutil.ReadFile(data[1:])
|
||||
|
|
|
@ -101,6 +101,34 @@ func TestKVPutCommand_Run(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestKVPutCommand_RunEmptyDataQuoted(t *testing.T) {
|
||||
srv, client := testAgentWithAPIClient(t)
|
||||
defer srv.Shutdown()
|
||||
waitForLeader(t, srv.httpAddr)
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
c := &KVPutCommand{Ui: ui}
|
||||
|
||||
args := []string{
|
||||
"-http-addr=" + srv.httpAddr,
|
||||
"foo", "",
|
||||
}
|
||||
|
||||
code := c.Run(args)
|
||||
if code != 0 {
|
||||
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
data, _, err := client.KV().Get("foo", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if data.Value != nil {
|
||||
t.Errorf("bad: %#v", data.Value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKVPutCommand_RunBase64(t *testing.T) {
|
||||
srv, client := testAgentWithAPIClient(t)
|
||||
defer srv.Shutdown()
|
||||
|
|
Loading…
Reference in New Issue