diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-15 18:15:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-15 18:15:58 +0300 |
commit | f357b1fa2f6a1a204f1ab9070e8a64d717c8960c (patch) | |
tree | 067cd32e690d992f1b31862ceb3dce7456fdf8cc /spec | |
parent | c70fec25f88e1f1866c6b3d91de8587bdad59391 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/users/email_verification_on_login_spec.rb | 1 | ||||
-rw-r--r-- | spec/frontend/sentry/init_sentry_spec.js | 4 | ||||
-rw-r--r-- | spec/lib/banzai/filter/inline_diff_filter_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/concerns/require_email_verification_spec.rb | 14 | ||||
-rw-r--r-- | spec/tooling/danger/ignored_model_columns_spec.rb | 145 | ||||
-rw-r--r-- | spec/tooling/fixtures/cleanup_conversion_migration.txt | 44 | ||||
-rw-r--r-- | spec/tooling/fixtures/remove_column_migration.txt | 84 | ||||
-rw-r--r-- | spec/tooling/fixtures/rename_column_migration.txt | 45 |
8 files changed, 335 insertions, 4 deletions
diff --git a/spec/features/users/email_verification_on_login_spec.rb b/spec/features/users/email_verification_on_login_spec.rb index 407311afbc9..d83040efd72 100644 --- a/spec/features/users/email_verification_on_login_spec.rb +++ b/spec/features/users/email_verification_on_login_spec.rb @@ -247,6 +247,7 @@ RSpec.describe 'Email Verification On Login', :clean_gitlab_redis_rate_limiting, end it_behaves_like 'email verification required' + it_behaves_like 'no email verification required when 2fa enabled or ff disabled' describe 'when waiting for the auto unlock time' do before do diff --git a/spec/frontend/sentry/init_sentry_spec.js b/spec/frontend/sentry/init_sentry_spec.js index 8cfbcc1cfca..e31068b935b 100644 --- a/spec/frontend/sentry/init_sentry_spec.js +++ b/spec/frontend/sentry/init_sentry_spec.js @@ -22,6 +22,7 @@ const mockVersion = '1.0.0'; const mockRevision = '00112233'; const mockFeatureCategory = 'my_feature_category'; const mockPage = 'index:page'; +const mockSentryClientsideTracesSampleRate = 0.1; jest.mock('sentrybrowser', () => { return { @@ -51,6 +52,7 @@ describe('SentryConfig', () => { version: mockVersion, revision: mockRevision, feature_category: mockFeatureCategory, + sentry_clientside_traces_sample_rate: mockSentryClientsideTracesSampleRate, }; document.body.dataset.page = mockPage; @@ -89,6 +91,8 @@ describe('SentryConfig', () => { release: mockVersion, allowUrls: [mockGitlabUrl, 'webpack-internal://'], environment: mockEnvironment, + tracesSampleRate: mockSentryClientsideTracesSampleRate, + tracePropagationTargets: [/^\//], transport: makeFetchTransport, stackParser: defaultStackParser, diff --git a/spec/lib/banzai/filter/inline_diff_filter_spec.rb b/spec/lib/banzai/filter/inline_diff_filter_spec.rb index 1388a9053d9..89ee17837e0 100644 --- a/spec/lib/banzai/filter/inline_diff_filter_spec.rb +++ b/spec/lib/banzai/filter/inline_diff_filter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Banzai::Filter::InlineDiffFilter do +RSpec.describe Banzai::Filter::InlineDiffFilter, feature_category: :source_code_management do include FilterSpecHelper it 'adds inline diff span tags for deletions when using square brackets' do diff --git a/spec/models/concerns/require_email_verification_spec.rb b/spec/models/concerns/require_email_verification_spec.rb index bfce2e93c97..63312d4e1f1 100644 --- a/spec/models/concerns/require_email_verification_spec.rb +++ b/spec/models/concerns/require_email_verification_spec.rb @@ -57,9 +57,17 @@ RSpec.describe RequireEmailVerification, feature_category: :insider_threat do it { is_expected.to eq(false) } end - context 'when failed_attempts is GTE overridden amount' do + context 'when failed_attempts is GTE overridden amount but LT Devise default amount' do before do - instance.failed_attempts = 3 + instance.failed_attempts = 6 + end + + it { is_expected.to eq(overridden) } + end + + context 'when failed_attempts is GTE Devise default amount' do + before do + instance.failed_attempts = 10 end it { is_expected.to eq(true) } @@ -79,7 +87,7 @@ RSpec.describe RequireEmailVerification, feature_category: :insider_threat do context 'when locked longer ago than Devise default time but shorter ago than overriden time' do before do - instance.locked_at = 31.minutes.ago + instance.locked_at = 11.minutes.ago end it { is_expected.to eq(!overridden) } diff --git a/spec/tooling/danger/ignored_model_columns_spec.rb b/spec/tooling/danger/ignored_model_columns_spec.rb new file mode 100644 index 00000000000..737b6cce077 --- /dev/null +++ b/spec/tooling/danger/ignored_model_columns_spec.rb @@ -0,0 +1,145 @@ +# frozen_string_literal: true + +require 'danger' +require 'gitlab/dangerfiles/spec_helper' + +require_relative '../../../tooling/danger/ignored_model_columns' +require_relative '../../../tooling/danger/project_helper' + +RSpec.describe Tooling::Danger::IgnoredModelColumns, feature_category: :tooling do + subject(:ignored_model_columns) { fake_danger.new(helper: fake_helper) } + + let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) } + let(:fake_project_helper) { instance_double(Tooling::Danger::ProjectHelper) } + let(:comment) { described_class::COMMENT.chomp } + let(:file_diff) do + File.read(File.expand_path("../fixtures/#{fixture}", __dir__)).split("\n") + end + + include_context "with dangerfile" + + describe '#add_comment_for_ignored_model_columns' do + let(:file_lines) { file_diff.map { |line| line.delete_prefix('+').delete_prefix('-') } } + + before do + allow(ignored_model_columns).to receive(:project_helper).and_return(fake_project_helper) + allow(ignored_model_columns.project_helper).to receive(:file_lines).and_return(file_lines) + allow(ignored_model_columns.helper).to receive(:all_changed_files).and_return([filename]) + allow(ignored_model_columns.helper).to receive(:changed_lines).with(filename).and_return(file_diff) + end + + context 'when table column is renamed in a regular migration' do + let(:filename) { 'db/migrate/rename_my_column_migration.rb' } + let(:fixture) { 'rename_column_migration.txt' } + let(:matching_lines) { [7, 11, 15, 19, 23, 27, 31, 35, 39] } + + it 'adds comment at the correct line' do + matching_lines.each do |line_number| + expect(ignored_model_columns).to receive(:markdown).with("\n#{comment}", file: filename, line: line_number) + end + + ignored_model_columns.add_comment_for_ignored_model_columns + end + end + + context 'when table column is renamed in a post migration' do + let(:filename) { 'db/post_migrate/remove_column_migration.rb' } + let(:fixture) { 'remove_column_migration.txt' } + let(:matching_lines) { [7, 8, 16, 24, 32, 40, 48, 56, 64, 72] } + + it 'adds comment at the correct line' do + matching_lines.each do |line_number| + expect(ignored_model_columns).to receive(:markdown).with("\n#{comment}", file: filename, line: line_number) + end + + ignored_model_columns.add_comment_for_ignored_model_columns + end + end + + context 'when table cleanup is performed in a post migration' do + let(:filename) { 'db/post_migrate/cleanup_conversion_big_int_migration.rb' } + let(:fixture) { 'cleanup_conversion_migration.txt' } + let(:matching_lines) { [7, 11, 15, 19, 23, 27, 31, 35, 39] } + + it 'adds comment at the correct line' do + matching_lines.each do |line_number| + expect(ignored_model_columns).to receive(:markdown).with("\n#{comment}", file: filename, line: line_number) + end + + ignored_model_columns.add_comment_for_ignored_model_columns + end + end + + context 'when a regular migration does not rename table column' do + let(:filename) { 'db/migrate/my_migration.rb' } + let(:file_diff) do + [ + "+ undo_cleanup_concurrent_column_rename(:my_table, :old_column, :new_column)", + "- cleanup_concurrent_column_rename(:my_table, :new_column, :old_column)" + ] + end + + let(:file_lines) do + [ + ' def up', + ' undo_cleanup_concurrent_column_rename(:my_table, :old_column, :new_column)', + ' end' + ] + end + + it 'does not add comment' do + expect(ignored_model_columns).not_to receive(:markdown) + + ignored_model_columns.add_comment_for_ignored_model_columns + end + end + + context 'when a post migration does not remove table column' do + let(:filename) { 'db/migrate/my_migration.rb' } + let(:file_diff) do + [ + "+ add_column(:my_table, :my_column, :type)", + "- remove_column(:my_table, :my_column)" + ] + end + + let(:file_lines) do + [ + ' def up', + ' add_column(:my_table, :my_column, :type)', + ' end' + ] + end + + it 'does not add comment' do + expect(ignored_model_columns).not_to receive(:markdown) + + ignored_model_columns.add_comment_for_ignored_model_columns + end + end + + context 'when a post migration does not convert table column' do + let(:filename) { 'db/migrate/my_migration.rb' } + let(:file_diff) do + [ + "+ restore_conversion_of_integer_to_bigint(TABLE, COLUMNS)", + "- cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)" + ] + end + + let(:file_lines) do + [ + ' def up', + ' cleanup_conversion_of_integer_to_bigint(TABLE, COLUMNS)', + ' end' + ] + end + + it 'does not add comment' do + expect(ignored_model_columns).not_to receive(:markdown) + + ignored_model_columns.add_comment_for_ignored_model_columns + end + end + end +end diff --git a/spec/tooling/fixtures/cleanup_conversion_migration.txt b/spec/tooling/fixtures/cleanup_conversion_migration.txt new file mode 100644 index 00000000000..14a7937b469 --- /dev/null +++ b/spec/tooling/fixtures/cleanup_conversion_migration.txt @@ -0,0 +1,44 @@ ++# frozen_string_literal: true ++ ++class TestMigration < Gitlab::Database::Migration[2.1] ++ disable_ddl_transaction! ++ ++ def up ++ cleanup_conversion_of_integer_to_bigint :my_table, :my_column ++ end ++ ++ def up ++ cleanup_conversion_of_integer_to_bigint 'my_table', 'my_column' ++ end ++ ++ def up ++ cleanup_conversion_of_integer_to_bigint "my_table", "my_column", "new_column" ++ end ++ ++ def up ++ cleanup_conversion_of_integer_to_bigint TABLE_NAME, MY_COLUMN ++ end ++ ++ def up ++ cleanup_conversion_of_integer_to_bigint(:my_table, :my_column) ++ end ++ ++ def up ++ cleanup_conversion_of_integer_to_bigint('my_table', 'my_column') ++ end ++ ++ def up ++ cleanup_conversion_of_integer_to_bigint("my_table", "my_column") ++ end ++ ++ def up ++ cleanup_conversion_of_integer_to_bigint(TABLE_NAME, MY_COLUMN) ++ end ++ ++ def up ++ cleanup_conversion_of_integer_to_bigint( ++ :my_table, ++ :my_column ++ ) ++ end ++end diff --git a/spec/tooling/fixtures/remove_column_migration.txt b/spec/tooling/fixtures/remove_column_migration.txt new file mode 100644 index 00000000000..885f0060d92 --- /dev/null +++ b/spec/tooling/fixtures/remove_column_migration.txt @@ -0,0 +1,84 @@ ++# frozen_string_literal: true ++ ++class TestMigration < Gitlab::Database::Migration[2.1] ++ disable_ddl_transaction! ++ ++ def up ++ remove_column :my_table, :my_column ++ remove_column :my_other_table, :my_column ++ end ++ ++ def down ++ remove_column :my_table, :my_column ++ end ++ ++ def up ++ remove_column 'my_table', 'my_column' ++ end ++ ++ def down ++ remove_column 'my_table', 'my_column' ++ end ++ ++ def up ++ remove_column "my_table", "my_column", "new_column" ++ end ++ ++ def down ++ remove_column "my_table", "my_column", "new_column" ++ end ++ ++ def up ++ remove_column TABLE_NAME, MY_COLUMN ++ end ++ ++ def down ++ remove_column TABLE_NAME, MY_COLUMN ++ end ++ ++ def up ++ remove_column(:my_table, :my_column) ++ end ++ ++ def down ++ remove_column(:my_table, :my_column) ++ end ++ ++ def up ++ remove_column('my_table', 'my_column') ++ end ++ ++ def down ++ remove_column('my_table', 'my_column') ++ end ++ ++ def up ++ remove_column("my_table", "my_column") ++ end ++ ++ def down ++ remove_column("my_table", "my_column") ++ end ++ ++ def up ++ remove_column(TABLE_NAME, MY_COLUMN) ++ end ++ ++ def down ++ remove_column(TABLE_NAME, MY_COLUMN) ++ end ++ ++ def up ++ remove_column( ++ :my_table, ++ :my_column ++ ) ++ end ++ ++ def down ++ remove_column( ++ :my_table, ++ :my_column ++ ) ++ end ++end diff --git a/spec/tooling/fixtures/rename_column_migration.txt b/spec/tooling/fixtures/rename_column_migration.txt new file mode 100644 index 00000000000..e79029219a5 --- /dev/null +++ b/spec/tooling/fixtures/rename_column_migration.txt @@ -0,0 +1,45 @@ ++# frozen_string_literal: true ++ ++class TestMigration < Gitlab::Database::Migration[2.1] ++ disable_ddl_transaction! ++ ++ def up ++ cleanup_concurrent_column_rename :my_table, :old_column, :new_column ++ end ++ ++ def up ++ cleanup_concurrent_column_rename 'my_table', 'old_column', 'new_column' ++ end ++ ++ def up ++ cleanup_concurrent_column_rename "my_table", "old_column", "new_column" ++ end ++ ++ def up ++ cleanup_concurrent_column_rename TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME ++ end ++ ++ def up ++ cleanup_concurrent_column_rename(:my_table, :old_column, :new_column) ++ end ++ ++ def up ++ cleanup_concurrent_column_rename('my_table', 'old_column', 'new_column') ++ end ++ ++ def up ++ cleanup_concurrent_column_rename("my_table", "old_column", "new_column") ++ end ++ ++ def up ++ cleanup_concurrent_column_rename(TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME) ++ end ++ ++ def up ++ cleanup_concurrent_column_rename( ++ :my_table, ++ :old_column, ++ :new_column ++ ) ++ end ++end |