Commit a0db8a39 authored by Sean McGivern's avatar Sean McGivern

Add feature flag for using Received header for incoming emails

This flag - use_received_header_for_incoming_emails - is enabled by
default, but it's there so we can disable it if needed.
parent 379a40bd
---
name: use_received_header_for_incoming_emails
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/81489
rollout_issue_url:
milestone: '14.9'
type: development
group: group::certify
default_enabled: true
......@@ -148,6 +148,8 @@ module Gitlab
end
def find_first_key_from_received_headers
return unless ::Feature.enabled?(:use_received_header_for_incoming_emails, default_enabled: :yaml)
recipients_from_received_headers.find do |email|
key = email_class.key_from_address(email)
break key if key
......
......@@ -38,6 +38,15 @@ RSpec.describe Gitlab::Email::Receiver do
end
end
shared_examples 'failed receive' do
it 'adds metric event' do
expect(::Gitlab::Metrics::BackgroundTransaction).to receive(:current).and_return(metric_transaction)
expect(metric_transaction).to receive(:add_event).with('email_receiver_error', { error: expected_error.name })
expect { receiver.execute }.to raise_error(expected_error)
end
end
context 'when the email contains a valid email address in a header' do
before do
stub_incoming_email_setting(enabled: true, address: "incoming+%{key}@appmail.example.com")
......@@ -75,21 +84,24 @@ RSpec.describe Gitlab::Email::Receiver do
it_behaves_like 'successful receive'
end
context 'when all other headers are missing, fall back to checking Received headers' do
context 'when all other headers are missing' do
let(:email_raw) { fixture_file('emails/missing_delivered_to_header.eml') }
let(:meta_key) { :received_recipients }
let(:meta_value) { ['incoming+gitlabhq/gitlabhq+auth_token@appmail.example.com', 'incoming+gitlabhq/gitlabhq@example.com'] }
it_behaves_like 'successful receive'
end
end
context 'when use_received_header_for_incoming_emails is enabled' do
it_behaves_like 'successful receive'
end
shared_examples 'failed receive' do
it 'adds metric event' do
expect(::Gitlab::Metrics::BackgroundTransaction).to receive(:current).and_return(metric_transaction)
expect(metric_transaction).to receive(:add_event).with('email_receiver_error', { error: expected_error.name })
context 'when use_received_header_for_incoming_emails is disabled' do
let(:expected_error) { Gitlab::Email::UnknownIncomingEmail }
expect { receiver.execute }.to raise_error(expected_error)
before do
stub_feature_flags(use_received_header_for_incoming_emails: false)
end
it_behaves_like 'failed receive'
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment