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

cli: Fix panic on empty data argument to kv put #2635

Merged
merged 1 commit into from
Jan 5, 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
5 changes: 5 additions & 0 deletions command/kv_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:])
Expand Down
28 changes: 28 additions & 0 deletions command/kv_put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down