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 <zzakscott@gmail.com>
This commit is contained in:
Hartley McGuire 2024-06-26 21:41:21 -04:00 committed by Rafael Mendonça França
parent cd3d94a48a
commit b5b5835aef
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
2 changed files with 14 additions and 1 deletions

View File

@ -52,7 +52,11 @@ module ActionMailbox
before_action :authenticate_by_password, :require_valid_rfc822_message
def create
ActionMailbox::InboundEmail.create_and_extract_message_id! request.body.read
if request.body
ActionMailbox::InboundEmail.create_and_extract_message_id! request.body.read
else
head :unprocessable_entity
end
end
private

View File

@ -31,6 +31,15 @@ class ActionMailbox::Ingresses::Relay::InboundEmailsControllerTest < ActionDispa
assert_equal "05988AA6EC0D44318855A5E39E3B6F9E@jansterba.com", inbound_email.message_id
end
test "rejecting a request with no body" do
assert_no_difference -> { ActionMailbox::InboundEmail.count } do
post rails_relay_inbound_emails_url, headers: { "Authorization" => credentials, "Content-Type" => "message/rfc822" },
env: { "rack.input" => nil }
end
assert_response :unprocessable_entity
end
test "rejecting an unauthorized inbound email" do
assert_no_difference -> { ActionMailbox::InboundEmail.count } do
post rails_relay_inbound_emails_url, headers: { "Content-Type" => "message/rfc822" },