2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-05-30 11:11:17 -04:00
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
describe WebhooksController do
|
2019-12-03 04:05:53 -05:00
|
|
|
before { Discourse.redis.flushall }
|
2016-05-30 11:11:17 -04:00
|
|
|
|
2016-06-01 15:48:06 -04:00
|
|
|
let(:email) { "em@il.com" }
|
2016-06-08 18:33:13 -04:00
|
|
|
let(:message_id) { "12345@il.com" }
|
2016-06-01 15:48:06 -04:00
|
|
|
|
|
|
|
context "mailgun" do
|
2019-01-31 11:52:33 -05:00
|
|
|
|
|
|
|
let(:token) { "705a8ccd2ce932be8e98c221fe701c1b4a0afcb8bbd57726de" }
|
|
|
|
let(:timestamp) { Time.now.to_i }
|
|
|
|
let(:data) { "#{timestamp}#{token}" }
|
|
|
|
let(:signature) { OpenSSL::HMAC.hexdigest("SHA256", SiteSetting.mailgun_api_key, data) }
|
|
|
|
|
|
|
|
before do
|
2016-06-06 19:55:24 -04:00
|
|
|
SiteSetting.mailgun_api_key = "key-8221462f0c915af3f6f2e2df7aa5a493"
|
2019-01-31 11:52:33 -05:00
|
|
|
end
|
2016-05-30 11:11:17 -04:00
|
|
|
|
2019-01-31 11:52:33 -05:00
|
|
|
it "works (deprecated)" do
|
2016-06-01 15:48:06 -04:00
|
|
|
user = Fabricate(:user, email: email)
|
2017-02-05 13:06:35 -05:00
|
|
|
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
|
2016-05-30 11:11:17 -04:00
|
|
|
|
2018-06-05 01:17:33 -04:00
|
|
|
post "/webhooks/mailgun.json", params: {
|
|
|
|
"token" => token,
|
|
|
|
"timestamp" => timestamp,
|
2017-08-31 00:06:56 -04:00
|
|
|
"event" => "dropped",
|
|
|
|
"recipient" => email,
|
2019-01-31 11:52:33 -05:00
|
|
|
"Message-Id" => "<#{message_id}>",
|
2018-06-05 01:17:33 -04:00
|
|
|
"signature" => signature
|
|
|
|
}
|
2016-05-30 11:11:17 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2016-05-30 11:11:17 -04:00
|
|
|
|
|
|
|
email_log.reload
|
|
|
|
expect(email_log.bounced).to eq(true)
|
2019-01-31 11:52:33 -05:00
|
|
|
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.hard_bounce_score)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works (new)" do
|
|
|
|
user = Fabricate(:user, email: email)
|
|
|
|
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
|
|
|
|
|
|
|
|
post "/webhooks/mailgun.json", params: {
|
|
|
|
"signature" => {
|
|
|
|
"token" => token,
|
|
|
|
"timestamp" => timestamp,
|
|
|
|
"signature" => signature,
|
|
|
|
},
|
|
|
|
"event-data" => {
|
|
|
|
"event" => "failed",
|
|
|
|
"severity" => "temporary",
|
|
|
|
"recipient" => email,
|
|
|
|
"message" => {
|
|
|
|
"headers" => {
|
|
|
|
"message-id" => message_id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
email_log.reload
|
|
|
|
expect(email_log.bounced).to eq(true)
|
|
|
|
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.soft_bounce_score)
|
2016-05-30 11:11:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-01 15:48:06 -04:00
|
|
|
context "sendgrid" do
|
|
|
|
it "works" do
|
|
|
|
user = Fabricate(:user, email: email)
|
2017-02-05 13:06:35 -05:00
|
|
|
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
|
2016-06-01 15:48:06 -04:00
|
|
|
|
2018-06-05 01:17:33 -04:00
|
|
|
post "/webhooks/sendgrid.json", params: {
|
2017-08-31 00:06:56 -04:00
|
|
|
"_json" => [
|
|
|
|
{
|
2018-12-04 04:48:16 -05:00
|
|
|
"email" => email,
|
2017-08-31 00:06:56 -04:00
|
|
|
"smtp-id" => "<12345@il.com>",
|
2018-12-04 04:48:16 -05:00
|
|
|
"event" => "bounce",
|
|
|
|
"status" => "5.0.0"
|
2017-08-31 00:06:56 -04:00
|
|
|
}
|
|
|
|
]
|
2018-06-05 01:17:33 -04:00
|
|
|
}
|
2016-06-01 15:48:06 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2016-06-01 15:48:06 -04:00
|
|
|
|
|
|
|
email_log.reload
|
|
|
|
expect(email_log.bounced).to eq(true)
|
2019-01-31 11:52:33 -05:00
|
|
|
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.hard_bounce_score)
|
2016-06-01 15:48:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-06 13:47:45 -04:00
|
|
|
context "mailjet" do
|
|
|
|
it "works" do
|
|
|
|
user = Fabricate(:user, email: email)
|
2017-02-05 13:06:35 -05:00
|
|
|
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
|
2016-06-06 13:47:45 -04:00
|
|
|
|
2018-06-05 01:17:33 -04:00
|
|
|
post "/webhooks/mailjet.json", params: {
|
2017-08-31 00:06:56 -04:00
|
|
|
"event" => "bounce",
|
2018-12-04 04:48:16 -05:00
|
|
|
"email" => email,
|
2017-08-31 00:06:56 -04:00
|
|
|
"hard_bounce" => true,
|
2018-12-04 04:48:16 -05:00
|
|
|
"CustomID" => message_id
|
2018-06-05 01:17:33 -04:00
|
|
|
}
|
2016-06-06 13:47:45 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2016-06-06 13:47:45 -04:00
|
|
|
|
|
|
|
email_log.reload
|
|
|
|
expect(email_log.bounced).to eq(true)
|
2019-01-31 11:52:33 -05:00
|
|
|
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.hard_bounce_score)
|
2016-06-06 13:47:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-13 06:31:01 -04:00
|
|
|
context "mandrill" do
|
|
|
|
it "works" do
|
|
|
|
user = Fabricate(:user, email: email)
|
2017-02-05 13:06:35 -05:00
|
|
|
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
|
2016-06-13 06:31:01 -04:00
|
|
|
|
2018-06-05 01:17:33 -04:00
|
|
|
post "/webhooks/mandrill.json", params: {
|
2017-08-31 00:06:56 -04:00
|
|
|
mandrill_events: [{
|
|
|
|
"event" => "hard_bounce",
|
|
|
|
"msg" => {
|
|
|
|
"email" => email,
|
|
|
|
"metadata" => {
|
|
|
|
"message_id" => message_id
|
|
|
|
}
|
2016-06-13 06:31:01 -04:00
|
|
|
}
|
2017-08-31 00:06:56 -04:00
|
|
|
}]
|
2018-06-05 01:17:33 -04:00
|
|
|
}
|
2016-06-13 06:31:01 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2016-06-13 06:31:01 -04:00
|
|
|
|
|
|
|
email_log.reload
|
|
|
|
expect(email_log.bounced).to eq(true)
|
2019-01-31 11:52:33 -05:00
|
|
|
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.hard_bounce_score)
|
2016-06-13 06:31:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-27 01:13:34 -04:00
|
|
|
context "sparkpost" do
|
|
|
|
it "works" do
|
|
|
|
user = Fabricate(:user, email: email)
|
2017-02-05 13:06:35 -05:00
|
|
|
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
|
2016-09-27 01:13:34 -04:00
|
|
|
|
2018-06-05 01:17:33 -04:00
|
|
|
post "/webhooks/sparkpost.json", params: {
|
2017-08-31 00:06:56 -04:00
|
|
|
"_json" => [{
|
|
|
|
"msys" => {
|
|
|
|
"message_event" => {
|
|
|
|
"bounce_class" => 10,
|
|
|
|
"rcpt_to" => email,
|
|
|
|
"rcpt_meta" => {
|
|
|
|
"message_id" => message_id
|
|
|
|
}
|
2016-10-27 13:35:50 -04:00
|
|
|
}
|
2016-09-27 01:13:34 -04:00
|
|
|
}
|
2017-08-31 00:06:56 -04:00
|
|
|
}]
|
2018-06-05 01:17:33 -04:00
|
|
|
}
|
2016-09-27 01:13:34 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2016-09-27 01:13:34 -04:00
|
|
|
|
|
|
|
email_log.reload
|
|
|
|
expect(email_log.bounced).to eq(true)
|
2019-01-31 11:52:33 -05:00
|
|
|
expect(email_log.user.user_stat.bounce_score).to eq(SiteSetting.hard_bounce_score)
|
2016-09-27 01:13:34 -04:00
|
|
|
end
|
|
|
|
end
|
2016-05-30 11:11:17 -04:00
|
|
|
end
|