diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/lib/gitlab/background_migration | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/lib/gitlab/background_migration')
6 files changed, 167 insertions, 22 deletions
diff --git a/spec/lib/gitlab/background_migration/add_modified_to_approval_merge_request_rule_spec.rb b/spec/lib/gitlab/background_migration/add_modified_to_approval_merge_request_rule_spec.rb new file mode 100644 index 00000000000..81b8b5dde08 --- /dev/null +++ b/spec/lib/gitlab/background_migration/add_modified_to_approval_merge_request_rule_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::AddModifiedToApprovalMergeRequestRule, schema: 20200817195628 do + let(:determine_if_rules_are_modified) { described_class.new } + + let(:namespace) { table(:namespaces).create!(name: 'gitlab', path: 'gitlab') } + let(:projects) { table(:projects) } + let(:normal_project) { projects.create!(namespace_id: namespace.id) } + let(:overridden_project) { projects.create!(namespace_id: namespace.id) } + let(:rules) { table(:approval_merge_request_rules) } + let(:project_rules) { table(:approval_project_rules) } + let(:sources) { table(:approval_merge_request_rule_sources) } + let(:merge_requests) { table(:merge_requests) } + let(:groups) { table(:namespaces) } + let(:mr_groups) { table(:approval_merge_request_rules_groups) } + let(:project_groups) { table(:approval_project_rules_groups) } + + before do + project_rule = project_rules.create!(project_id: normal_project.id, approvals_required: 3, name: 'test rule') + overridden_project_rule = project_rules.create!(project_id: overridden_project.id, approvals_required: 5, name: 'other test rule') + overridden_project_rule_two = project_rules.create!(project_id: overridden_project.id, approvals_required: 7, name: 'super cool rule') + + merge_request = merge_requests.create!(target_branch: 'feature', source_branch: 'default', source_project_id: normal_project.id, target_project_id: normal_project.id) + overridden_merge_request = merge_requests.create!(target_branch: 'feature-2', source_branch: 'default', source_project_id: overridden_project.id, target_project_id: overridden_project.id) + + merge_rule = rules.create!(merge_request_id: merge_request.id, approvals_required: 3, name: 'test rule') + overridden_merge_rule = rules.create!(merge_request_id: overridden_merge_request.id, approvals_required: 6, name: 'other test rule') + overridden_merge_rule_two = rules.create!(merge_request_id: overridden_merge_request.id, approvals_required: 7, name: 'super cool rule') + + sources.create!(approval_project_rule_id: project_rule.id, approval_merge_request_rule_id: merge_rule.id) + sources.create!(approval_project_rule_id: overridden_project_rule.id, approval_merge_request_rule_id: overridden_merge_rule.id) + sources.create!(approval_project_rule_id: overridden_project_rule_two.id, approval_merge_request_rule_id: overridden_merge_rule_two.id) + + group1 = groups.create!(name: "group1", path: "test_group1", type: 'Group') + group2 = groups.create!(name: "group2", path: "test_group2", type: 'Group') + group3 = groups.create!(name: "group3", path: "test_group3", type: 'Group') + + project_groups.create!(approval_project_rule_id: overridden_project_rule_two.id, group_id: group1.id) + project_groups.create!(approval_project_rule_id: overridden_project_rule_two.id, group_id: group2.id) + project_groups.create!(approval_project_rule_id: overridden_project_rule_two.id, group_id: group3.id) + + mr_groups.create!(approval_merge_request_rule_id: overridden_merge_rule.id, group_id: group1.id) + mr_groups.create!(approval_merge_request_rule_id: overridden_merge_rule_two.id, group_id: group2.id) + end + + describe '#perform' do + it 'changes the correct rules' do + original_count = rules.all.count + + determine_if_rules_are_modified.perform(rules.minimum(:id), rules.maximum(:id)) + + results = rules.where(modified_from_project_rule: true) + + expect(results.count).to eq 2 + expect(results.collect(&:name)).to eq(['other test rule', 'super cool rule']) + expect(rules.count).to eq original_count + end + end +end diff --git a/spec/lib/gitlab/background_migration/merge_request_assignees_migration_progress_check_spec.rb b/spec/lib/gitlab/background_migration/merge_request_assignees_migration_progress_check_spec.rb index a3840e3a22e..85a9c88ebff 100644 --- a/spec/lib/gitlab/background_migration/merge_request_assignees_migration_progress_check_spec.rb +++ b/spec/lib/gitlab/background_migration/merge_request_assignees_migration_progress_check_spec.rb @@ -73,7 +73,7 @@ RSpec.describe Gitlab::BackgroundMigration::MergeRequestAssigneesMigrationProgre described_class.new.perform - expect(Feature.enabled?(:multiple_merge_request_assignees)).to eq(true) + expect(Feature.enabled?(:multiple_merge_request_assignees, type: :licensed)).to eq(true) end end diff --git a/spec/lib/gitlab/background_migration/migrate_u2f_webauthn_spec.rb b/spec/lib/gitlab/background_migration/migrate_u2f_webauthn_spec.rb new file mode 100644 index 00000000000..33498ffa748 --- /dev/null +++ b/spec/lib/gitlab/background_migration/migrate_u2f_webauthn_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::MigrateU2fWebauthn, :migration, schema: 20200925125321 do + let(:users) { table(:users) } + + let(:user) { users.create!(email: 'email@email.com', name: 'foo', username: 'foo', projects_limit: 0) } + + let(:u2f_registrations) { table(:u2f_registrations) } + let(:webauthn_registrations) { table(:webauthn_registrations) } + + let!(:u2f_registration_not_migrated) { create_u2f_registration(1, 'reg1') } + let!(:u2f_registration_not_migrated_no_name) { create_u2f_registration(2, nil, 2) } + let!(:u2f_registration_migrated) { create_u2f_registration(3, 'reg3') } + + subject { described_class.new.perform(1, 3) } + + before do + converted_credential = convert_credential_for(u2f_registration_migrated) + webauthn_registrations.create!(converted_credential) + end + + it 'migrates all records' do + expect { subject }.to change { webauthn_registrations.count }.from(1).to(3) + + all_webauthn_registrations = webauthn_registrations.all.map(&:attributes) + + [u2f_registration_not_migrated, u2f_registration_not_migrated_no_name].each do |u2f_registration| + expected_credential = convert_credential_for(u2f_registration).except(:created_at).stringify_keys + expect(all_webauthn_registrations).to include(a_hash_including(expected_credential)) + end + end + + def create_u2f_registration(id, name, counter = 5) + 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: counter, + name: name, + user_id: user.id }) + end + + def convert_credential_for(u2f_registration) + converted_credential = WebAuthn::U2fMigrator.new( + app_id: Gitlab.config.gitlab.url, + certificate: u2f_registration.certificate, + key_handle: u2f_registration.key_handle, + public_key: u2f_registration.public_key, + counter: u2f_registration.counter + ).credential + + { + credential_xid: Base64.strict_encode64(converted_credential.id), + public_key: Base64.strict_encode64(converted_credential.public_key), + counter: u2f_registration.counter, + name: u2f_registration.name || '', + user_id: u2f_registration.user_id, + u2f_registration_id: u2f_registration.id, + created_at: u2f_registration.created_at + } + end +end diff --git a/spec/lib/gitlab/background_migration/migrate_users_bio_to_user_details_spec.rb b/spec/lib/gitlab/background_migration/migrate_users_bio_to_user_details_spec.rb index db3cbe7ccdc..3cec5cb4c35 100644 --- a/spec/lib/gitlab/background_migration/migrate_users_bio_to_user_details_spec.rb +++ b/spec/lib/gitlab/background_migration/migrate_users_bio_to_user_details_spec.rb @@ -82,21 +82,4 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateUsersBioToUserDetails, :migra expect(user_detail).to be_nil end - - context 'when `migrate_bio_to_user_details` feature flag is off' do - before do - stub_feature_flags(migrate_bio_to_user_details: false) - end - - it 'does nothing' do - already_existing_user_details = user_details.where(user_id: [ - user_has_different_details.id, - user_already_has_details.id - ]) - - subject - - expect(user_details.all).to match_array(already_existing_user_details) - end - end end diff --git a/spec/lib/gitlab/background_migration/replace_blocked_by_links_spec.rb b/spec/lib/gitlab/background_migration/replace_blocked_by_links_spec.rb new file mode 100644 index 00000000000..fa4f2d1fd88 --- /dev/null +++ b/spec/lib/gitlab/background_migration/replace_blocked_by_links_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::ReplaceBlockedByLinks, schema: 20201015073808 do + let(:namespace) { table(:namespaces).create!(name: 'gitlab', path: 'gitlab-org') } + let(:project) { table(:projects).create!(namespace_id: namespace.id, name: 'gitlab') } + let(:issue1) { table(:issues).create!(project_id: project.id, title: 'a') } + let(:issue2) { table(:issues).create!(project_id: project.id, title: 'b') } + let(:issue3) { table(:issues).create!(project_id: project.id, title: 'c') } + let(:issue_links) { table(:issue_links) } + let!(:blocks_link) { issue_links.create!(source_id: issue1.id, target_id: issue2.id, link_type: 1) } + let!(:bidirectional_link) { issue_links.create!(source_id: issue2.id, target_id: issue1.id, link_type: 2) } + let!(:blocked_link) { issue_links.create!(source_id: issue1.id, target_id: issue3.id, link_type: 2) } + + subject { described_class.new.perform(issue_links.minimum(:id), issue_links.maximum(:id)) } + + it 'deletes issue links where opposite relation already exists' do + expect { subject }.to change { issue_links.count }.by(-1) + end + + it 'ignores issue links other than blocked_by' do + subject + + expect(blocks_link.reload.link_type).to eq(1) + end + + it 'updates blocked_by issue links' do + subject + + link = blocked_link.reload + expect(link.link_type).to eq(1) + expect(link.source_id).to eq(issue3.id) + expect(link.target_id).to eq(issue1.id) + end +end diff --git a/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb b/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb index 392b44d1a1f..2dae4a65eeb 100644 --- a/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb +++ b/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb @@ -74,14 +74,14 @@ RSpec.describe Gitlab::BackgroundMigration::UserMentions::CreateResourceUserMent let(:user_mentions) { merge_request_user_mentions } let(:resource) { merge_request } - it_behaves_like 'resource mentions migration', MigrateMergeRequestMentionsToDb, MergeRequest + it_behaves_like 'resource mentions migration', MigrateMergeRequestMentionsToDb, 'MergeRequest' context 'when FF disabled' do before do stub_feature_flags(migrate_user_mentions: false) end - it_behaves_like 'resource migration not run', MigrateMergeRequestMentionsToDb, MergeRequest + it_behaves_like 'resource migration not run', MigrateMergeRequestMentionsToDb, 'MergeRequest' end end @@ -103,14 +103,14 @@ RSpec.describe Gitlab::BackgroundMigration::UserMentions::CreateResourceUserMent let(:user_mentions) { commit_user_mentions } let(:resource) { commit } - it_behaves_like 'resource notes mentions migration', MigrateCommitNotesMentionsToDb, Commit + it_behaves_like 'resource notes mentions migration', MigrateCommitNotesMentionsToDb, 'Commit' context 'when FF disabled' do before do stub_feature_flags(migrate_user_mentions: false) end - it_behaves_like 'resource notes migration not run', MigrateCommitNotesMentionsToDb, Commit + it_behaves_like 'resource notes migration not run', MigrateCommitNotesMentionsToDb, 'Commit' end end end |