Skip to content

Commit

Permalink
Merge pull request #10712 from hashicorp/b-gh-10711
Browse files Browse the repository at this point in the history
cmd: validate the type flag when querying plugin status.
  • Loading branch information
jrasell committed Jun 7, 2021
2 parents a93da8b + 2d92e6f commit bb3a98e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 11 additions & 2 deletions command/plugin_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ func (c *PluginStatusCommand) Run(args []string) int {
return 1
}

typeArg = strings.ToLower(typeArg)

// Check that we either got no arguments or exactly one.
args = flags.Args()
if len(args) > 1 {
Expand All @@ -120,6 +118,17 @@ func (c *PluginStatusCommand) Run(args []string) int {
return 1
}

typeArg = strings.ToLower(typeArg)

// Check that the plugin type flag is supported. Empty implies we are
// querying all plugins, otherwise we currently only support "csi".
switch typeArg {
case "", "csi":
default:
c.Ui.Error(fmt.Sprintf("Unsupported plugin type: %s", typeArg))
return 1
}

// Truncate the id unless full length is requested
c.length = shortId
if c.verbose {
Expand Down
8 changes: 8 additions & 0 deletions command/plugin_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ func TestPluginStatusCommand_Fails(t *testing.T) {
out := ui.ErrorWriter.String()
require.Contains(t, out, commandErrorText(cmd))
ui.ErrorWriter.Reset()

// Test an unsupported plugin type.
code = cmd.Run([]string{"-type=not-a-plugin"})
require.Equal(t, 1, code)

out = ui.ErrorWriter.String()
require.Contains(t, out, "Unsupported plugin type: not-a-plugin")
ui.ErrorWriter.Reset()
}

func TestPluginStatusCommand_AutocompleteArgs(t *testing.T) {
Expand Down

0 comments on commit bb3a98e

Please sign in to comment.