Skip to content

A platform for community discussion. Free, open, simple.

FIX: Broken ping event for web hooks due to missing payload.

Guo Xiang Tan43f7cb05c97b
diff --git a/app/jobs/regular/emit_web_hook_event.rb b/app/jobs/regular/emit_web_hook_event.rb
index 4a968513670..db90dd04019 100644
--- a/app/jobs/regular/emit_web_hook_event.rb
+++ b/app/jobs/regular/emit_web_hook_event.rb
@@ -8,7 +8,6 @@ module Jobs
%i{
web_hook_id
event_type
- payload
}.each do |key|
raise Discourse::InvalidParameters.new(key) unless args[key].present?
end
@@ -25,6 +24,7 @@ module Jobs
return if web_hook.category_ids.present? && (!args[:category_id].present? ||
!web_hook.category_ids.include?(args[:category_id]))
+ raise Discourse::InvalidParameters.new(:payload) unless args[:payload].present?
args[:payload] = JSON.parse(args[:payload])
end
diff --git a/spec/jobs/emit_web_hook_event_spec.rb b/spec/jobs/emit_web_hook_event_spec.rb
index 7354d78b94b..97a86f66838 100644
--- a/spec/jobs/emit_web_hook_event_spec.rb
+++ b/spec/jobs/emit_web_hook_event_spec.rb
@@ -24,6 +24,16 @@ describe Jobs::EmitWebHookEvent do
end.to raise_error(Discourse::InvalidParameters)
end
+ it 'does not raise an error for a ping event without payload' do
+ stub_request(:post, "https://meta.discourse.org/webhook_listener")
+ .to_return(body: 'OK', status: 200)
+
+ subject.execute(
+ web_hook_id: post_hook.id,
+ event_type: described_class::PING_EVENT
+ )
+ end
+
it "doesn't emit when the hook is inactive" do
subject.execute(
web_hook_id: inactive_hook.id,
@@ -99,7 +109,7 @@ describe Jobs::EmitWebHookEvent do
web_hook_id: post_hook.id,
event_type: described_class::PING_EVENT,
event_name: described_class::PING_EVENT,
- payload: { test: "some payload" }.to_json
+ payload: { test: "this payload shouldn't appear" }.to_json
)
event = WebHookEvent.last