From 3f803cb75c70a7089bda2dd170d28010e75cedd3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 13 Jul 2014 10:29:31 -0700 Subject: [PATCH] command/output: protect againts blank params --- command/output.go | 2 +- command/output_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/command/output.go b/command/output.go index 7e5ec1776..6c9d94b8e 100644 --- a/command/output.go +++ b/command/output.go @@ -28,7 +28,7 @@ func (c *OutputCommand) Run(args []string) int { } args = cmdFlags.Args() - if len(args) != 1 { + if len(args) != 1 || args[0] == "" { c.Ui.Error( "The output command expects exactly one argument with the name\n" + "of an output variable.\n") diff --git a/command/output_test.go b/command/output_test.go index 3c4a29e20..f177198c5 100644 --- a/command/output_test.go +++ b/command/output_test.go @@ -68,6 +68,32 @@ func TestOutput_badVar(t *testing.T) { } } +func TestOutput_blank(t *testing.T) { + originalState := &terraform.State{ + Outputs: map[string]string{ + "foo": "bar", + }, + } + + statePath := testStateFile(t, originalState) + + ui := new(cli.MockUi) + c := &OutputCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(testProvider()), + Ui: ui, + }, + } + + args := []string{ + "-state", statePath, + "", + } + if code := c.Run(args); code != 1 { + t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) + } +} + func TestOutput_manyArgs(t *testing.T) { ui := new(cli.MockUi) c := &OutputCommand{