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

cmd: validate the type flag when querying plugin status. #10712

Merged
merged 1 commit into from
Jun 7, 2021
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
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