mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
use proper 'Message-Id' field
This commit is contained in:
parent
9a81115c1c
commit
214e25f1b5
2 changed files with 7 additions and 8 deletions
|
@ -7,7 +7,7 @@ class WebhooksController < ActionController::Base
|
|||
return mailgun_failure if SiteSetting.mailgun_api_key.blank?
|
||||
|
||||
# token is a random string of 50 characters
|
||||
token = params.delete("token")
|
||||
token = params["token"]
|
||||
return mailgun_failure if token.blank? || token.size != 50
|
||||
|
||||
# prevent replay attack
|
||||
|
@ -16,14 +16,14 @@ class WebhooksController < ActionController::Base
|
|||
$redis.expire(key, 10.minutes)
|
||||
|
||||
# ensure timestamp isn't too far from current time
|
||||
timestamp = params.delete("timestamp")
|
||||
timestamp = params["timestamp"]
|
||||
return mailgun_failure if (Time.at(timestamp.to_i) - Time.now).abs > 24.hours.to_i
|
||||
|
||||
# check the signature
|
||||
return mailgun_failure unless mailgun_verify(timestamp, token, params["signature"])
|
||||
|
||||
event = params.delete("event")
|
||||
message_id = params.delete("message-id")
|
||||
event = params["event"]
|
||||
message_id = params["Message-Id"].tr("<>", "")
|
||||
|
||||
# only handle soft bounces, because hard bounces are also handled
|
||||
# by the "dropped" event and we don't want to increase bounce score twice
|
||||
|
|
|
@ -4,13 +4,13 @@ describe WebhooksController do
|
|||
before { $redis.flushall }
|
||||
|
||||
let(:email) { "em@il.com" }
|
||||
let(:message_id) { "12345@il.com" }
|
||||
|
||||
context "mailgun" do
|
||||
|
||||
it "works" do
|
||||
SiteSetting.mailgun_api_key = "key-8221462f0c915af3f6f2e2df7aa5a493"
|
||||
|
||||
message_id = "12345@il.com"
|
||||
user = Fabricate(:user, email: email)
|
||||
email_log = Fabricate(:email_log, user: user, message_id: message_id)
|
||||
|
||||
|
@ -19,7 +19,7 @@ describe WebhooksController do
|
|||
post :mailgun, "token" => "705a8ccd2ce932be8e98c221fe701c1b4a0afcb8bbd57726de",
|
||||
"timestamp" => Time.now.to_i,
|
||||
"event" => "dropped",
|
||||
"message-id" => message_id
|
||||
"Message-Id" => "<12345@il.com>"
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
|
@ -34,7 +34,7 @@ describe WebhooksController do
|
|||
|
||||
it "works" do
|
||||
user = Fabricate(:user, email: email)
|
||||
email_log = Fabricate(:email_log, user: user, message_id: "12345@il.com")
|
||||
email_log = Fabricate(:email_log, user: user, message_id: message_id)
|
||||
|
||||
post :sendgrid, "_json" => [
|
||||
{
|
||||
|
@ -57,7 +57,6 @@ describe WebhooksController do
|
|||
context "mailjet" do
|
||||
|
||||
it "works" do
|
||||
message_id = "12345@il.com"
|
||||
user = Fabricate(:user, email: email)
|
||||
email_log = Fabricate(:email_log, user: user, message_id: message_id)
|
||||
|
||||
|
|
Loading…
Reference in a new issue