FIX: use MD5 of the email_string when there's no 'Message-Id'

This commit is contained in:
Régis Hanol
2016-03-14 18:18:58 +01:00
parent 1ba65765e4
commit 4a3cb4a000
5 changed files with 13 additions and 20 deletions

View File

@ -21,14 +21,6 @@ describe Email::Receiver do
expect { Email::Receiver.new("") }.to raise_error(Email::Receiver::EmptyEmailError)
end
it "raises an NoMessageIdError when 'mail_string' is not an email" do
expect { Email::Receiver.new("wat") }.to raise_error(Email::Receiver::NoMessageIdError)
end
it "raises an NoMessageIdError when 'mail_string' is missing the message_id" do
expect { Email::Receiver.new(email(:missing_message_id)) }.to raise_error(Email::Receiver::NoMessageIdError)
end
it "raises an AutoGeneratedEmailError when the mail is auto generated" do
expect { process(:auto_generated_precedence) }.to raise_error(Email::Receiver::AutoGeneratedEmailError)
expect { process(:auto_generated_header) }.to raise_error(Email::Receiver::AutoGeneratedEmailError)
@ -65,6 +57,12 @@ describe Email::Receiver do
let(:post) { create_post(topic: topic, user: user) }
let!(:email_log) { Fabricate(:email_log, reply_key: reply_key, user: user, topic: topic, post: post) }
it "uses MD5 of 'mail_string' there is no message_id" do
mail_string = email(:missing_message_id)
expect { Email::Receiver.new(mail_string).process! }.to change { IncomingEmail.count }
expect(IncomingEmail.last.message_id).to eq(Digest::MD5.hexdigest(mail_string))
end
it "raises a ReplyUserNotMatchingError when the email address isn't matching the one we sent the notification to" do
expect { process(:reply_user_not_matching) }.to raise_error(Email::Receiver::ReplyUserNotMatchingError)
end