FIX: Return `nil` when the `reply_key` is missing

This commit is contained in:
Robin Ward 2017-06-08 14:28:48 -04:00
parent 6997925a52
commit 602e4d0da4
2 changed files with 23 additions and 0 deletions

View File

@ -346,6 +346,7 @@ module Email
return { type: :reply, obj: email_log } if email_log
end
end
nil
end
def process_destination(destination, user, body, elided)

View File

@ -555,4 +555,26 @@ describe Email::Receiver do
end
context "check_address" do
before do
SiteSetting.reply_by_email_address = "foo+%{reply_key}@bar.com"
end
it "returns nil when the key is invalid" do
expect(Email::Receiver.check_address('fake@fake.com')).to be_nil
expect(Email::Receiver.check_address('foo+4f97315cc828096c9cb34c6f1a0d6fe8@bar.com')).to be_nil
end
context "with a valid reply" do
it "returns the destination when the key is valid" do
Fabricate(:email_log, reply_key: '4f97315cc828096c9cb34c6f1a0d6fe8')
dest = Email::Receiver.check_address('foo+4f97315cc828096c9cb34c6f1a0d6fe8@bar.com')
expect(dest).to be_present
expect(dest[:type]).to eq(:reply)
expect(dest[:obj]).to be_present
end
end
end
end