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

schedule_migrate_u2f_webauthn_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5dc4d676063561d13d6ec48020ed8623aa077c7c (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
# frozen_string_literal: true

require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200929114107_schedule_migrate_u2f_webauthn.rb')

RSpec.describe ScheduleMigrateU2fWebauthn do
  let(:migration_name) { described_class::MIGRATION }
  let(:u2f_registrations) { table(:u2f_registrations) }
  let(:webauthn_registrations) { table(:webauthn_registrations) }

  let(:users) { table(:users) }

  let(:user) { users.create!(email: 'email@email.com', name: 'foo', username: 'foo', projects_limit: 0) }

  before do
    stub_const("#{described_class.name}::BATCH_SIZE", 1)
  end

  context 'when there are u2f registrations' do
    let!(:u2f_reg_1) { create_u2f_registration(1, 'reg1') }
    let!(:u2f_reg_2) { create_u2f_registration(2, 'reg2') }

    it 'schedules a background migration' do
      Sidekiq::Testing.fake! do
        freeze_time do
          migrate!

          expect(migration_name).to be_scheduled_delayed_migration(2.minutes, 1, 1)
          expect(migration_name).to be_scheduled_delayed_migration(4.minutes, 2, 2)
          expect(BackgroundMigrationWorker.jobs.size).to eq(2)
        end
      end
    end
  end

  context 'when there are no u2f registrations' do
    it 'does not schedule background migrations' do
      Sidekiq::Testing.fake! do
        freeze_time do
          migrate!

          expect(BackgroundMigrationWorker.jobs.size).to eq(0)
        end
      end
    end
  end

  def create_u2f_registration(id, name)
    device = U2F::FakeU2F.new(FFaker::BaconIpsum.characters(5))
    u2f_registrations.create!({ id: id,
                                certificate: Base64.strict_encode64(device.cert_raw),
                                key_handle: U2F.urlsafe_encode64(device.key_handle_raw),
                                public_key: Base64.strict_encode64(device.origin_public_key_raw),
                                counter: 5,
                                name: name,
                                user_id: user.id })
  end
end