summaryrefslogtreecommitdiff
path: root/vendor/gems
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 23:50:22 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 23:50:22 +0000
commit9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch)
tree70467ae3692a0e35e5ea56bcb803eb512a10bedb /vendor/gems
parent4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff)
downloadgitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'vendor/gems')
-rw-r--r--vendor/gems/mail-smtp_pool/.gitignore3
-rw-r--r--vendor/gems/mail-smtp_pool/.gitlab-ci.yml29
-rw-r--r--vendor/gems/mail-smtp_pool/Gemfile5
-rw-r--r--vendor/gems/mail-smtp_pool/LICENSE21
-rw-r--r--vendor/gems/mail-smtp_pool/README.md57
-rw-r--r--vendor/gems/mail-smtp_pool/lib/mail/smtp_pool.rb34
-rw-r--r--vendor/gems/mail-smtp_pool/lib/mail/smtp_pool/connection.rb60
-rw-r--r--vendor/gems/mail-smtp_pool/mail-smtp_pool.gemspec26
-rw-r--r--vendor/gems/mail-smtp_pool/spec/lib/mail/smtp_pool/connection_spec.rb93
-rw-r--r--vendor/gems/mail-smtp_pool/spec/lib/mail/smtp_pool_spec.rb68
-rw-r--r--vendor/gems/mail-smtp_pool/spec/spec_helper.rb84
11 files changed, 480 insertions, 0 deletions
diff --git a/vendor/gems/mail-smtp_pool/.gitignore b/vendor/gems/mail-smtp_pool/.gitignore
new file mode 100644
index 00000000000..1fbdf80cd36
--- /dev/null
+++ b/vendor/gems/mail-smtp_pool/.gitignore
@@ -0,0 +1,3 @@
+Gemfile.lock
+*.gem
+.bundle
diff --git a/vendor/gems/mail-smtp_pool/.gitlab-ci.yml b/vendor/gems/mail-smtp_pool/.gitlab-ci.yml
new file mode 100644
index 00000000000..56eff5b30a7
--- /dev/null
+++ b/vendor/gems/mail-smtp_pool/.gitlab-ci.yml
@@ -0,0 +1,29 @@
+workflow:
+ rules:
+ - if: $CI_MERGE_REQUEST_ID
+
+.rspec:
+ cache:
+ key: mail-smtp_pool-ruby
+ paths:
+ - vendor/gems/mail-smtp_pool/vendor/ruby
+ before_script:
+ - cd vendor/gems/mail-smtp_pool
+ - ruby -v # Print out ruby version for debugging
+ - gem install bundler --no-document # Bundler is not installed with the image
+ - bundle config set --local path 'vendor' # Install dependencies into ./vendor/ruby
+ - bundle install -j $(nproc)
+ script:
+ - bundle exec rspec
+
+rspec-2.6:
+ image: "ruby:2.6"
+ extends: .rspec
+
+rspec-2.7:
+ image: "ruby:2.7"
+ extends: .rspec
+
+rspec-3.0:
+ image: "ruby:3.0"
+ extends: .rspec
diff --git a/vendor/gems/mail-smtp_pool/Gemfile b/vendor/gems/mail-smtp_pool/Gemfile
new file mode 100644
index 00000000000..7f4f5e950d1
--- /dev/null
+++ b/vendor/gems/mail-smtp_pool/Gemfile
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+source 'https://rubygems.org'
+
+gemspec
diff --git a/vendor/gems/mail-smtp_pool/LICENSE b/vendor/gems/mail-smtp_pool/LICENSE
new file mode 100644
index 00000000000..e6de2f90864
--- /dev/null
+++ b/vendor/gems/mail-smtp_pool/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016-2021 GitLab B.V.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/vendor/gems/mail-smtp_pool/README.md b/vendor/gems/mail-smtp_pool/README.md
new file mode 100644
index 00000000000..bdb2be97663
--- /dev/null
+++ b/vendor/gems/mail-smtp_pool/README.md
@@ -0,0 +1,57 @@
+# Mail::SMTPPool
+
+This gem is an extension to `Mail` that allows delivery of emails using an SMTP connection pool
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+```ruby
+gem 'mail-smtp_pool'
+```
+
+And then execute:
+
+```shell
+bundle
+```
+
+Or install it yourself as:
+
+```shell
+gem install mail-smtp_pool
+```
+
+## Usage with ActionMailer
+
+```ruby
+# config/environments/development.rb
+
+Rails.application.configure do
+ ...
+
+ ActionMailer::Base.add_delivery_method :smtp_pool, Mail::SMTPPool
+
+ config.action_mailer.perform_deliveries = true
+ config.action_mailer.smtp_pool_settings = {
+ pool: Mail::SMTPPool.create_pool(
+ pool_size: 5,
+ pool_timeout: 5,
+ address: 'smtp.gmail.com',
+ port: 587,
+ domain: 'example.com',
+ user_name: '<username>',
+ password: '<password>',
+ authentication: 'plain',
+ enable_starttls_auto: true
+ )
+ }
+end
+```
+
+Configuration options:
+
+* `pool_size` - The maximum number of SMTP connections in the pool. Connections are created lazily as needed.
+* `pool_timeout` - The number of seconds to wait for a connection in the pool to be available. A `Timeout::Error` exception is raised when this is exceeded.
+
+This also accepts all options supported by `Mail::SMTP`. See https://www.rubydoc.info/gems/mail/2.6.1/Mail/SMTP for more information.
diff --git a/vendor/gems/mail-smtp_pool/lib/mail/smtp_pool.rb b/vendor/gems/mail-smtp_pool/lib/mail/smtp_pool.rb
new file mode 100644
index 00000000000..ab8a7652058
--- /dev/null
+++ b/vendor/gems/mail-smtp_pool/lib/mail/smtp_pool.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require 'connection_pool'
+require 'mail/smtp_pool/connection'
+
+module Mail
+ class SMTPPool
+ POOL_DEFAULTS = {
+ pool_size: 5,
+ pool_timeout: 5
+ }.freeze
+
+ class << self
+ def create_pool(settings = {})
+ pool_settings = POOL_DEFAULTS.merge(settings)
+ smtp_settings = settings.reject { |k, v| POOL_DEFAULTS.keys.include?(k) }
+
+ ConnectionPool.new(size: pool_settings[:pool_size], timeout: pool_settings[:pool_timeout]) do
+ Mail::SMTPPool::Connection.new(smtp_settings)
+ end
+ end
+ end
+
+ def initialize(settings)
+ raise ArgumentError, 'pool is required. You can create one using Mail::SMTPPool.create_pool.' if settings[:pool].nil?
+
+ @pool = settings[:pool]
+ end
+
+ def deliver!(mail)
+ @pool.with { |conn| conn.deliver!(mail) }
+ end
+ end
+end
diff --git a/vendor/gems/mail-smtp_pool/lib/mail/smtp_pool/connection.rb b/vendor/gems/mail-smtp_pool/lib/mail/smtp_pool/connection.rb
new file mode 100644
index 00000000000..ab0d20153d8
--- /dev/null
+++ b/vendor/gems/mail-smtp_pool/lib/mail/smtp_pool/connection.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+# A connection object that can be used to deliver mail.
+#
+# This is meant to be used in a pool so the main difference between this
+# and Mail::SMTP is that this expects deliver! to be called multiple times.
+#
+# SMTP connection reset and error handling is handled by this class and
+# the SMTP connection is not closed after a delivery.
+
+require 'mail'
+
+module Mail
+ class SMTPPool
+ class Connection < Mail::SMTP
+ def initialize(values)
+ super
+
+ @smtp_session = nil
+ end
+
+ def deliver!(mail)
+ response = Mail::SMTPConnection.new(connection: smtp_session, return_response: true).deliver!(mail)
+
+ settings[:return_response] ? response : self
+ end
+
+ def finish
+ finish_smtp_session if @smtp_session && @smtp_session.started?
+ end
+
+ private
+
+ def smtp_session
+ return start_smtp_session if @smtp_session.nil? || !@smtp_session.started?
+ return @smtp_session if reset_smtp_session
+
+ finish_smtp_session
+ start_smtp_session
+ end
+
+ def start_smtp_session
+ @smtp_session = build_smtp_session.start(settings[:domain], settings[:user_name], settings[:password], settings[:authentication])
+ end
+
+ def reset_smtp_session
+ !@smtp_session.instance_variable_get(:@error_occurred) && @smtp_session.rset.success?
+ rescue Net::SMTPError, IOError
+ false
+ end
+
+ def finish_smtp_session
+ @smtp_session.finish
+ rescue Net::SMTPError, IOError
+ ensure
+ @smtp_session = nil
+ end
+ end
+ end
+end
diff --git a/vendor/gems/mail-smtp_pool/mail-smtp_pool.gemspec b/vendor/gems/mail-smtp_pool/mail-smtp_pool.gemspec
new file mode 100644
index 00000000000..3d9036f19b1
--- /dev/null
+++ b/vendor/gems/mail-smtp_pool/mail-smtp_pool.gemspec
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+lib = File.expand_path('lib', __dir__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+
+Gem::Specification.new do |spec|
+ spec.name = 'mail-smtp_pool'
+ spec.version = '0.1.0'
+ spec.authors = ['Heinrich Lee Yu']
+ spec.email = ['heinrich@gitlab.com']
+
+ spec.summary = 'Mail extension for sending using an SMTP connection pool'
+ spec.homepage = 'https://gitlab.com/gitlab-org/gitlab/-/tree/master/vendor/gems/mail-smtp_pool'
+ spec.metadata = { 'source_code_uri' => 'https://gitlab.com/gitlab-org/gitlab/-/tree/master/vendor/gems/mail-smtp_pool' }
+ spec.license = 'MIT'
+
+ spec.files = Dir['lib/**/*.rb']
+ spec.require_paths = ['lib']
+
+ # Please maintain alphabetical order for dependencies
+ spec.add_runtime_dependency 'connection_pool', '~> 2.0'
+ spec.add_runtime_dependency 'mail', '~> 2.7'
+
+ # Please maintain alphabetical order for dev dependencies
+ spec.add_development_dependency 'rspec', '~> 3.10.0'
+end
diff --git a/vendor/gems/mail-smtp_pool/spec/lib/mail/smtp_pool/connection_spec.rb b/vendor/gems/mail-smtp_pool/spec/lib/mail/smtp_pool/connection_spec.rb
new file mode 100644
index 00000000000..78426296406
--- /dev/null
+++ b/vendor/gems/mail-smtp_pool/spec/lib/mail/smtp_pool/connection_spec.rb
@@ -0,0 +1,93 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Mail::SMTPPool::Connection do
+ let(:connection) { described_class.new({}) }
+ let(:mail) do
+ Mail.new do
+ from 'mikel@test.lindsaar.net'
+ to 'you@test.lindsaar.net'
+ subject 'This is a test email'
+ body 'Test body'
+ end
+ end
+
+ after do
+ MockSMTP.clear_deliveries
+ end
+
+ describe '#deliver!' do
+ it 'delivers mail using the same SMTP connection' do
+ mock_smtp = MockSMTP.new
+
+ expect(Net::SMTP).to receive(:new).once.and_return(mock_smtp)
+ expect(mock_smtp).to receive(:sendmail).twice.and_call_original
+ expect(mock_smtp).to receive(:rset).once.and_call_original
+
+ connection.deliver!(mail)
+ connection.deliver!(mail)
+
+ expect(MockSMTP.deliveries.size).to eq(2)
+ end
+
+ context 'when RSET fails' do
+ let(:mock_smtp) { MockSMTP.new }
+ let(:mock_smtp_2) { MockSMTP.new }
+
+ before do
+ expect(Net::SMTP).to receive(:new).twice.and_return(mock_smtp, mock_smtp_2)
+ end
+
+ context 'with an IOError' do
+ before do
+ expect(mock_smtp).to receive(:rset).once.and_raise(IOError)
+ end
+
+ it 'creates a new SMTP connection' do
+ expect(mock_smtp).to receive(:sendmail).once.and_call_original
+ expect(mock_smtp).to receive(:finish).once.and_call_original
+ expect(mock_smtp_2).to receive(:sendmail).once.and_call_original
+
+ connection.deliver!(mail)
+ connection.deliver!(mail)
+
+ expect(MockSMTP.deliveries.size).to eq(2)
+ end
+ end
+
+ context 'with an SMTP error' do
+ before do
+ expect(mock_smtp).to receive(:rset).once.and_raise(Net::SMTPServerBusy)
+ end
+
+ it 'creates a new SMTP connection' do
+ expect(mock_smtp).to receive(:sendmail).once.and_call_original
+ expect(mock_smtp).to receive(:finish).once.and_call_original
+ expect(mock_smtp_2).to receive(:sendmail).once.and_call_original
+
+ connection.deliver!(mail)
+ connection.deliver!(mail)
+
+ expect(MockSMTP.deliveries.size).to eq(2)
+ end
+
+ context 'and closing the old connection fails' do
+ before do
+ expect(mock_smtp).to receive(:finish).once.and_raise(IOError)
+ end
+
+ it 'creates a new SMTP connection' do
+ expect(mock_smtp).to receive(:sendmail).once.and_call_original
+ expect(mock_smtp_2).to receive(:sendmail).once.and_call_original
+
+ connection.deliver!(mail)
+ connection.deliver!(mail)
+
+ expect(MockSMTP.deliveries.size).to eq(2)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/vendor/gems/mail-smtp_pool/spec/lib/mail/smtp_pool_spec.rb b/vendor/gems/mail-smtp_pool/spec/lib/mail/smtp_pool_spec.rb
new file mode 100644
index 00000000000..aa2a0e19ac8
--- /dev/null
+++ b/vendor/gems/mail-smtp_pool/spec/lib/mail/smtp_pool_spec.rb
@@ -0,0 +1,68 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Mail::SMTPPool do
+ describe '.create_pool' do
+ it 'sets the default pool settings' do
+ expect(ConnectionPool).to receive(:new).with(size: 5, timeout: 5).once
+
+ described_class.create_pool
+ end
+
+ it 'allows overriding pool size and timeout' do
+ expect(ConnectionPool).to receive(:new).with(size: 3, timeout: 2).once
+
+ described_class.create_pool(pool_size: 3, pool_timeout: 2)
+ end
+
+ it 'creates an SMTP connection with the correct settings' do
+ settings = { address: 'smtp.example.com', port: '465' }
+
+ smtp_pool = described_class.create_pool(settings)
+
+ expect(Mail::SMTPPool::Connection).to receive(:new).with(settings).once.and_call_original
+
+ smtp_pool.checkout
+ end
+ end
+
+ describe '#initialize' do
+ it 'raises an error if a pool is not specified' do
+ expect { described_class.new({}) }.to raise_error(
+ ArgumentError, 'pool is required. You can create one using Mail::SMTPPool.create_pool.'
+ )
+ end
+ end
+
+ describe '#deliver!' do
+ let(:mail) do
+ Mail.new do
+ from 'mikel@test.lindsaar.net'
+ to 'you@test.lindsaar.net'
+ subject 'This is a test email'
+ body 'Test body'
+ end
+ end
+
+ after do
+ MockSMTP.clear_deliveries
+ end
+
+ it 'delivers mail using a connection from the pool' do
+ connection_pool = double(ConnectionPool)
+ connection = double(Mail::SMTPPool::Connection)
+
+ expect(connection_pool).to receive(:with).and_yield(connection)
+ expect(connection).to receive(:deliver!).with(mail)
+
+ described_class.new(pool: connection_pool).deliver!(mail)
+ end
+
+ it 'delivers mail' do
+ described_class.new(pool: described_class.create_pool).deliver!(mail)
+
+ expect(MockSMTP.deliveries.size).to eq(1)
+ end
+ end
+end
diff --git a/vendor/gems/mail-smtp_pool/spec/spec_helper.rb b/vendor/gems/mail-smtp_pool/spec/spec_helper.rb
new file mode 100644
index 00000000000..4d339850381
--- /dev/null
+++ b/vendor/gems/mail-smtp_pool/spec/spec_helper.rb
@@ -0,0 +1,84 @@
+# frozen_string_literal: true
+
+require 'mail/smtp_pool'
+
+# Original mockup from ActionMailer
+# Based on https://github.com/mikel/mail/blob/22a7afc23f253319965bf9228a0a430eec94e06d/spec/spec_helper.rb#L74-L138
+class MockSMTP
+ def self.deliveries
+ @@deliveries
+ end
+
+ def self.security
+ @@security
+ end
+
+ def initialize
+ @@deliveries = []
+ @@security = nil
+ @started = false
+ end
+
+ def sendmail(mail, from, to)
+ @@deliveries << [mail, from, to]
+ 'OK'
+ end
+
+ def rset
+ Net::SMTP::Response.parse('250 OK')
+ end
+
+ def start(*args)
+ @started = true
+
+ if block_given?
+ result = yield(self)
+ @started = false
+
+ return result
+ else
+ return self
+ end
+ end
+
+ def started?
+ @started
+ end
+
+ def finish
+ @started = false
+ return true
+ end
+
+ def self.clear_deliveries
+ @@deliveries = []
+ end
+
+ def self.clear_security
+ @@security = nil
+ end
+
+ def enable_tls(context)
+ raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @@security && @@security != :enable_tls
+ @@security = :enable_tls
+ context
+ end
+
+ def enable_starttls(context = nil)
+ raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @@security == :enable_tls
+ @@security = :enable_starttls
+ context
+ end
+
+ def enable_starttls_auto(context)
+ raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @@security == :enable_tls
+ @@security = :enable_starttls_auto
+ context
+ end
+end
+
+class Net::SMTP
+ def self.new(*args)
+ MockSMTP.new
+ end
+end