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