diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 09:16:11 +0000 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /spec/lib/gitlab/email/failure_handler_spec.rb | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) | |
download | gitlab-ce-edaa33dee2ff2f7ea3fac488d41558eb5f86d68c.tar.gz |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'spec/lib/gitlab/email/failure_handler_spec.rb')
-rw-r--r-- | spec/lib/gitlab/email/failure_handler_spec.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/lib/gitlab/email/failure_handler_spec.rb b/spec/lib/gitlab/email/failure_handler_spec.rb new file mode 100644 index 00000000000..a912996e8f2 --- /dev/null +++ b/spec/lib/gitlab/email/failure_handler_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Email::FailureHandler do + let(:raw_message) { fixture_file('emails/valid_reply.eml') } + let(:receiver) { Gitlab::Email::Receiver.new(raw_message) } + + context 'email processing errors' do + where(:error, :message, :can_retry) do + [ + [Gitlab::Email::UnknownIncomingEmail, "We couldn't figure out what the email is for", false], + [Gitlab::Email::SentNotificationNotFoundError, "We couldn't figure out what the email is in reply to", false], + [Gitlab::Email::ProjectNotFound, "We couldn't find the project", false], + [Gitlab::Email::EmptyEmailError, "It appears that the email is blank", true], + [Gitlab::Email::UserNotFoundError, "We couldn't figure out what user corresponds to the email", false], + [Gitlab::Email::UserBlockedError, "Your account has been blocked", false], + [Gitlab::Email::UserNotAuthorizedError, "You are not allowed to perform this action", false], + [Gitlab::Email::NoteableNotFoundError, "The thread you are replying to no longer exists", false], + [Gitlab::Email::InvalidAttachment, "Could not deal with that", false], + [Gitlab::Email::InvalidRecordError, "The note could not be created for the following reasons", true], + [Gitlab::Email::EmailTooLarge, "it is too large", false] + ] + end + + with_them do + it "sends out a rejection email for #{params[:error]}" do + perform_enqueued_jobs do + described_class.handle(receiver, error.new(message)) + end + + email = ActionMailer::Base.deliveries.last + expect(email).not_to be_nil + expect(email.to).to match_array(["jake@adventuretime.ooo"]) + expect(email.subject).to include("Rejected") + expect(email.body.parts.last.to_s).to include(message) + end + + it 'strips out the body before passing to EmailRejectionMailer' do + mail = Mail.new(raw_message) + mail.body = nil + + expect(EmailRejectionMailer).to receive(:rejection).with(match(message), mail.encoded, can_retry).and_call_original + + described_class.handle(receiver, error.new(message)) + end + end + end + + context 'non-processing errors' do + where(:error) do + [ + [Gitlab::Email::AutoGeneratedEmailError.new("")], + [ActiveRecord::StatementTimeout.new("StatementTimeout")], + [RateLimitedService::RateLimitedError.new(key: :issues_create, rate_limiter: nil)] + ] + end + + with_them do + it "does not send a rejection email for #{params[:error]}" do + perform_enqueued_jobs do + described_class.handle(receiver, error) + end + + expect(ActionMailer::Base.deliveries).to be_empty + end + end + end +end |