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:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-25 19:31:46 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-25 19:32:06 +0300
commite92c90758eb4126acc84962d37bb273d6d87b27b (patch)
tree6d5f4ca9731a6aa76b80372276c68ab39e0f4149 /spec/lib/gitlab/email
parentb485c8c3723dc5aaba15ab9fa258010d1ec66d61 (diff)
Add latest changes from gitlab-org/security/gitlab@14-8-stable-ee
Diffstat (limited to 'spec/lib/gitlab/email')
-rw-r--r--spec/lib/gitlab/email/hook/validate_addresses_interceptor_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/lib/gitlab/email/hook/validate_addresses_interceptor_spec.rb b/spec/lib/gitlab/email/hook/validate_addresses_interceptor_spec.rb
new file mode 100644
index 00000000000..a3f0158db40
--- /dev/null
+++ b/spec/lib/gitlab/email/hook/validate_addresses_interceptor_spec.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Email::Hook::ValidateAddressesInterceptor do
+ describe 'UNSAFE_CHARACTERS' do
+ subject { described_class::UNSAFE_CHARACTERS }
+
+ it { is_expected.to match('\\') }
+ it { is_expected.to match("\x00") }
+ it { is_expected.to match("\x01") }
+ it { is_expected.not_to match('') }
+ it { is_expected.not_to match('user@example.com') }
+ it { is_expected.not_to match('foo-123+bar_456@example.com') }
+ end
+
+ describe '.delivering_email' do
+ let(:mail) do
+ ActionMailer::Base.mail(to: 'test@mail.com', from: 'info@mail.com', subject: 'title', body: 'hello')
+ end
+
+ let(:unsafe_email) { "evil+\x01$HOME@example.com" }
+
+ it 'sends emails to normal addresses' do
+ expect(Gitlab::AuthLogger).not_to receive(:info)
+ expect { mail.deliver_now }.to change(ActionMailer::Base.deliveries, :count)
+ end
+
+ [:from, :to, :cc, :bcc].each do |header|
+ it "does not send emails if the #{header.inspect} header contains unsafe characters" do
+ mail[header] = unsafe_email
+
+ expect(Gitlab::AuthLogger).to receive(:info).with(
+ message: 'Skipping email with unsafe characters in address',
+ address: unsafe_email,
+ subject: mail.subject
+ )
+
+ expect { mail.deliver_now }.not_to change(ActionMailer::Base.deliveries, :count)
+ end
+ end
+
+ [:reply_to].each do |header|
+ it "sends emails if the #{header.inspect} header contains unsafe characters" do
+ mail[header] = unsafe_email
+
+ expect(Gitlab::AuthLogger).not_to receive(:info)
+ expect { mail.deliver_now }.to change(ActionMailer::Base.deliveries, :count)
+ end
+ end
+ end
+end