Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/email/receiver_spec.rb')
-rw-r--r--spec/lib/gitlab/email/receiver_spec.rb58
1 files changed, 46 insertions, 12 deletions
diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb
index 9040731d8fd..79476c63e66 100644
--- a/spec/lib/gitlab/email/receiver_spec.rb
+++ b/spec/lib/gitlab/email/receiver_spec.rb
@@ -11,6 +11,7 @@ RSpec.describe Gitlab::Email::Receiver do
let_it_be(:project) { create(:project) }
let(:handler) { double(:handler, project: project, execute: true, metrics_event: nil, metrics_params: nil) }
+ let(:client_id) { 'email/jake@example.com' }
it 'correctly finds the mail key' do
expect(Gitlab::Email::Handler).to receive(:for).with(an_instance_of(Mail::Message), 'gitlabhq/gitlabhq+auth_token').and_return(handler)
@@ -33,7 +34,7 @@ RSpec.describe Gitlab::Email::Receiver do
metadata = receiver.mail_metadata
expect(metadata.keys).to match_array(%i(mail_uid from_address to_address mail_key references delivered_to envelope_to x_envelope_to meta received_recipients))
- expect(metadata[:meta]).to include(client_id: 'email/jake@example.com', project: project.full_path)
+ expect(metadata[:meta]).to include(client_id: client_id, project: project.full_path)
expect(metadata[meta_key]).to eq(meta_value)
end
end
@@ -89,19 +90,9 @@ RSpec.describe Gitlab::Email::Receiver do
let(:meta_key) { :received_recipients }
let(:meta_value) { ['incoming+gitlabhq/gitlabhq+auth_token@appmail.example.com', 'incoming+gitlabhq/gitlabhq@example.com'] }
- context 'when use_received_header_for_incoming_emails is enabled' do
+ describe 'it uses receive headers to find the key' do
it_behaves_like 'successful receive'
end
-
- context 'when use_received_header_for_incoming_emails is disabled' do
- let(:expected_error) { Gitlab::Email::UnknownIncomingEmail }
-
- before do
- stub_feature_flags(use_received_header_for_incoming_emails: false)
- end
-
- it_behaves_like 'failed receive'
- end
end
end
@@ -126,6 +117,49 @@ RSpec.describe Gitlab::Email::Receiver do
it_behaves_like 'failed receive'
end
+ context "when the email's To field is blank" do
+ before do
+ stub_incoming_email_setting(enabled: true, address: "incoming+%{key}@appmail.example.com")
+ end
+
+ let(:email_raw) do
+ <<~EMAIL
+ Delivered-To: incoming+gitlabhq/gitlabhq+auth_token@appmail.example.com
+ From: "jake@example.com" <jake@example.com>
+ Bcc: "support@example.com" <support@example.com>
+
+ Email content
+ EMAIL
+ end
+
+ let(:meta_key) { :delivered_to }
+ let(:meta_value) { ["incoming+gitlabhq/gitlabhq+auth_token@appmail.example.com"] }
+
+ it_behaves_like 'successful receive'
+ end
+
+ context "when the email's From field is blank" do
+ before do
+ stub_incoming_email_setting(enabled: true, address: "incoming+%{key}@appmail.example.com")
+ end
+
+ let(:email_raw) do
+ <<~EMAIL
+ Delivered-To: incoming+gitlabhq/gitlabhq+auth_token@appmail.example.com
+ To: "support@example.com" <support@example.com>
+
+ Email content
+ EMAIL
+ end
+
+ let(:meta_key) { :delivered_to }
+ let(:meta_value) { ["incoming+gitlabhq/gitlabhq+auth_token@appmail.example.com"] }
+
+ it_behaves_like 'successful receive' do
+ let(:client_id) { 'email/' }
+ end
+ end
+
context 'when the email was auto generated with X-Autoreply header' do
let(:email_raw) { fixture_file('emails/auto_reply.eml') }
let(:expected_error) { Gitlab::Email::AutoGeneratedEmailError }