A platform for community discussion. Free, open, simple.
FIX: correctly checks for chat enabled in incoming webhooks controller (#20730)
Joffrey JAFFEUX25d06faa8b14
diff --git a/plugins/chat/app/controllers/chat/incoming_webhooks_controller.rb b/plugins/chat/app/controllers/chat/incoming_webhooks_controller.rbindex a9f57bc7062..3e3485aa588 100644--- a/plugins/chat/app/controllers/chat/incoming_webhooks_controller.rb+++ b/plugins/chat/app/controllers/chat/incoming_webhooks_controller.rb@@ -2,6 +2,8 @@module Chatclass IncomingWebhooksController < ::ApplicationController+ requires_plugin Chat::PLUGIN_NAME+WEBHOOK_MESSAGES_PER_MINUTE_LIMIT = 10skip_before_action :verify_authenticity_token, :redirect_to_login_if_requireddiff --git a/plugins/chat/spec/requests/incoming_chat_webhooks_controller_spec.rb b/plugins/chat/spec/requests/chat/incoming_webhooks_controller_spec.rbsimilarity index 86%rename from plugins/chat/spec/requests/incoming_chat_webhooks_controller_spec.rbrename to plugins/chat/spec/requests/chat/incoming_webhooks_controller_spec.rbindex a970084a8ab..b011abfdae1 100644--- a/plugins/chat/spec/requests/incoming_chat_webhooks_controller_spec.rb+++ b/plugins/chat/spec/requests/chat/incoming_webhooks_controller_spec.rb@@ -8,7 +8,18 @@ RSpec.describe Chat::IncomingWebhooksController dobefore { SiteSetting.chat_debug_webhook_payloads = true }+ let(:valid_payload) { { text: "A new signup woo!" } }+describe "#create_message" do+ context "with chat disabled" do+ before { SiteSetting.chat_enabled = false }++ it "returns a 404" do+ post "/chat/hooks/#{webhook.key}.json", params: valid_payload+ expect(response.status).to eq(404)+ end+ end+it "errors with invalid key" dopost "/chat/hooks/null.json"expect(response.status).to eq(400)@@ -28,9 +39,9 @@ RSpec.describe Chat::IncomingWebhooksController doendit "creates a new chat message" do- expect {- post "/chat/hooks/#{webhook.key}.json", params: { text: "A new signup woo!" }- }.to change { Chat::Message.where(chat_channel: chat_channel).count }.by(1)+ expect { post "/chat/hooks/#{webhook.key}.json", params: valid_payload }.to change {+ Chat::Message.where(chat_channel: chat_channel).count+ }.by(1)expect(response.status).to eq(200)chat_webhook_event = Chat::WebhookEvent.lastexpect(chat_webhook_event.chat_message_id).to eq(Chat::Message.last.id)@@ -62,15 +73,24 @@ RSpec.describe Chat::IncomingWebhooksController doit "rate limits" doRateLimiter.enableRateLimiter.clear_all!- 10.times { post "/chat/hooks/#{webhook.key}.json", params: { text: "A new signup woo!" } }+ 10.times { post "/chat/hooks/#{webhook.key}.json", params: valid_payload }expect(response.status).to eq(200)- post "/chat/hooks/#{webhook.key}.json", params: { text: "A new signup woo!" }+ post "/chat/hooks/#{webhook.key}.json", params: valid_payloadexpect(response.status).to eq(429)endenddescribe "#create_message_slack_compatible" do+ context "with chat disabled" do+ before { SiteSetting.chat_enabled = false }++ it "returns a 404" do+ post "/chat/hooks/#{webhook.key}/slack.json", params: valid_payload+ expect(response.status).to eq(404)+ end+ end+it "processes the text param with SlackCompatibility" doexpect {post "/chat/hooks/#{webhook.key}/slack.json", params: { text: "A new signup woo <!here>!" }