Skip to content

Commit

Permalink
FIX: ensure inactive users can't email in
Browse files Browse the repository at this point in the history
  • Loading branch information
ZogStriP committed Dec 21, 2015
1 parent b3198d7 commit 3e923c7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/email/receiver.rb
Expand Up @@ -20,6 +20,7 @@ class EmailLogNotFound < ProcessingError; end
class InvalidPost < ProcessingError; end
class ReplyUserNotFoundError < ProcessingError; end
class ReplyUserNotMatchingError < ProcessingError; end
class InactiveUserError < ProcessingError; end

attr_reader :body, :email_log

Expand Down Expand Up @@ -58,8 +59,8 @@ def process
user_email = from.address
user_name = from.display_name

# TODO: deal with suspended/inactive users
user = User.find_by_email(user_email)
raise InactiveUserError if user.present? && !user.active && !user.staged

# TODO: take advantage of all the "TO"s
dest_info = dest_infos[0]
Expand Down
32 changes: 32 additions & 0 deletions spec/components/email/receiver_spec.rb
Expand Up @@ -447,6 +447,38 @@ def test_parse_body(mail_string)
end
end

describe "posting reply as a inactive user" do
let(:reply_key) { raise "Override this in a lower describe block" }
let(:email_raw) { raise "Override this in a lower describe block" }
let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) }
let(:receiver) { Email::Receiver.new(email_raw) }
let(:topic) { Fabricate(:topic) }
let(:post) { Fabricate(:post, topic: topic, post_number: 1) }
let(:replying_user_email) { 'jake@adventuretime.ooo' }
let(:replying_user) { Fabricate(:user, email: replying_user_email, trust_level: 2, active: false) }
let(:email_log) { EmailLog.new(reply_key: reply_key,
post: post,
post_id: post.id,
topic_id: topic.id,
email_type: 'user_posted',
user: replying_user,
user_id: replying_user.id,
to_address: replying_user_email
) }

before do
email_log.save
end

describe "should not create post" do
let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
let!(:email_raw) { fill_email(fixture_file("emails/valid_reply.eml"), replying_user_email, to) }
it "raises a InactiveUserError" do
expect { receiver.process }.to raise_error(Email::Receiver::InactiveUserError)
end
end
end

describe "posting a new topic in a category" do
let(:category_destination) { raise "Override this in a lower describe block" }
let(:email_raw) { raise "Override this in a lower describe block" }
Expand Down

0 comments on commit 3e923c7

Please sign in to comment.