A platform for community discussion. Free, open, simple.
DEV: Add web_hook_event_ssl_opts modifier (#44380)
Chris Alberti2440149c03be
diff --git a/app/services/web_hook_emitter.rb b/app/services/web_hook_emitter.rbindex dc03da8db77..4fd52e1e0f7 100644--- a/app/services/web_hook_emitter.rb+++ b/app/services/web_hook_emitter.rb@@ -22,7 +22,11 @@ class WebHookEmitterheaders =DiscoursePluginRegistry.apply_modifier(:web_hook_event_headers, headers, body, @webhook_event)- connection_opts[:ssl] = { verify: false } if [email protected]_certificate+ ssl_opts = {}+ ssl_opts[:verify] = false if [email protected]_certificate+ ssl_opts =+ DiscoursePluginRegistry.apply_modifier(:web_hook_event_ssl_opts, ssl_opts, @webhook_event)+ connection_opts[:ssl] = ssl_opts if ssl_opts.present?conn = Faraday.new(nil, connection_opts) { |f| f.adapter FinalDestination::FaradayAdapter }diff --git a/spec/jobs/emit_web_hook_event_spec.rb b/spec/jobs/emit_web_hook_event_spec.rbindex 4cbe5f29e97..a0814777199 100644--- a/spec/jobs/emit_web_hook_event_spec.rb+++ b/spec/jobs/emit_web_hook_event_spec.rb@@ -376,5 +376,44 @@ RSpec.describe Jobs::EmitWebHookEvent do)endend++ context "with `web_hook_event_ssl_opts` modifier" do+ let(:modifier_block) do+ Proc.new do |ssl_opts, _|+ ssl_opts[:client_cert] = "my cert"+ ssl_opts+ end+ end++ it "passes additional ssl options to the connection" do+ plugin_instance = Plugin::Instance.new+ plugin_instance.register_modifier(:web_hook_event_ssl_opts, &modifier_block)++ captured_opts = nil+ allow(Faraday).to receive(:new).and_wrap_original do |m, *args, &block|+ captured_opts = args[1] # connection_opts+ m.call(*args, &block)+ end++ stub_request(:post, post_hook.payload_url).to_return(body: "OK", status: 200)++ topic_event_type = WebHookEventType.all.first+ web_hook_id = Fabricate("#{topic_event_type.name.gsub("_created", "")}_web_hook").id++ job.execute(+ web_hook_id: web_hook_id,+ event_type: topic_event_type.name,+ payload: { test: "some payload" }.to_json,+ )++ expect(captured_opts[:ssl]).to include(client_cert: "my cert")+ ensure+ DiscoursePluginRegistry.unregister_modifier(+ plugin_instance,+ :web_hook_event_ssl_opts,+ &modifier_block+ )+ end+ endendend