From b3919d01554d31c5486d17332f4a4dde89a23239 Mon Sep 17 00:00:00 2001
From: George Claghorn <george@basecamp.com>
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 +++++++++++++---
 test/unit/inbound_email/message_id_test.rb               |  4 +---
 2 files changed, 14 insertions(+), 6 deletions(-)

(limited to 'test')

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
 
diff --git a/test/unit/inbound_email/message_id_test.rb b/test/unit/inbound_email/message_id_test.rb
index aa9ce90b4c..c744a5bf99 100644
--- a/test/unit/inbound_email/message_id_test.rb
+++ b/test/unit/inbound_email/message_id_test.rb
@@ -7,9 +7,7 @@ class ActionMailbox::InboundEmail::MessageIdTest < ActiveSupport::TestCase
   end
 
   test "message id is generated if its missing" do
-    source_without_message_id = "Date: Fri, 28 Sep 2018 11:08:55 -0700\r\nTo: a@example.com\r\nMime-Version: 1.0\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: 7bit\r\n\r\nHello!"
-    inbound_email = create_inbound_email Tempfile.new.tap { |raw_email| raw_email.write source_without_message_id }
-
+    inbound_email = create_inbound_email "Date: Fri, 28 Sep 2018 11:08:55 -0700\r\nTo: a@example.com\r\nMime-Version: 1.0\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: 7bit\r\n\r\nHello!"
     assert_not_nil inbound_email.message_id
   end
 end
-- 
cgit v1.2.3