From 6b7eac5c51cbef4acd1ab7f48884e7b614f71678 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Sat, 6 Oct 2018 22:02:08 -0400 Subject: Accept inbound emails from a variety of ingresses --- .../amazon/inbound_emails_controller_test.rb | 18 ++++++++ .../mailgun/inbound_emails_controller_test.rb | 51 ++++++++++++++++++++++ .../postfix/inbound_emails_controller_test.rb | 33 ++++++++++++++ .../sendgrid/inbound_emails_controller_test.rb | 33 ++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 test/controllers/ingresses/amazon/inbound_emails_controller_test.rb create mode 100644 test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb create mode 100644 test/controllers/ingresses/postfix/inbound_emails_controller_test.rb create mode 100644 test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb (limited to 'test/controllers/ingresses') diff --git a/test/controllers/ingresses/amazon/inbound_emails_controller_test.rb b/test/controllers/ingresses/amazon/inbound_emails_controller_test.rb new file mode 100644 index 0000000000..5eda6d8d65 --- /dev/null +++ b/test/controllers/ingresses/amazon/inbound_emails_controller_test.rb @@ -0,0 +1,18 @@ +require "test_helper" + +ActionMailbox::Ingresses::Amazon::InboundEmailsController.verifier = + Module.new { def self.authentic?(message); true; end } + +class ActionMailbox::Ingresses::Amazon::InboundEmailsControllerTest < ActionDispatch::IntegrationTest + test "receiving an inbound email from Amazon" do + assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do + post rails_amazon_inbound_emails_url, params: { content: file_fixture("../files/welcome.eml").read }, as: :json + end + + assert_response :no_content + + inbound_email = ActionMailbox::InboundEmail.last + assert_equal file_fixture("../files/welcome.eml").read, inbound_email.raw_email.download + assert_equal "0CB459E0-0336-41DA-BC88-E6E28C697DDB@37signals.com", inbound_email.message_id + end +end diff --git a/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb b/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb new file mode 100644 index 0000000000..873d0e81d8 --- /dev/null +++ b/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb @@ -0,0 +1,51 @@ +require "test_helper" + +ActionMailbox::Ingresses::Mailgun::InboundEmailsController::Authenticator.key = "tbsy84uSV1Kt3ZJZELY2TmShPRs91E3yL4tzf96297vBCkDWgL" + +class ActionMailbox::Ingresses::Mailgun::InboundEmailsControllerTest < ActionDispatch::IntegrationTest + test "receiving an inbound email from Mailgun" do + assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do + travel_to "2018-10-09 15:15:00 EDT" + post rails_mailgun_inbound_emails_url, params: { + timestamp: 1539112500, + token: "7VwW7k6Ak7zcTwoSoNm7aTtbk1g67MKAnsYLfUB7PdszbgR5Xi", + signature: "ef24c5225322217bb065b80bb54eb4f9206d764e3e16abab07f0a64d1cf477cc", + "body-mime" => file_fixture("../files/welcome.eml").read + } + end + + assert_response :ok + + inbound_email = ActionMailbox::InboundEmail.last + assert_equal file_fixture("../files/welcome.eml").read, inbound_email.raw_email.download + assert_equal "0CB459E0-0336-41DA-BC88-E6E28C697DDB@37signals.com", inbound_email.message_id + end + + test "rejecting a delayed inbound email from Mailgun" do + assert_no_difference -> { ActionMailbox::InboundEmail.count } do + travel_to "2018-10-09 15:26:00 EDT" + post rails_mailgun_inbound_emails_url, params: { + timestamp: 1539112500, + token: "7VwW7k6Ak7zcTwoSoNm7aTtbk1g67MKAnsYLfUB7PdszbgR5Xi", + signature: "ef24c5225322217bb065b80bb54eb4f9206d764e3e16abab07f0a64d1cf477cc", + "body-mime" => file_fixture("../files/welcome.eml").read + } + end + + assert_response :unauthorized + end + + test "rejecting a forged inbound email from Mailgun" do + assert_no_difference -> { ActionMailbox::InboundEmail.count } do + travel_to "2018-10-09 15:15:00 EDT" + post rails_mailgun_inbound_emails_url, params: { + timestamp: 1539112500, + token: "Zx8mJBiGmiiyyfWnho3zKyjCg2pxLARoCuBM7X9AKCioShGiMX", + signature: "ef24c5225322217bb065b80bb54eb4f9206d764e3e16abab07f0a64d1cf477cc", + "body-mime" => file_fixture("../files/welcome.eml").read + } + end + + assert_response :unauthorized + end +end diff --git a/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb b/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb new file mode 100644 index 0000000000..bade5215d6 --- /dev/null +++ b/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb @@ -0,0 +1,33 @@ +require "test_helper" + +ActionMailbox::Ingresses::Postfix::InboundEmailsController.password = "tbsy84uSV1Kt3ZJZELY2TmShPRs91E3yL4tzf96297vBCkDWgL" + +class ActionMailbox::Ingresses::Postfix::InboundEmailsControllerTest < ActionDispatch::IntegrationTest + test "receiving an inbound email from Postfix" do + assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do + post rails_postfix_inbound_emails_url, headers: { authorization: credentials }, + params: { message: fixture_file_upload("files/welcome.eml", "message/rfc822") } + end + + assert_response :no_content + + inbound_email = ActionMailbox::InboundEmail.last + assert_equal file_fixture("../files/welcome.eml").read, inbound_email.raw_email.download + assert_equal "0CB459E0-0336-41DA-BC88-E6E28C697DDB@37signals.com", inbound_email.message_id + end + + test "rejecting an unauthorized inbound email from Postfix" do + assert_no_difference -> { ActionMailbox::InboundEmail.count } do + post rails_postfix_inbound_emails_url, params: { message: fixture_file_upload("files/welcome.eml", "message/rfc822") } + end + + assert_response :unauthorized + end + + private + delegate :username, :password, to: ActionMailbox::Ingresses::Postfix::InboundEmailsController + + def credentials + ActionController::HttpAuthentication::Basic.encode_credentials username, password + end +end diff --git a/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb b/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb new file mode 100644 index 0000000000..7663c6657e --- /dev/null +++ b/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb @@ -0,0 +1,33 @@ +require "test_helper" + +ActionMailbox::Ingresses::Sendgrid::InboundEmailsController.password = "tbsy84uSV1Kt3ZJZELY2TmShPRs91E3yL4tzf96297vBCkDWgL" + +class ActionMailbox::Ingresses::Sendgrid::InboundEmailsControllerTest < ActionDispatch::IntegrationTest + test "receiving an inbound email from Sendgrid" do + assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do + post rails_sendgrid_inbound_emails_url, + headers: { authorization: credentials }, params: { email: file_fixture("../files/welcome.eml").read } + end + + assert_response :no_content + + inbound_email = ActionMailbox::InboundEmail.last + assert_equal file_fixture("../files/welcome.eml").read, inbound_email.raw_email.download + assert_equal "0CB459E0-0336-41DA-BC88-E6E28C697DDB@37signals.com", inbound_email.message_id + end + + test "rejecting an unauthorized inbound email from Sendgrid" do + assert_no_difference -> { ActionMailbox::InboundEmail.count } do + post rails_sendgrid_inbound_emails_url, params: { email: file_fixture("../files/welcome.eml").read } + end + + assert_response :unauthorized + end + + private + delegate :username, :password, to: ActionMailbox::Ingresses::Sendgrid::InboundEmailsController + + def credentials + ActionController::HttpAuthentication::Basic.encode_credentials username, password + end +end -- cgit v1.2.3 From 3984460424b678d844009319598e2b41c350ca3c Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Wed, 17 Oct 2018 00:12:03 -0400 Subject: Add Mandrill support --- .../mandrill/inbound_emails_controller_test.rb | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb (limited to 'test/controllers/ingresses') diff --git a/test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb b/test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb new file mode 100644 index 0000000000..abef6baa4f --- /dev/null +++ b/test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb @@ -0,0 +1,31 @@ +require "test_helper" + +ActionMailbox::Ingresses::Mandrill::InboundEmailsController::Authenticator.key = "1l9Qf7lutEf7h73VXfBwhw" + +class ActionMailbox::Ingresses::Mandrill::InboundEmailsControllerTest < ActionDispatch::IntegrationTest + setup do + @events = JSON.generate([{ event: "inbound", msg: { raw_msg: file_fixture("../files/welcome.eml").read } }]) + end + + test "receiving an inbound email from Mandrill" do + assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do + post rails_mandrill_inbound_emails_url, + headers: { "X-Mandrill-Signature" => "gldscd2tAb/G+DmpiLcwukkLrC4=" }, params: { mandrill_events: @events } + end + + assert_response :ok + + inbound_email = ActionMailbox::InboundEmail.last + assert_equal file_fixture("../files/welcome.eml").read, inbound_email.raw_email.download + assert_equal "0CB459E0-0336-41DA-BC88-E6E28C697DDB@37signals.com", inbound_email.message_id + end + + test "rejecting a forged inbound email from Mandrill" do + assert_no_difference -> { ActionMailbox::InboundEmail.count } do + post rails_mandrill_inbound_emails_url, + headers: { "X-Mandrill-Signature" => "forged" }, params: { mandrill_events: @events } + end + + assert_response :unauthorized + end +end -- cgit v1.2.3 From b3919d01554d31c5486d17332f4a4dde89a23239 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Thu, 18 Oct 2018 10:23:17 -0400 Subject: Don't require Postfix to send form data --- .../ingresses/postfix/inbound_emails_controller_test.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'test/controllers/ingresses') diff --git a/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb b/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb index bade5215d6..3fa0854576 100644 --- a/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb +++ b/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb @@ -5,8 +5,8 @@ ActionMailbox::Ingresses::Postfix::InboundEmailsController.password = "tbsy84uSV class ActionMailbox::Ingresses::Postfix::InboundEmailsControllerTest < ActionDispatch::IntegrationTest test "receiving an inbound email from Postfix" do assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do - post rails_postfix_inbound_emails_url, headers: { authorization: credentials }, - params: { message: fixture_file_upload("files/welcome.eml", "message/rfc822") } + post rails_postfix_inbound_emails_url, headers: { "Authorization" => credentials, "Content-Type" => "message/rfc822" }, + params: file_fixture("../files/welcome.eml").read end assert_response :no_content @@ -18,12 +18,22 @@ class ActionMailbox::Ingresses::Postfix::InboundEmailsControllerTest < ActionDis test "rejecting an unauthorized inbound email from Postfix" do assert_no_difference -> { ActionMailbox::InboundEmail.count } do - post rails_postfix_inbound_emails_url, params: { message: fixture_file_upload("files/welcome.eml", "message/rfc822") } + post rails_postfix_inbound_emails_url, headers: { "Content-Type" => "message/rfc822" }, + params: file_fixture("../files/welcome.eml").read end assert_response :unauthorized end + test "rejecting an inbound email of an unsupported media type from Postfix" do + assert_no_difference -> { ActionMailbox::InboundEmail.count } do + post rails_postfix_inbound_emails_url, headers: { "Authorization" => credentials, "Content-Type" => "text/plain" }, + params: file_fixture("../files/welcome.eml").read + end + + assert_response :unsupported_media_type + end + private delegate :username, :password, to: ActionMailbox::Ingresses::Postfix::InboundEmailsController -- cgit v1.2.3 From 6b41c48f8ea098943e3948812d147c80eb79dd94 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Fri, 19 Oct 2018 20:05:12 -0400 Subject: Update test --- test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/controllers/ingresses') diff --git a/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb b/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb index 873d0e81d8..35e8314618 100644 --- a/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb +++ b/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb @@ -14,7 +14,7 @@ class ActionMailbox::Ingresses::Mailgun::InboundEmailsControllerTest < ActionDis } end - assert_response :ok + assert_response :no_content inbound_email = ActionMailbox::InboundEmail.last assert_equal file_fixture("../files/welcome.eml").read, inbound_email.raw_email.download -- cgit v1.2.3 From be0a8bec8701c7df2667dbf1569429218ea30370 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Mon, 29 Oct 2018 13:45:24 -0400 Subject: Raise when required config is missing --- .../mailgun/inbound_emails_controller_test.rb | 38 ++++++++++++++++++++++ .../mandrill/inbound_emails_controller_test.rb | 28 ++++++++++++++++ .../postfix/inbound_emails_controller_test.rb | 27 ++++++++++++++- .../sendgrid/inbound_emails_controller_test.rb | 27 ++++++++++++++- 4 files changed, 118 insertions(+), 2 deletions(-) (limited to 'test/controllers/ingresses') diff --git a/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb b/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb index 35e8314618..8fb3dd28c6 100644 --- a/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb +++ b/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb @@ -48,4 +48,42 @@ class ActionMailbox::Ingresses::Mailgun::InboundEmailsControllerTest < ActionDis assert_response :unauthorized end + + test "raising when the configured Mailgun API key is nil" do + switch_key_to nil do + assert_raises ArgumentError do + travel_to "2018-10-09 15:15:00 EDT" + post rails_mailgun_inbound_emails_url, params: { + timestamp: 1539112500, + token: "7VwW7k6Ak7zcTwoSoNm7aTtbk1g67MKAnsYLfUB7PdszbgR5Xi", + signature: "ef24c5225322217bb065b80bb54eb4f9206d764e3e16abab07f0a64d1cf477cc", + "body-mime" => file_fixture("../files/welcome.eml").read + } + end + end + end + + test "raising when the configured Mailgun API key is blank" do + switch_key_to "" do + assert_raises ArgumentError do + travel_to "2018-10-09 15:15:00 EDT" + post rails_mailgun_inbound_emails_url, params: { + timestamp: 1539112500, + token: "7VwW7k6Ak7zcTwoSoNm7aTtbk1g67MKAnsYLfUB7PdszbgR5Xi", + signature: "ef24c5225322217bb065b80bb54eb4f9206d764e3e16abab07f0a64d1cf477cc", + "body-mime" => file_fixture("../files/welcome.eml").read + } + end + end + end + + private + delegate :key, :key=, to: ActionMailbox::Ingresses::Mailgun::InboundEmailsController::Authenticator + + def switch_key_to(new_key) + previous_key, self.key = key, new_key + yield + ensure + self.key = previous_key + end end diff --git a/test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb b/test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb index abef6baa4f..1658d85104 100644 --- a/test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb +++ b/test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb @@ -28,4 +28,32 @@ class ActionMailbox::Ingresses::Mandrill::InboundEmailsControllerTest < ActionDi assert_response :unauthorized end + + test "raising when Mandrill API key is nil" do + switch_key_to nil do + assert_raises ArgumentError do + post rails_mandrill_inbound_emails_url, + headers: { "X-Mandrill-Signature" => "gldscd2tAb/G+DmpiLcwukkLrC4=" }, params: { mandrill_events: @events } + end + end + end + + test "raising when Mandrill API key is blank" do + switch_key_to "" do + assert_raises ArgumentError do + post rails_mandrill_inbound_emails_url, + headers: { "X-Mandrill-Signature" => "gldscd2tAb/G+DmpiLcwukkLrC4=" }, params: { mandrill_events: @events } + end + end + end + + private + delegate :key, :key=, to: ActionMailbox::Ingresses::Mandrill::InboundEmailsController::Authenticator + + def switch_key_to(new_key) + previous_key, self.key = key, new_key + yield + ensure + self.key = previous_key + end end diff --git a/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb b/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb index 3fa0854576..a9588791b9 100644 --- a/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb +++ b/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb @@ -34,10 +34,35 @@ class ActionMailbox::Ingresses::Postfix::InboundEmailsControllerTest < ActionDis assert_response :unsupported_media_type end + test "raising when the configured password is nil" do + switch_password_to nil do + assert_raises ArgumentError do + post rails_postfix_inbound_emails_url, headers: { "Authorization" => credentials, "Content-Type" => "message/rfc822" }, + params: file_fixture("../files/welcome.eml").read + end + end + end + + test "raising when the configured password is blank" do + switch_password_to "" do + assert_raises ArgumentError do + post rails_postfix_inbound_emails_url, headers: { "Authorization" => credentials, "Content-Type" => "message/rfc822" }, + params: file_fixture("../files/welcome.eml").read + end + end + end + private - delegate :username, :password, to: ActionMailbox::Ingresses::Postfix::InboundEmailsController + delegate :username, :password, :password=, to: ActionMailbox::Ingresses::Postfix::InboundEmailsController def credentials ActionController::HttpAuthentication::Basic.encode_credentials username, password end + + def switch_password_to(new_password) + previous_password, self.password = password, new_password + yield + ensure + self.password = previous_password + end end diff --git a/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb b/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb index 7663c6657e..759a532087 100644 --- a/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb +++ b/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb @@ -24,10 +24,35 @@ class ActionMailbox::Ingresses::Sendgrid::InboundEmailsControllerTest < ActionDi assert_response :unauthorized end + test "raising when the configured password is nil" do + switch_password_to nil do + assert_raises ArgumentError do + post rails_sendgrid_inbound_emails_url, + headers: { authorization: credentials }, params: { email: file_fixture("../files/welcome.eml").read } + end + end + end + + test "raising when the configured password is blank" do + switch_password_to "" do + assert_raises ArgumentError do + post rails_sendgrid_inbound_emails_url, + headers: { authorization: credentials }, params: { email: file_fixture("../files/welcome.eml").read } + end + end + end + private - delegate :username, :password, to: ActionMailbox::Ingresses::Sendgrid::InboundEmailsController + delegate :username, :password, :password=, to: ActionMailbox::Ingresses::Sendgrid::InboundEmailsController def credentials ActionController::HttpAuthentication::Basic.encode_credentials username, password end + + def switch_password_to(new_password) + previous_password, self.password = password, new_password + yield + ensure + self.password = previous_password + end end -- cgit v1.2.3 From 7755f9b381c007ce98e0858473a9f29f1cd25311 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Mon, 5 Nov 2018 09:11:01 -0500 Subject: Read ingress passwords/API keys from encrypted credentials Fall back to ENV for people who prefer that approach. --- .../ingresses/amazon/inbound_emails_controller_test.rb | 2 ++ .../mailgun/inbound_emails_controller_test.rb | 10 +++++----- .../mandrill/inbound_emails_controller_test.rb | 9 ++++----- .../postfix/inbound_emails_controller_test.rb | 18 ++---------------- .../sendgrid/inbound_emails_controller_test.rb | 15 +++------------ 5 files changed, 16 insertions(+), 38 deletions(-) (limited to 'test/controllers/ingresses') diff --git a/test/controllers/ingresses/amazon/inbound_emails_controller_test.rb b/test/controllers/ingresses/amazon/inbound_emails_controller_test.rb index 5eda6d8d65..c36c500cbe 100644 --- a/test/controllers/ingresses/amazon/inbound_emails_controller_test.rb +++ b/test/controllers/ingresses/amazon/inbound_emails_controller_test.rb @@ -4,6 +4,8 @@ ActionMailbox::Ingresses::Amazon::InboundEmailsController.verifier = Module.new { def self.authentic?(message); true; end } class ActionMailbox::Ingresses::Amazon::InboundEmailsControllerTest < ActionDispatch::IntegrationTest + setup { ActionMailbox.ingress = :amazon } + test "receiving an inbound email from Amazon" do assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do post rails_amazon_inbound_emails_url, params: { content: file_fixture("../files/welcome.eml").read }, as: :json diff --git a/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb b/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb index 8fb3dd28c6..c5ec71013e 100644 --- a/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb +++ b/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb @@ -1,8 +1,10 @@ require "test_helper" -ActionMailbox::Ingresses::Mailgun::InboundEmailsController::Authenticator.key = "tbsy84uSV1Kt3ZJZELY2TmShPRs91E3yL4tzf96297vBCkDWgL" +ENV["MAILGUN_INGRESS_API_KEY"] = "tbsy84uSV1Kt3ZJZELY2TmShPRs91E3yL4tzf96297vBCkDWgL" class ActionMailbox::Ingresses::Mailgun::InboundEmailsControllerTest < ActionDispatch::IntegrationTest + setup { ActionMailbox.ingress = :mailgun } + test "receiving an inbound email from Mailgun" do assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do travel_to "2018-10-09 15:15:00 EDT" @@ -78,12 +80,10 @@ class ActionMailbox::Ingresses::Mailgun::InboundEmailsControllerTest < ActionDis end private - delegate :key, :key=, to: ActionMailbox::Ingresses::Mailgun::InboundEmailsController::Authenticator - def switch_key_to(new_key) - previous_key, self.key = key, new_key + previous_key, ENV["MAILGUN_INGRESS_API_KEY"] = ENV["MAILGUN_INGRESS_API_KEY"], new_key yield ensure - self.key = previous_key + ENV["MAILGUN_INGRESS_API_KEY"] = previous_key end end diff --git a/test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb b/test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb index 1658d85104..c8a8e731d6 100644 --- a/test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb +++ b/test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb @@ -1,9 +1,10 @@ require "test_helper" -ActionMailbox::Ingresses::Mandrill::InboundEmailsController::Authenticator.key = "1l9Qf7lutEf7h73VXfBwhw" +ENV["MANDRILL_INGRESS_API_KEY"] = "1l9Qf7lutEf7h73VXfBwhw" class ActionMailbox::Ingresses::Mandrill::InboundEmailsControllerTest < ActionDispatch::IntegrationTest setup do + ActionMailbox.ingress = :mandrill @events = JSON.generate([{ event: "inbound", msg: { raw_msg: file_fixture("../files/welcome.eml").read } }]) end @@ -48,12 +49,10 @@ class ActionMailbox::Ingresses::Mandrill::InboundEmailsControllerTest < ActionDi end private - delegate :key, :key=, to: ActionMailbox::Ingresses::Mandrill::InboundEmailsController::Authenticator - def switch_key_to(new_key) - previous_key, self.key = key, new_key + previous_key, ENV["MANDRILL_INGRESS_API_KEY"] = ENV["MANDRILL_INGRESS_API_KEY"], new_key yield ensure - self.key = previous_key + ENV["MANDRILL_INGRESS_API_KEY"] = previous_key end end diff --git a/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb b/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb index a9588791b9..5e0777aa30 100644 --- a/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb +++ b/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb @@ -1,8 +1,8 @@ require "test_helper" -ActionMailbox::Ingresses::Postfix::InboundEmailsController.password = "tbsy84uSV1Kt3ZJZELY2TmShPRs91E3yL4tzf96297vBCkDWgL" - class ActionMailbox::Ingresses::Postfix::InboundEmailsControllerTest < ActionDispatch::IntegrationTest + setup { ActionMailbox.ingress = :postfix } + test "receiving an inbound email from Postfix" do assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do post rails_postfix_inbound_emails_url, headers: { "Authorization" => credentials, "Content-Type" => "message/rfc822" }, @@ -51,18 +51,4 @@ class ActionMailbox::Ingresses::Postfix::InboundEmailsControllerTest < ActionDis end end end - - private - delegate :username, :password, :password=, to: ActionMailbox::Ingresses::Postfix::InboundEmailsController - - def credentials - ActionController::HttpAuthentication::Basic.encode_credentials username, password - end - - def switch_password_to(new_password) - previous_password, self.password = password, new_password - yield - ensure - self.password = previous_password - end end diff --git a/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb b/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb index 759a532087..bf6ccd8f03 100644 --- a/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb +++ b/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb @@ -1,8 +1,8 @@ require "test_helper" -ActionMailbox::Ingresses::Sendgrid::InboundEmailsController.password = "tbsy84uSV1Kt3ZJZELY2TmShPRs91E3yL4tzf96297vBCkDWgL" - class ActionMailbox::Ingresses::Sendgrid::InboundEmailsControllerTest < ActionDispatch::IntegrationTest + setup { ActionMailbox.ingress = :sendgrid } + test "receiving an inbound email from Sendgrid" do assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do post rails_sendgrid_inbound_emails_url, @@ -43,16 +43,7 @@ class ActionMailbox::Ingresses::Sendgrid::InboundEmailsControllerTest < ActionDi end private - delegate :username, :password, :password=, to: ActionMailbox::Ingresses::Sendgrid::InboundEmailsController - def credentials - ActionController::HttpAuthentication::Basic.encode_credentials username, password - end - - def switch_password_to(new_password) - previous_password, self.password = password, new_password - yield - ensure - self.password = previous_password + ActionController::HttpAuthentication::Basic.encode_credentials "actionmailbox", ENV["RAILS_INBOUND_EMAIL_PASSWORD"] end end -- cgit v1.2.3 From a7e8fe4d6e3f18eb3431e9fc95b42542ae2946fb Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Mon, 5 Nov 2018 12:52:56 -0500 Subject: Remove duplicate method --- .../controllers/ingresses/sendgrid/inbound_emails_controller_test.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'test/controllers/ingresses') diff --git a/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb b/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb index bf6ccd8f03..0c7d0d6846 100644 --- a/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb +++ b/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb @@ -41,9 +41,4 @@ class ActionMailbox::Ingresses::Sendgrid::InboundEmailsControllerTest < ActionDi end end end - - private - def credentials - ActionController::HttpAuthentication::Basic.encode_credentials "actionmailbox", ENV["RAILS_INBOUND_EMAIL_PASSWORD"] - end end -- cgit v1.2.3