2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-10-01 03:04:02 -04:00
|
|
|
require_dependency 'jobs/regular/process_post'
|
2013-06-13 18:11:10 -04:00
|
|
|
|
|
|
|
describe Jobs::PollMailbox do
|
|
|
|
|
2016-01-18 18:57:55 -05:00
|
|
|
let(:poller) { Jobs::PollMailbox.new }
|
2013-06-13 18:11:10 -04:00
|
|
|
|
2014-04-09 13:26:19 -04:00
|
|
|
describe ".execute" do
|
|
|
|
|
2014-08-26 19:52:35 -04:00
|
|
|
it "does no polling if pop3_polling_enabled is false" do
|
2016-01-18 18:57:55 -05:00
|
|
|
SiteSetting.expects(:pop3_polling_enabled).returns(false)
|
2014-08-26 19:52:35 -04:00
|
|
|
poller.expects(:poll_pop3).never
|
2014-04-09 13:26:19 -04:00
|
|
|
poller.execute({})
|
|
|
|
end
|
|
|
|
|
2016-01-18 18:57:55 -05:00
|
|
|
it "polls when pop3_polling_enabled is true" do
|
|
|
|
SiteSetting.expects(:pop3_polling_enabled).returns(true)
|
|
|
|
poller.expects(:poll_pop3).once
|
|
|
|
poller.execute({})
|
2014-04-09 13:26:19 -04:00
|
|
|
end
|
2013-06-13 18:11:10 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-08-26 19:52:35 -04:00
|
|
|
describe ".poll_pop3" do
|
2014-04-09 13:26:19 -04:00
|
|
|
|
2016-04-06 02:59:48 -04:00
|
|
|
context "pop errors" do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Discourse.expects(:handle_job_exception).at_least_once
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2016-05-17 22:42:40 -04:00
|
|
|
$redis.del(Jobs::PollMailbox::POLL_MAILBOX_TIMEOUT_ERROR_KEY)
|
2016-04-06 02:59:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "add an admin dashboard message on pop authentication error" do
|
|
|
|
Net::POP3.any_instance.expects(:start)
|
|
|
|
.raises(Net::POPAuthenticationError.new).at_least_once
|
|
|
|
|
|
|
|
poller.poll_pop3
|
|
|
|
|
|
|
|
i18n_key = 'dashboard.poll_pop3_auth_error'
|
|
|
|
|
|
|
|
expect(AdminDashboardData.problem_message_check(i18n_key))
|
|
|
|
.to eq(I18n.t(i18n_key))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "logs an error on pop connection timeout error" do
|
|
|
|
Net::POP3.any_instance.expects(:start).raises(Net::OpenTimeout.new).at_least_once
|
|
|
|
|
|
|
|
4.times { poller.poll_pop3 }
|
|
|
|
|
|
|
|
i18n_key = 'dashboard.poll_pop3_timeout'
|
|
|
|
|
|
|
|
expect(AdminDashboardData.problem_message_check(i18n_key))
|
|
|
|
.to eq(I18n.t(i18n_key))
|
|
|
|
end
|
2014-04-09 13:26:19 -04:00
|
|
|
end
|
|
|
|
|
2014-08-26 20:00:27 -04:00
|
|
|
it "calls enable_ssl when the setting is enabled" do
|
|
|
|
SiteSetting.pop3_polling_ssl = true
|
|
|
|
Net::POP3.any_instance.stubs(:start)
|
|
|
|
Net::POP3.any_instance.expects(:enable_ssl)
|
|
|
|
poller.poll_pop3
|
|
|
|
end
|
|
|
|
|
2016-01-18 18:57:55 -05:00
|
|
|
it "does not call enable_ssl when the setting is disabled" do
|
2014-08-26 20:00:27 -04:00
|
|
|
SiteSetting.pop3_polling_ssl = false
|
|
|
|
Net::POP3.any_instance.stubs(:start)
|
|
|
|
Net::POP3.any_instance.expects(:enable_ssl).never
|
|
|
|
poller.poll_pop3
|
|
|
|
end
|
2014-04-09 13:26:19 -04:00
|
|
|
end
|
|
|
|
|
2016-04-07 10:21:17 -04:00
|
|
|
describe "#process_popmail" do
|
|
|
|
def process_popmail(email_name)
|
|
|
|
pop_mail = stub("pop mail")
|
|
|
|
pop_mail.expects(:pop).returns(email(email_name))
|
|
|
|
Jobs::PollMailbox.new.process_popmail(pop_mail)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not reply to a bounced email" do
|
|
|
|
expect { process_popmail(:bounced_email) }.to_not change { ActionMailer::Base.deliveries.count }
|
|
|
|
|
|
|
|
incoming_email = IncomingEmail.last
|
|
|
|
|
|
|
|
expect(incoming_email.rejection_message).to eq(
|
2016-05-16 06:22:03 -04:00
|
|
|
I18n.t("emails.incoming.errors.bounced_email_error")
|
2016-04-07 10:21:17 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-06-13 18:11:10 -04:00
|
|
|
end
|