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

Fix panic when running command without resource #447

Merged
merged 9 commits into from
Jul 21, 2021
6 changes: 3 additions & 3 deletions pkg/execute/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/command/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down