summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/backfill_integrations_enable_ssl_verification_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/background_migration/backfill_integrations_enable_ssl_verification_spec.rb')
-rw-r--r--spec/lib/gitlab/background_migration/backfill_integrations_enable_ssl_verification_spec.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/spec/lib/gitlab/background_migration/backfill_integrations_enable_ssl_verification_spec.rb b/spec/lib/gitlab/background_migration/backfill_integrations_enable_ssl_verification_spec.rb
new file mode 100644
index 00000000000..b3825a7c4ea
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/backfill_integrations_enable_ssl_verification_spec.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::BackfillIntegrationsEnableSslVerification, schema: 20220425121410 do
+ let(:migration) { described_class.new }
+ let(:integrations) { described_class::Integration }
+
+ before do
+ integrations.create!(id: 1, type_new: 'Integrations::Bamboo') # unaffected integration
+ integrations.create!(id: 2, type_new: 'Integrations::DroneCi') # no properties
+ integrations.create!(id: 3, type_new: 'Integrations::DroneCi',
+ properties: {}) # no URL
+ integrations.create!(id: 4, type_new: 'Integrations::DroneCi',
+ properties: { 'drone_url' => '' }) # blank URL
+ integrations.create!(id: 5, type_new: 'Integrations::DroneCi',
+ properties: { 'drone_url' => 'https://example.com:foo' }) # invalid URL
+ integrations.create!(id: 6, type_new: 'Integrations::DroneCi',
+ properties: { 'drone_url' => 'https://example.com' }) # unknown URL
+ integrations.create!(id: 7, type_new: 'Integrations::DroneCi',
+ properties: { 'drone_url' => 'http://cloud.drone.io' }) # no HTTPS
+ integrations.create!(id: 8, type_new: 'Integrations::DroneCi',
+ properties: { 'drone_url' => 'https://cloud.drone.io' }) # known URL
+ integrations.create!(id: 9, type_new: 'Integrations::Teamcity',
+ properties: { 'teamcity_url' => 'https://example.com' }) # unknown URL
+ integrations.create!(id: 10, type_new: 'Integrations::Teamcity',
+ properties: { 'teamcity_url' => 'https://foo.bar.teamcity.com' }) # unknown URL
+ integrations.create!(id: 11, type_new: 'Integrations::Teamcity',
+ properties: { 'teamcity_url' => 'https://teamcity.com' }) # unknown URL
+ integrations.create!(id: 12, type_new: 'Integrations::Teamcity',
+ properties: { 'teamcity_url' => 'https://customer.teamcity.com' }) # known URL
+ end
+
+ def properties(id)
+ integrations.find(id).properties
+ end
+
+ it 'enables SSL verification for known-good hostnames', :aggregate_failures do
+ migration.perform(1, 12)
+
+ # Bamboo
+ expect(properties(1)).to be_nil
+
+ # DroneCi
+ expect(properties(2)).to be_nil
+ expect(properties(3)).not_to include('enable_ssl_verification')
+ expect(properties(4)).not_to include('enable_ssl_verification')
+ expect(properties(5)).not_to include('enable_ssl_verification')
+ expect(properties(6)).not_to include('enable_ssl_verification')
+ expect(properties(7)).not_to include('enable_ssl_verification')
+ expect(properties(8)).to include('enable_ssl_verification' => true)
+
+ # Teamcity
+ expect(properties(9)).not_to include('enable_ssl_verification')
+ expect(properties(10)).not_to include('enable_ssl_verification')
+ expect(properties(11)).not_to include('enable_ssl_verification')
+ expect(properties(12)).to include('enable_ssl_verification' => true)
+ end
+
+ it 'only updates records within the given ID range', :aggregate_failures do
+ migration.perform(1, 8)
+
+ expect(properties(8)).to include('enable_ssl_verification' => true)
+ expect(properties(12)).not_to include('enable_ssl_verification')
+ end
+
+ it 'marks the job as succeeded' do
+ expect(Gitlab::Database::BackgroundMigrationJob).to receive(:mark_all_as_succeeded)
+ .with('BackfillIntegrationsEnableSslVerification', [1, 10])
+
+ migration.perform(1, 10)
+ end
+end