From 983a56e3bd27e027944e3ce7c2af0752f0cfbf90 Mon Sep 17 00:00:00 2001 From: Wolftallemo <72576136+Wolftallemo@users.noreply.github.com> Date: Thu, 15 Dec 2022 16:21:07 -0500 Subject: [PATCH] FIX: FIX: Correctly parse Mandrill webhooks (#17116) Mandrill sends webhook messages as a URL-encoded body, with the mandrill_events property as an encoded JSON array. --- app/controllers/webhooks_controller.rb | 2 +- spec/requests/webhooks_controller_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/webhooks_controller.rb b/app/controllers/webhooks_controller.rb index 7271ac5f6b8..74024b31524 100644 --- a/app/controllers/webhooks_controller.rb +++ b/app/controllers/webhooks_controller.rb @@ -49,7 +49,7 @@ class WebhooksController < ActionController::Base end def mandrill - events = params["mandrill_events"] + events = JSON.parse(params["mandrill_events"]) events.each do |event| message_id = event.dig("msg", "metadata", "message_id") to_address = event.dig("msg", "email") diff --git a/spec/requests/webhooks_controller_spec.rb b/spec/requests/webhooks_controller_spec.rb index 070c8039924..53b5f062565 100644 --- a/spec/requests/webhooks_controller_spec.rb +++ b/spec/requests/webhooks_controller_spec.rb @@ -142,7 +142,7 @@ RSpec.describe WebhooksController do "message_id" => message_id } } - }] + }].to_json } expect(response.status).to eq(200)