diff options
author | George Claghorn <george@basecamp.com> | 2018-11-05 09:11:01 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-11-05 09:11:01 -0500 |
commit | 7755f9b381c007ce98e0858473a9f29f1cd25311 (patch) | |
tree | 9130fccc00bf2602cdcf92eda572deec911f6302 /test/controllers/ingresses | |
parent | cb041ddc7e94da15e2db72188545f78da6cadb53 (diff) | |
download | rails-7755f9b381c007ce98e0858473a9f29f1cd25311.tar.gz rails-7755f9b381c007ce98e0858473a9f29f1cd25311.tar.bz2 rails-7755f9b381c007ce98e0858473a9f29f1cd25311.zip |
Read ingress passwords/API keys from encrypted credentials
Fall back to ENV for people who prefer that approach.
Diffstat (limited to 'test/controllers/ingresses')
5 files changed, 16 insertions, 38 deletions
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 |