diff --git a/pkg/execute/executor.go b/pkg/execute/executor.go index 5b9659666..1eb02eb29 100644 --- a/pkg/execute/executor.go +++ b/pkg/execute/executor.go @@ -192,9 +192,9 @@ func (e *DefaultExecutor) Execute() string { } if len(args) >= 1 && utils.AllowedKubectlVerbMap[args[0]] { if validDebugCommands[args[0]] || // Don't check for resource if is a valid debug command - utils.AllowedKubectlResourceMap[args[1]] || // Check if allowed resource - utils.AllowedKubectlResourceMap[utils.KindResourceMap[strings.ToLower(args[1])]] || // Check if matches with kind name - utils.AllowedKubectlResourceMap[utils.ShortnameResourceMap[strings.ToLower(args[1])]] { // Check if matches with short name + (len(args) >= 2 && (utils.AllowedKubectlResourceMap[args[1]] || // Check if allowed resource + utils.AllowedKubectlResourceMap[utils.KindResourceMap[strings.ToLower(args[1])]] || // Check if matches with kind name + utils.AllowedKubectlResourceMap[utils.ShortnameResourceMap[strings.ToLower(args[1])]])) { // Check if matches with short name isClusterNamePresent := strings.Contains(e.Message, "--cluster-name") if !e.AllowKubectl { if isClusterNamePresent && e.ClusterName == utils.GetClusterNameFromKubectlCmd(e.Message) { diff --git a/test/e2e/command/kubectl.go b/test/e2e/command/kubectl.go index c25ca9888..70b8ec1ab 100644 --- a/test/e2e/command/kubectl.go +++ b/test/e2e/command/kubectl.go @@ -64,6 +64,11 @@ func (c *context) testKubectlCommand(t *testing.T) { expected: "```\nCommand not supported. Please run /botkubehelp to see supported commands.\n```", channel: c.Config.Communications.Slack.Channel, }, + "kubectl command without a resource": { + command: "get", + expected: "```\nCommand not supported. Please run /botkubehelp to see supported commands.\n```", + channel: c.Config.Communications.Slack.Channel, + }, } for name, test := range tests {