From 0322f1bf4355d68433c72067be62db2427075390 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Tue, 26 Jun 2018 10:15:00 -0400 Subject: [PATCH] Validate operator init args (#4838) --- command/operator_init.go | 6 ++++++ command/operator_init_test.go | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/command/operator_init.go b/command/operator_init.go index 18a0d278e..0476e5cf9 100644 --- a/command/operator_init.go +++ b/command/operator_init.go @@ -259,6 +259,12 @@ func (c *OperatorInitCommand) Run(args []string) int { c.flagStatus = true } + args = f.Args() + if len(args) > 0 { + c.UI.Error(fmt.Sprintf("Too many arguments (expected 0, got %d)", len(args))) + return 1 + } + // Build the initial init request initReq := &api.InitRequest{ SecretShares: c.flagKeyShares, diff --git a/command/operator_init_test.go b/command/operator_init_test.go index 2698c1ae7..b90b5d65c 100644 --- a/command/operator_init_test.go +++ b/command/operator_init_test.go @@ -35,6 +35,12 @@ func TestOperatorInitCommand_Run(t *testing.T) { out string code int }{ + { + "too_many_args", + []string{"foo"}, + "Too many arguments", + 1, + }, { "pgp_keys_multi", []string{ @@ -341,7 +347,8 @@ func TestOperatorInitCommand_Run(t *testing.T) { cmd.client = client code := cmd.Run([]string{ - "secret/foo", + "-key-shares=1", + "-key-threshold=1", }) if exp := 2; code != exp { t.Errorf("expected %d to be %d", code, exp)