mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: when getting a reply by email, ensure it's by the same user
This commit is contained in:
@@ -262,6 +262,7 @@ This is a link http://example.com"
|
||||
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(:post) { create_post }
|
||||
let(:topic) { post.topic }
|
||||
@@ -286,7 +287,7 @@ This is a link http://example.com"
|
||||
|
||||
describe "valid_reply.eml" do
|
||||
let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
|
||||
let!(:email_raw) { fixture_file("emails/valid_reply.eml") }
|
||||
let!(:email_raw) { fill_email(fixture_file("emails/valid_reply.eml"), replying_user_email, to) }
|
||||
|
||||
it "creates a post with the correct content" do
|
||||
start_count = topic.posts.count
|
||||
@@ -296,7 +297,6 @@ This is a link http://example.com"
|
||||
expect(topic.posts.count).to eq(start_count + 1)
|
||||
created_post = topic.posts.last
|
||||
expect(created_post.via_email).to eq(true)
|
||||
expect(created_post.raw_email).to eq(fixture_file("emails/valid_reply.eml"))
|
||||
expect(created_post.cooked.strip).to eq(fixture_file("emails/valid_reply.cooked").strip)
|
||||
end
|
||||
end
|
||||
@@ -386,6 +386,7 @@ This is a link http://example.com"
|
||||
describe "posting reply to a closed topic" 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, closed: true) }
|
||||
let(:post) { Fabricate(:post, topic: topic, post_number: 1) }
|
||||
@@ -407,7 +408,7 @@ This is a link http://example.com"
|
||||
|
||||
describe "should not create post" do
|
||||
let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
|
||||
let!(:email_raw) { fixture_file("emails/valid_reply.eml") }
|
||||
let!(:email_raw) { fill_email(fixture_file("emails/valid_reply.eml"), replying_user_email, to) }
|
||||
it "raises a TopicClosedError" do
|
||||
expect { receiver.process }.to raise_error(Email::Receiver::TopicClosedError)
|
||||
end
|
||||
@@ -417,6 +418,7 @@ This is a link http://example.com"
|
||||
describe "posting reply to a deleted topic" 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(:deleted_topic) { Fabricate(:deleted_topic) }
|
||||
let(:post) { Fabricate(:post, topic: deleted_topic, post_number: 1) }
|
||||
@@ -438,7 +440,7 @@ This is a link http://example.com"
|
||||
|
||||
describe "should not create post" do
|
||||
let!(:reply_key) { '59d8df8370b7e95c5a49fbf86aeb2c93' }
|
||||
let!(:email_raw) { fixture_file("emails/valid_reply.eml") }
|
||||
let!(:email_raw) { fill_email(fixture_file("emails/valid_reply.eml"), replying_user_email, to) }
|
||||
it "raises a TopicNotFoundError" do
|
||||
expect { receiver.process }.to raise_error(Email::Receiver::TopicNotFoundError)
|
||||
end
|
||||
@@ -499,16 +501,16 @@ This is a link http://example.com"
|
||||
describe "with a valid email" do
|
||||
let(:reply_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" }
|
||||
let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) }
|
||||
let(:user_email) { "test@test.com" }
|
||||
let(:user) { Fabricate(:user, email: user_email, trust_level: 2)}
|
||||
let(:post) { create_post(user: user) }
|
||||
|
||||
let(:valid_reply) {
|
||||
reply = fixture_file("emails/valid_reply.eml")
|
||||
to = SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key)
|
||||
fill_email(reply, "test@test.com", to)
|
||||
fill_email(reply, user.email, to)
|
||||
}
|
||||
|
||||
let(:receiver) { Email::Receiver.new(valid_reply) }
|
||||
let(:post) { create_post }
|
||||
let(:user) { post.user }
|
||||
let(:email_log) { EmailLog.new(reply_key: reply_key,
|
||||
post_id: post.id,
|
||||
topic_id: post.topic_id,
|
||||
@@ -516,7 +518,7 @@ This is a link http://example.com"
|
||||
post: post,
|
||||
user: user,
|
||||
email_type: 'test',
|
||||
to_address: 'test@test.com'
|
||||
to_address: user.email
|
||||
) }
|
||||
let(:reply_body) {
|
||||
"I could not disagree more. I am obviously biased but adventure time is the
|
||||
@@ -527,7 +529,7 @@ greatest show ever created. Everyone should watch it.
|
||||
describe "with an email log" do
|
||||
|
||||
it "extracts data" do
|
||||
expect{ receiver.process }.to raise_error(Email::Receiver::EmailLogNotFound)
|
||||
expect { receiver.process }.to raise_error(Email::Receiver::EmailLogNotFound)
|
||||
|
||||
email_log.save!
|
||||
receiver.process
|
||||
@@ -540,6 +542,34 @@ greatest show ever created. Everyone should watch it.
|
||||
|
||||
end
|
||||
|
||||
describe "with a valid email from a different user" do
|
||||
let(:reply_key) { SecureRandom.hex(16) }
|
||||
let(:to) { SiteSetting.reply_by_email_address.gsub("%{reply_key}", reply_key) }
|
||||
let(:user) { Fabricate(:user, email: "test@test.com", trust_level: 2)}
|
||||
let(:post) { create_post(user: user) }
|
||||
let!(:email_log) { EmailLog.create(reply_key: reply_key,
|
||||
post_id: post.id,
|
||||
topic_id: post.topic_id,
|
||||
user_id: post.user_id,
|
||||
post: post,
|
||||
user: user,
|
||||
email_type: 'test',
|
||||
to_address: user.email) }
|
||||
|
||||
it "raises ReplyUserNotFoundError when user doesn't exist" do
|
||||
reply = fill_email(fixture_file("emails/valid_reply.eml"), "unknown@user.com", to)
|
||||
receiver = Email::Receiver.new(reply)
|
||||
expect { receiver.process }.to raise_error(Email::Receiver::ReplyUserNotFoundError)
|
||||
end
|
||||
|
||||
it "raises ReplyUserNotMatchingError when user is not matching the reply key" do
|
||||
another_user = Fabricate(:user, email: "existing@user.com")
|
||||
reply = fill_email(fixture_file("emails/valid_reply.eml"), another_user.email, to)
|
||||
receiver = Email::Receiver.new(reply)
|
||||
expect { receiver.process }.to raise_error(Email::Receiver::ReplyUserNotMatchingError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "processes an email to a category" do
|
||||
let(:to) { "some@email.com" }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user