diff options
Diffstat (limited to 'spec/services/service_desk')
4 files changed, 84 insertions, 61 deletions
diff --git a/spec/services/service_desk/custom_email_verifications/create_service_spec.rb b/spec/services/service_desk/custom_email_verifications/create_service_spec.rb index 0046213e0b2..03c5743434e 100644 --- a/spec/services/service_desk/custom_email_verifications/create_service_spec.rb +++ b/spec/services/service_desk/custom_email_verifications/create_service_spec.rb @@ -14,7 +14,6 @@ RSpec.describe ServiceDesk::CustomEmailVerifications::CreateService, feature_cat let(:service) { described_class.new(project: project, current_user: user) } - let(:error_feature_flag_disabled) { 'Feature flag service_desk_custom_email is not enabled' } let(:error_user_not_authorized) { s_('ServiceDesk|User cannot manage project.') } let(:error_settings_missing) { s_('ServiceDesk|Service Desk setting missing') } let(:expected_error_message) { error_settings_missing } @@ -45,7 +44,7 @@ RSpec.describe ServiceDesk::CustomEmailVerifications::CreateService, feature_cat end end - shared_examples 'a verification process with ramp up error' do |error, error_identifier| + shared_examples 'a verification process with ramp up error' do it 'aborts verification process', :aggregate_failures do allow(message).to receive(:deliver).and_raise(error) @@ -80,16 +79,6 @@ RSpec.describe ServiceDesk::CustomEmailVerifications::CreateService, feature_cat it_behaves_like 'a verification process that exits early' - context 'when feature flag :service_desk_custom_email is disabled' do - let(:expected_error_message) { error_feature_flag_disabled } - - before do - stub_feature_flags(service_desk_custom_email: false) - end - - it_behaves_like 'a verification process that exits early' - end - context 'when service desk setting exists' do let(:settings) { create(:service_desk_setting, project: project, custom_email: 'user@example.com') } let(:service) { described_class.new(project: settings.project, current_user: user) } @@ -115,7 +104,7 @@ RSpec.describe ServiceDesk::CustomEmailVerifications::CreateService, feature_cat end context 'when user has maintainer role in project' do - before do + before_all do project.add_maintainer(user) end @@ -151,10 +140,25 @@ RSpec.describe ServiceDesk::CustomEmailVerifications::CreateService, feature_cat allow(Notify).to receive(:service_desk_verification_result_email).and_return(message_delivery) end - it_behaves_like 'a verification process with ramp up error', SocketError, 'smtp_host_issue' - it_behaves_like 'a verification process with ramp up error', OpenSSL::SSL::SSLError, 'smtp_host_issue' - it_behaves_like 'a verification process with ramp up error', - Net::SMTPAuthenticationError.new('Invalid username or password'), 'invalid_credentials' + it_behaves_like 'a verification process with ramp up error' do + let(:error) { SocketError } + let(:error_identifier) { 'smtp_host_issue' } + end + + it_behaves_like 'a verification process with ramp up error' do + let(:error) { OpenSSL::SSL::SSLError } + let(:error_identifier) { 'smtp_host_issue' } + end + + it_behaves_like 'a verification process with ramp up error' do + let(:error) { Net::SMTPAuthenticationError.new('Invalid username or password') } + let(:error_identifier) { 'invalid_credentials' } + end + + it_behaves_like 'a verification process with ramp up error' do + let(:error) { Net::ReadTimeout } + let(:error_identifier) { 'read_timeout' } + end end end end diff --git a/spec/services/service_desk/custom_email_verifications/update_service_spec.rb b/spec/services/service_desk/custom_email_verifications/update_service_spec.rb index f87952d1d0e..103caf0e6c5 100644 --- a/spec/services/service_desk/custom_email_verifications/update_service_spec.rb +++ b/spec/services/service_desk/custom_email_verifications/update_service_spec.rb @@ -14,7 +14,6 @@ RSpec.describe ServiceDesk::CustomEmailVerifications::UpdateService, feature_cat let(:message_delivery) { instance_double(ActionMailer::MessageDelivery) } let(:service) { described_class.new(project: settings.project, params: { mail: mail_object }) } - let(:error_feature_flag_disabled) { 'Feature flag service_desk_custom_email is not enabled' } let(:error_parameter_missing) { s_('ServiceDesk|Service Desk setting or verification object missing') } let(:error_already_finished) { s_('ServiceDesk|Custom email address has already been verified.') } let(:error_already_failed) do @@ -28,6 +27,9 @@ RSpec.describe ServiceDesk::CustomEmailVerifications::UpdateService, feature_cat before do allow(message_delivery).to receive(:deliver_later) allow(Notify).to receive(:service_desk_verification_result_email).and_return(message_delivery) + + stub_incoming_email_setting(enabled: true, address: 'support+%{key}@example.com') + stub_service_desk_email_setting(enabled: true, address: 'contact+%{key}@example.com') end shared_examples 'a failing verification process' do |expected_error_identifier| @@ -86,26 +88,6 @@ RSpec.describe ServiceDesk::CustomEmailVerifications::UpdateService, feature_cat expect(settings).not_to be_custom_email_enabled end - context 'when feature flag :service_desk_custom_email is disabled' do - let(:expected_error_message) { error_feature_flag_disabled } - - before do - stub_feature_flags(service_desk_custom_email: false) - end - - it 'exits early' do - expect(Notify).to receive(:service_desk_verification_result_email).exactly(0).times - - expect(Gitlab::AppLogger).to receive(:warn).with(logger_params.merge( - error_message: expected_error_message - )).once - - response = service.execute - - expect(response).to be_error - end - end - context 'when verification exists' do let!(:verification) { create(:service_desk_custom_email_verification, project: project) } @@ -139,7 +121,34 @@ RSpec.describe ServiceDesk::CustomEmailVerifications::UpdateService, feature_cat verification.update!(token: 'ZROT4ZZXA-Y6') # token from email fixture end - let(:email_raw) { email_fixture('emails/service_desk_custom_email_address_verification.eml') } + let(:service_desk_address) { project.service_desk_incoming_address } + let(:verification_address) { 'custom-support-email+verify@example.com' } + let(:verification_token) { 'ZROT4ZZXA-Y6' } + let(:shared_email_raw) do + <<~EMAIL + From: Flight Support <custom-support-email@example.com> + Subject: Verify custom email address custom-support-email@example.com for Flight + Auto-Submitted: no + + + This email is auto-generated. It verifies the ownership of the entered Service Desk custom email address and + correct functionality of email forwarding. + + Verification token: #{verification_token} + -- + + You're receiving this email because of your account on 127.0.0.1. + EMAIL + end + + let(:email_raw) do + <<~EMAIL + Delivered-To: #{service_desk_address} + To: #{verification_address} + #{shared_email_raw} + EMAIL + end + let(:mail_object) { Mail::Message.new(email_raw) } it 'verifies and sends result emails' do @@ -181,6 +190,38 @@ RSpec.describe ServiceDesk::CustomEmailVerifications::UpdateService, feature_cat it_behaves_like 'a failing verification process', 'mail_not_received_within_timeframe' end + context 'and service desk address from service_desk_email was used as forwarding target' do + let(:service_desk_address) { project.service_desk_alias_address } + + it_behaves_like 'a failing verification process', 'incorrect_forwarding_target' + + context 'when multiple Delivered-To headers are present' do + let(:email_raw) do + <<~EMAIL + Delivered-To: other@example.com + Delivered-To: #{service_desk_address} + To: #{verification_address} + #{shared_email_raw} + EMAIL + end + + it_behaves_like 'a failing verification process', 'incorrect_forwarding_target' + end + + context 'when multiple To headers are present' do + # Microsoft Exchange forwards emails this way when forwarding + # to an external email address using a transport rule + let(:email_raw) do + <<~EMAIL + To: #{service_desk_address}, #{verification_address} + #{shared_email_raw} + EMAIL + end + + it_behaves_like 'a failing verification process', 'incorrect_forwarding_target' + end + end + context 'when already verified' do let(:expected_error_message) { error_already_finished } diff --git a/spec/services/service_desk/custom_emails/create_service_spec.rb b/spec/services/service_desk/custom_emails/create_service_spec.rb index e165131bcf9..a015817b380 100644 --- a/spec/services/service_desk/custom_emails/create_service_spec.rb +++ b/spec/services/service_desk/custom_emails/create_service_spec.rb @@ -8,7 +8,6 @@ RSpec.describe ServiceDesk::CustomEmails::CreateService, feature_category: :serv let_it_be(:user) { create(:user) } let(:service) { described_class.new(project: project, current_user: user, params: params) } - let(:error_feature_flag_disabled) { 'Feature flag service_desk_custom_email is not enabled' } let(:error_user_not_authorized) { s_('ServiceDesk|User cannot manage project.') } let(:error_cannot_create_custom_email) { s_('ServiceDesk|Cannot create custom email') } let(:error_custom_email_exists) { s_('ServiceDesk|Custom email already exists') } @@ -52,16 +51,6 @@ RSpec.describe ServiceDesk::CustomEmails::CreateService, feature_category: :serv end end - context 'when feature flag service_desk_custom_email is disabled' do - let(:expected_error_message) { error_feature_flag_disabled } - - before do - stub_feature_flags(service_desk_custom_email: false) - end - - it_behaves_like 'a service that exits with error' - end - context 'with illegitimate user' do let(:expected_error_message) { error_user_not_authorized } diff --git a/spec/services/service_desk/custom_emails/destroy_service_spec.rb b/spec/services/service_desk/custom_emails/destroy_service_spec.rb index 7f53a941d4e..d77e408c31b 100644 --- a/spec/services/service_desk/custom_emails/destroy_service_spec.rb +++ b/spec/services/service_desk/custom_emails/destroy_service_spec.rb @@ -8,7 +8,6 @@ RSpec.describe ServiceDesk::CustomEmails::DestroyService, feature_category: :ser let(:user) { build_stubbed(:user) } let(:service) { described_class.new(project: project, current_user: user) } - let(:error_feature_flag_disabled) { 'Feature flag service_desk_custom_email is not enabled' } let(:error_user_not_authorized) { s_('ServiceDesk|User cannot manage project.') } let(:error_does_not_exist) { s_('ServiceDesk|Custom email does not exist') } let(:expected_error_message) { nil } @@ -45,16 +44,6 @@ RSpec.describe ServiceDesk::CustomEmails::DestroyService, feature_category: :ser end end - context 'when feature flag service_desk_custom_email is disabled' do - let(:expected_error_message) { error_feature_flag_disabled } - - before do - stub_feature_flags(service_desk_custom_email: false) - end - - it_behaves_like 'a service that exits with error' - end - context 'with illegitimate user' do let(:expected_error_message) { error_user_not_authorized } |