From 4027bd7052446434ae0d7ecc8a0bb9740acc11bc Mon Sep 17 00:00:00 2001 From: Thijs de Jong Date: Fri, 15 Jan 2021 09:17:32 +0100 Subject: [PATCH 1/3] Fix panic --- pkg/execute/executor.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/execute/executor.go b/pkg/execute/executor.go index ddcc8611c..8cebd8734 100644 --- a/pkg/execute/executor.go +++ b/pkg/execute/executor.go @@ -190,9 +190,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) { From 8eb5cbba7d6699aab9bf0744b027ea50f06d1ba8 Mon Sep 17 00:00:00 2001 From: Thijs de Jong Date: Mon, 18 Jan 2021 09:42:58 +0100 Subject: [PATCH 2/3] Add test --- test/e2e/command/kubectl.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/e2e/command/kubectl.go b/test/e2e/command/kubectl.go index c074b54b9..c8b46f6ed 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: "```Command not supported. Please run /botkubehelp to see supported commands.```", channel: c.Config.Communications.Slack.Channel, }, + "kubectl command without a resource": { + command: "get", + expected: "```Command not supported. Please run /botkubehelp to see supported commands.```", + channel: c.Config.Communications.Slack.Channel, + }, } for name, test := range tests { From b5b5517d29322baadb436ed9a238298e7fa3c611 Mon Sep 17 00:00:00 2001 From: Prasad Ghangal Date: Wed, 21 Jul 2021 10:50:12 +0530 Subject: [PATCH 3/3] Update test/e2e/command/kubectl.go --- test/e2e/command/kubectl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/command/kubectl.go b/test/e2e/command/kubectl.go index e5c5bf1de..70b8ec1ab 100644 --- a/test/e2e/command/kubectl.go +++ b/test/e2e/command/kubectl.go @@ -66,7 +66,7 @@ func (c *context) testKubectlCommand(t *testing.T) { }, "kubectl command without a resource": { command: "get", - expected: "```Command not supported. Please run /botkubehelp to see supported commands.```", + expected: "```\nCommand not supported. Please run /botkubehelp to see supported commands.\n```", channel: c.Config.Communications.Slack.Channel, }, }