Skip to content

Commit b5b5835

Browse files
skipkayhilzzak
authored andcommitted
Fix Action Mailbox assuming request.body present
In Rack 3.1, `rack.intput` (`request.body`) is no longer guaranteed to be present, so we can no longer unconditionally call `read` on it. Co-authored-by: zzak <[email protected]>
1 parent cd3d94a commit b5b5835

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

actionmailbox/app/controllers/action_mailbox/ingresses/relay/inbound_emails_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ class Ingresses::Relay::InboundEmailsController < ActionMailbox::BaseController
5252
before_action :authenticate_by_password, :require_valid_rfc822_message
5353

5454
def create
55-
ActionMailbox::InboundEmail.create_and_extract_message_id! request.body.read
55+
if request.body
56+
ActionMailbox::InboundEmail.create_and_extract_message_id! request.body.read
57+
else
58+
head :unprocessable_entity
59+
end
5660
end
5761

5862
private

actionmailbox/test/controllers/ingresses/relay/inbound_emails_controller_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ class ActionMailbox::Ingresses::Relay::InboundEmailsControllerTest < ActionDispa
3131
assert_equal "[email protected]", inbound_email.message_id
3232
end
3333

34+
test "rejecting a request with no body" do
35+
assert_no_difference -> { ActionMailbox::InboundEmail.count } do
36+
post rails_relay_inbound_emails_url, headers: { "Authorization" => credentials, "Content-Type" => "message/rfc822" },
37+
env: { "rack.input" => nil }
38+
end
39+
40+
assert_response :unprocessable_entity
41+
end
42+
3443
test "rejecting an unauthorized inbound email" do
3544
assert_no_difference -> { ActionMailbox::InboundEmail.count } do
3645
post rails_relay_inbound_emails_url, headers: { "Content-Type" => "message/rfc822" },

0 commit comments

Comments
 (0)