A platform for community discussion. Free, open, simple.
DEV: Move webhook event header modifier for redelivery-recalucation (#27177)
Mark VanLandingham971b66e44093
diff --git a/app/jobs/regular/emit_web_hook_event.rb b/app/jobs/regular/emit_web_hook_event.rbindex 95522950c09..74c097cff79 100644--- a/app/jobs/regular/emit_web_hook_event.rb+++ b/app/jobs/regular/emit_web_hook_event.rb@@ -47,13 +47,6 @@ module Jobsuri = URI(@web_hook.payload_url.strip)web_hook_headers = build_webhook_headers(uri, web_hook_body, web_hook_event)- web_hook_headers =- DiscoursePluginRegistry.apply_modifier(- :web_hook_event_headers,- web_hook_headers,- web_hook_body,- web_hook_event,- )emitter = WebHookEmitter.new(@web_hook, web_hook_event)web_hook_response = emitter.emit!(headers: web_hook_headers, body: web_hook_body)diff --git a/app/services/web_hook_emitter.rb b/app/services/web_hook_emitter.rbindex 738026e48d5..dc03da8db77 100644--- a/app/services/web_hook_emitter.rb+++ b/app/services/web_hook_emitter.rb@@ -19,6 +19,9 @@ class WebHookEmitter},}+ headers =+ DiscoursePluginRegistry.apply_modifier(:web_hook_event_headers, headers, body, @webhook_event)+connection_opts[:ssl] = { verify: false } if [email protected]_certificateconn = Faraday.new(nil, connection_opts) { |f| f.adapter FinalDestination::FaradayAdapter }diff --git a/spec/requests/admin/web_hooks_controller_spec.rb b/spec/requests/admin/web_hooks_controller_spec.rbindex ca75bd0572b..b5e3de66975 100644--- a/spec/requests/admin/web_hooks_controller_spec.rb+++ b/spec/requests/admin/web_hooks_controller_spec.rb@@ -289,5 +289,37 @@ RSpec.describe Admin::WebHooksController doexpect(parsed_event["status"]).to eq(-1)expect(parsed_event["response_body"]).to eq(nil)end++ context "with web_hook_event_headers_for_redelivery modifier registered" do+ let(:modifier_block) do+ Proc.new do |headers, _, _|+ headers["bb"] = "22"+ headers+ end+ end+ it "modifies the headers & saves the updated headers to the webhook event" do+ plugin_instance = Plugin::Instance.new+ plugin_instance.register_modifier(:web_hook_event_headers, &modifier_block)++ stub_request(:post, web_hook.payload_url).to_return(+ status: 402,+ body: "efg",+ headers: {+ "Content-Type" => "application/json",+ "yoo" => "man",+ },+ )+ post "/admin/api/web_hooks/#{web_hook.id}/events/#{web_hook_event.id}/redeliver.json"+ expect(response.status).to eq(200)++ expect(JSON.parse(web_hook_event.reload.headers)).to eq({ "aa" => "1", "bb" => "22" })+ ensure+ DiscoursePluginRegistry.unregister_modifier(+ plugin_instance,+ :web_hook_event_headers,+ &modifier_block+ )+ end+ endendend