diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-27 00:10:31 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-27 00:10:31 +0300 |
commit | 277496b843d3c14cfd48286b1718b03775d83bbc (patch) | |
tree | 2ba3b900aa2103955dc28217d83acf9263ae08aa /spec | |
parent | ea413f31cf00268c71bfab1351b92f75e72c9a80 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/acme_challenges_controller_spec.rb | 9 | ||||
-rw-r--r-- | spec/requests/application_controller_spec.rb | 15 | ||||
-rw-r--r-- | spec/requests/chaos_controller_spec.rb | 14 | ||||
-rw-r--r-- | spec/requests/health_controller_spec.rb | 4 | ||||
-rw-r--r-- | spec/requests/metrics_controller_spec.rb | 9 | ||||
-rw-r--r-- | spec/requests/oauth/authorizations_controller_spec.rb | 4 | ||||
-rw-r--r-- | spec/requests/registrations_controller_spec.rb | 6 | ||||
-rw-r--r-- | spec/requests/sessions_spec.rb | 4 | ||||
-rw-r--r-- | spec/rubocop/batched_background_migrations_dictionary_spec.rb (renamed from spec/rubocop/batched_background_migrations_spec.rb) | 32 | ||||
-rw-r--r-- | spec/rubocop/cop/background_migration/dictionary_file_spec.rb (renamed from spec/rubocop/cop/background_migration/missing_dictionary_file_spec.rb) | 83 | ||||
-rw-r--r-- | spec/rubocop/cop/migration/unfinished_dependencies_spec.rb | 2 | ||||
-rw-r--r-- | spec/support/helpers/database/duplicate_indexes.yml | 6 | ||||
-rw-r--r-- | spec/support/shared_examples/controllers/base_action_controller_shared_examples.rb | 26 |
13 files changed, 96 insertions, 118 deletions
diff --git a/spec/requests/acme_challenges_controller_spec.rb b/spec/requests/acme_challenges_controller_spec.rb deleted file mode 100644 index f37aefed488..00000000000 --- a/spec/requests/acme_challenges_controller_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe AcmeChallengesController, type: :request, feature_category: :pages do - it_behaves_like 'Base action controller' do - subject(:request) { get acme_challenge_path } - end -end diff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rb deleted file mode 100644 index 52fdf6bc69e..00000000000 --- a/spec/requests/application_controller_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ApplicationController, type: :request, feature_category: :shared do - let_it_be(:user) { create(:user) } - - before do - sign_in(user) - end - - it_behaves_like 'Base action controller' do - subject(:request) { get root_path } - end -end diff --git a/spec/requests/chaos_controller_spec.rb b/spec/requests/chaos_controller_spec.rb deleted file mode 100644 index d2ce618b041..00000000000 --- a/spec/requests/chaos_controller_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ChaosController, type: :request, feature_category: :tooling do - it_behaves_like 'Base action controller' do - before do - # Stub leak_mem so we don't actually leak memory for the base action controller tests. - allow(Gitlab::Chaos).to receive(:leak_mem).with(100, 30.seconds) - end - - subject(:request) { get leakmem_chaos_path } - end -end diff --git a/spec/requests/health_controller_spec.rb b/spec/requests/health_controller_spec.rb index 3ad1d8a75b4..639f6194af9 100644 --- a/spec/requests/health_controller_spec.rb +++ b/spec/requests/health_controller_spec.rb @@ -73,9 +73,7 @@ RSpec.describe HealthController, feature_category: :database do end describe 'GET /-/readiness' do - subject(:request) { get readiness_path, params: params, headers: headers } - - it_behaves_like 'Base action controller' + subject { get '/-/readiness', params: params, headers: headers } shared_context 'endpoint responding with readiness data' do context 'when requesting instance-checks' do diff --git a/spec/requests/metrics_controller_spec.rb b/spec/requests/metrics_controller_spec.rb deleted file mode 100644 index ce96906e020..00000000000 --- a/spec/requests/metrics_controller_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe MetricsController, type: :request, feature_category: :metrics do - it_behaves_like 'Base action controller' do - subject(:request) { get metrics_path } - end -end diff --git a/spec/requests/oauth/authorizations_controller_spec.rb b/spec/requests/oauth/authorizations_controller_spec.rb index 7887bf52542..257f238d9ef 100644 --- a/spec/requests/oauth/authorizations_controller_spec.rb +++ b/spec/requests/oauth/authorizations_controller_spec.rb @@ -20,10 +20,6 @@ RSpec.describe Oauth::AuthorizationsController, feature_category: :system_access end describe 'GET #new' do - it_behaves_like 'Base action controller' do - subject(:request) { get oauth_authorization_path } - end - context 'when application redirect URI has a custom scheme' do context 'when CSP is disabled' do before do diff --git a/spec/requests/registrations_controller_spec.rb b/spec/requests/registrations_controller_spec.rb index 71f2f347f0d..8b857046a4d 100644 --- a/spec/requests/registrations_controller_spec.rb +++ b/spec/requests/registrations_controller_spec.rb @@ -6,9 +6,7 @@ RSpec.describe RegistrationsController, type: :request, feature_category: :syste describe 'POST #create' do let_it_be(:user_attrs) { build_stubbed(:user).slice(:first_name, :last_name, :username, :email, :password) } - subject(:request) { post user_registration_path, params: { user: user_attrs } } - - it_behaves_like 'Base action controller' + subject(:create_user) { post user_registration_path, params: { user: user_attrs } } context 'when email confirmation is required' do before do @@ -17,7 +15,7 @@ RSpec.describe RegistrationsController, type: :request, feature_category: :syste end it 'redirects to the `users_almost_there_path`', unless: Gitlab.ee? do - request + create_user expect(response).to redirect_to(users_almost_there_path(email: user_attrs[:email])) end diff --git a/spec/requests/sessions_spec.rb b/spec/requests/sessions_spec.rb index 1a925969c5a..3428e607305 100644 --- a/spec/requests/sessions_spec.rb +++ b/spec/requests/sessions_spec.rb @@ -7,10 +7,6 @@ RSpec.describe 'Sessions', feature_category: :system_access do let(:user) { create(:user) } - it_behaves_like 'Base action controller' do - subject(:request) { get new_user_session_path } - end - context 'for authentication', :allow_forgery_protection do it 'logout does not require a csrf token' do login_as(user) diff --git a/spec/rubocop/batched_background_migrations_spec.rb b/spec/rubocop/batched_background_migrations_dictionary_spec.rb index a9b99bb466b..57ef929fd90 100644 --- a/spec/rubocop/batched_background_migrations_spec.rb +++ b/spec/rubocop/batched_background_migrations_dictionary_spec.rb @@ -2,20 +2,24 @@ require 'rubocop_spec_helper' -require_relative '../../rubocop/batched_background_migrations' +require_relative '../../rubocop/batched_background_migrations_dictionary' -RSpec.describe RuboCop::BatchedBackgroundMigrations, feature_category: :database do +RSpec.describe RuboCop::BatchedBackgroundMigrationsDictionary, feature_category: :database do let(:bbm_dictionary_file_name) { "#{described_class::DICTIONARY_BASE_DIR}/test_migration.yml" } let(:migration_version) { 20230307160250 } let(:finalized_by_version) { 20230307160255 } + let(:introduced_by_url) { 'https://test_url' } + let(:finalize_after) { '202312011212' } + let(:bbm_dictionary_data) do { migration_job_name: 'TestMigration', feature_category: :database, - introduced_by_url: 'https://test_url', + introduced_by_url: introduced_by_url, milestone: 16.5, queued_migration_version: migration_version, - finalized_by: finalized_by_version + finalized_by: finalized_by_version, + finalize_after: finalize_after } end @@ -40,4 +44,24 @@ RSpec.describe RuboCop::BatchedBackgroundMigrations, feature_category: :database expect(described_class.new('random').finalized_by).to be_nil end end + + describe '#introduced_by_url' do + it 'returns the introduced_by_url of the bbm with given version' do + expect(batched_background_migration.introduced_by_url).to eq(introduced_by_url) + end + + it 'returns nothing for non-existing bbm dictionary' do + expect(described_class.new('random').introduced_by_url).to be_nil + end + end + + describe '#finalize_after' do + it 'returns the finalize_after timestamp of the bbm with given version' do + expect(batched_background_migration.finalize_after).to eq(finalize_after) + end + + it 'returns nothing for non-existing bbm dictionary' do + expect(described_class.new('random').finalize_after).to be_nil + end + end end diff --git a/spec/rubocop/cop/background_migration/missing_dictionary_file_spec.rb b/spec/rubocop/cop/background_migration/dictionary_file_spec.rb index 32b958426b9..7becf9c09a4 100644 --- a/spec/rubocop/cop/background_migration/missing_dictionary_file_spec.rb +++ b/spec/rubocop/cop/background_migration/dictionary_file_spec.rb @@ -1,17 +1,36 @@ # frozen_string_literal: true require 'rubocop_spec_helper' -require_relative '../../../../rubocop/cop/background_migration/missing_dictionary_file' +require_relative '../../../../rubocop/cop/background_migration/dictionary_file' -RSpec.describe RuboCop::Cop::BackgroundMigration::MissingDictionaryFile, feature_category: :database do +RSpec.describe RuboCop::Cop::BackgroundMigration::DictionaryFile, feature_category: :database do let(:config) do RuboCop::Config.new( - 'BackgroundMigration/MissingDictionaryFile' => { - 'EnforcedSince' => 20230307160251 + 'BackgroundMigration/DictionaryFile' => { + 'EnforcedSince' => 20231018100907 } ) end + shared_examples 'migration with missing dictionary keys offense' do |missing_key| + it 'registers an offense' do + expect_offense(<<~RUBY) + class QueueMyMigration < Gitlab::Database::Migration[2.1] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{format(described_class::MSG[:missing_key], key: missing_key)} + MIGRATION = 'MyMigration' + + def up + queue_batched_background_migration( + MIGRATION, + :users, + :id + ) + end + end + RUBY + end + end + context 'for non post migrations' do before do allow(cop).to receive(:in_post_deployment_migration?).and_return(false) @@ -57,7 +76,7 @@ RSpec.describe RuboCop::Cop::BackgroundMigration::MissingDictionaryFile, feature context 'for migrations before enforced time' do before do - allow(cop).to receive(:version).and_return(20230307160250) + allow(cop).to receive(:version).and_return(20230918100907) end it 'does not throw any offenses' do @@ -79,7 +98,7 @@ RSpec.describe RuboCop::Cop::BackgroundMigration::MissingDictionaryFile, feature context 'for migrations after enforced time' do before do - allow(cop).to receive(:version).and_return(20230307160252) + allow(cop).to receive(:version).and_return(20231118100907) end it 'throws offense on not having the appropriate dictionary file with migration name as a constant' do @@ -114,22 +133,48 @@ RSpec.describe RuboCop::Cop::BackgroundMigration::MissingDictionaryFile, feature RUBY end - it 'does not throw offense with appropriate dictionary file' do - expect(File).to receive(:exist?).with(dictionary_file_path).and_return(true) + context 'with dictionary file' do + let(:introduced_by_url) { 'https://test_url' } + let(:finalize_after) { '20230507160251' } - expect_no_offenses(<<~RUBY) - class QueueMyMigration < Gitlab::Database::Migration[2.1] - MIGRATION = 'MyMigration' + before do + allow(File).to receive(:exist?).with(dictionary_file_path).and_return(true) - def up - queue_batched_background_migration( - MIGRATION, - :users, - :id - ) - end + allow_next_instance_of(RuboCop::BatchedBackgroundMigrationsDictionary) do |dictionary| + allow(dictionary).to receive(:finalize_after).and_return(finalize_after) + allow(dictionary).to receive(:introduced_by_url).and_return(introduced_by_url) end - RUBY + end + + context 'without introduced_by_url' do + it_behaves_like 'migration with missing dictionary keys offense', :introduced_by_url do + let(:introduced_by_url) { nil } + end + end + + context 'without finalize_after' do + it_behaves_like 'migration with missing dictionary keys offense', :finalize_after do + let(:finalize_after) { nil } + end + end + + context 'with required dictionary keys' do + it 'does not throw offense with appropriate dictionary file' do + expect_no_offenses(<<~RUBY) + class QueueMyMigration < Gitlab::Database::Migration[2.1] + MIGRATION = 'MyMigration' + + def up + queue_batched_background_migration( + MIGRATION, + :users, + :id + ) + end + end + RUBY + end + end end end end diff --git a/spec/rubocop/cop/migration/unfinished_dependencies_spec.rb b/spec/rubocop/cop/migration/unfinished_dependencies_spec.rb index cac48871856..f2e963ad322 100644 --- a/spec/rubocop/cop/migration/unfinished_dependencies_spec.rb +++ b/spec/rubocop/cop/migration/unfinished_dependencies_spec.rb @@ -99,7 +99,7 @@ RSpec.describe RuboCop::Cop::Migration::UnfinishedDependencies, feature_category context 'with properly finalized dependent background migrations' do before do - allow_next_instance_of(RuboCop::BatchedBackgroundMigrations) do |bbms| + allow_next_instance_of(RuboCop::BatchedBackgroundMigrationsDictionary) do |bbms| allow(bbms).to receive(:finalized_by).and_return(version - 5) end end diff --git a/spec/support/helpers/database/duplicate_indexes.yml b/spec/support/helpers/database/duplicate_indexes.yml index 1e78b8fc774..bb2802ba6d2 100644 --- a/spec/support/helpers/database/duplicate_indexes.yml +++ b/spec/support/helpers/database/duplicate_indexes.yml @@ -6,9 +6,6 @@ abuse_reports: alert_management_http_integrations: index_http_integrations_on_project_and_endpoint: - index_alert_management_http_integrations_on_project_id -analytics_cycle_analytics_group_stages: - index_group_stages_on_group_id_group_value_stream_id_and_name: - - index_analytics_ca_group_stages_on_group_id approval_project_rules_users: index_approval_project_rules_users_1: - index_approval_project_rules_users_on_approval_project_rule_id @@ -111,9 +108,6 @@ members: merge_request_assignees: index_merge_request_assignees_on_merge_request_id_and_user_id: - index_merge_request_assignees_on_merge_request_id -merge_request_metrics: - index_mr_metrics_on_target_project_id_merged_at_nulls_last: - - index_merge_request_metrics_on_target_project_id merge_requests: index_merge_requests_on_author_id_and_created_at: - index_merge_requests_on_author_id diff --git a/spec/support/shared_examples/controllers/base_action_controller_shared_examples.rb b/spec/support/shared_examples/controllers/base_action_controller_shared_examples.rb deleted file mode 100644 index 5f236f25d35..00000000000 --- a/spec/support/shared_examples/controllers/base_action_controller_shared_examples.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -# Requires `request` subject to be defined -# -# subject(:request) { get root_path } -RSpec.shared_examples 'Base action controller' do - describe 'security headers' do - describe 'Cross-Origin-Opener-Policy' do - it 'sets the header' do - request - - expect(response.headers['Cross-Origin-Opener-Policy']).to eq('same-origin') - end - - context 'when coop_header feature flag is disabled' do - it 'does not set the header' do - stub_feature_flags(coop_header: false) - - request - - expect(response.headers['Cross-Origin-Opener-Policy']).to be_nil - end - end - end - end -end |