Welcome to mirror list, hosted at ThFree Co, Russian Federation.

backfill_integrations_enable_ssl_verification_spec.rb « background_migration « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b3825a7c4ea995817869c22a3cfeae79fce23940 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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