diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-25 00:09:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-25 00:09:11 +0300 |
commit | 76bbc06371e3ea6cffa4fda45e7773006ec76dd7 (patch) | |
tree | 4a6623f22ae576ba2436168d9a256c4eb1e9c382 /spec | |
parent | 84cacdae74db0de90cf88ceef2191f399e9659b2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
20 files changed, 161 insertions, 52 deletions
diff --git a/spec/controllers/admin/topics_controller_spec.rb b/spec/controllers/admin/topics_controller_spec.rb index 111fdcc3be6..e640f8bb7ec 100644 --- a/spec/controllers/admin/topics_controller_spec.rb +++ b/spec/controllers/admin/topics_controller_spec.rb @@ -176,7 +176,7 @@ RSpec.describe Admin::TopicsController do describe 'POST #merge' do let_it_be(:source_topic) { create(:topic, name: 'source_topic') } - let_it_be(:project) { create(:project, topic_list: source_topic.name ) } + let_it_be(:project) { create(:project, topic_list: source_topic.name) } it 'merges source topic into target topic' do post :merge, params: { source_topic_id: source_topic.id, target_topic_id: topic.id } diff --git a/spec/controllers/groups/children_controller_spec.rb b/spec/controllers/groups/children_controller_spec.rb index 04cf7785f1e..f05551432fa 100644 --- a/spec/controllers/groups/children_controller_spec.rb +++ b/spec/controllers/groups/children_controller_spec.rb @@ -277,7 +277,7 @@ RSpec.describe Groups::ChildrenController do context 'with only projects' do let!(:other_project) { create(:project, :public, namespace: group) } - let!(:first_page_projects) { create_list(:project, per_page, :public, namespace: group ) } + let!(:first_page_projects) { create_list(:project, per_page, :public, namespace: group) } it 'has projects on the first page' do get :index, params: { group_id: group.to_param, sort: 'id_desc' }, format: :json diff --git a/spec/controllers/groups/registry/repositories_controller_spec.rb b/spec/controllers/groups/registry/repositories_controller_spec.rb index 9ac19b06718..62c15201a95 100644 --- a/spec/controllers/groups/registry/repositories_controller_spec.rb +++ b/spec/controllers/groups/registry/repositories_controller_spec.rb @@ -117,7 +117,7 @@ RSpec.describe Groups::Registry::RepositoriesController do it_behaves_like 'a package tracking event', described_class.name, 'list_repositories' context 'with project in subgroup' do - let_it_be(:test_group) { create(:group, parent: group ) } + let_it_be(:test_group) { create(:group, parent: group) } it_behaves_like 'renders a list of repositories' diff --git a/spec/controllers/groups/releases_controller_spec.rb b/spec/controllers/groups/releases_controller_spec.rb index 7dd0bc6206a..40e8cb4efc5 100644 --- a/spec/controllers/groups/releases_controller_spec.rb +++ b/spec/controllers/groups/releases_controller_spec.rb @@ -42,7 +42,7 @@ RSpec.describe Groups::ReleasesController do end it 'does not return any releases' do - expect(json_response.map { |r| r['tag'] } ).to be_empty + expect(json_response.map { |r| r['tag'] }).to be_empty end it 'returns OK' do @@ -56,7 +56,7 @@ RSpec.describe Groups::ReleasesController do index - expect(json_response.map { |r| r['tag'] } ).to match_array(%w(p2 p1 v2 v1)) + expect(json_response.map { |r| r['tag'] }).to match_array(%w(p2 p1 v2 v1)) end end diff --git a/spec/controllers/groups/runners_controller_spec.rb b/spec/controllers/groups/runners_controller_spec.rb index 6dbf0803892..2add3cd3b18 100644 --- a/spec/controllers/groups/runners_controller_spec.rb +++ b/spec/controllers/groups/runners_controller_spec.rb @@ -168,7 +168,7 @@ RSpec.describe Groups::RunnersController do new_desc = runner.description.swapcase expect do - post :update, params: params.merge(runner: { description: new_desc } ) + post :update, params: params.merge(runner: { description: new_desc }) end.to change { runner.ensure_runner_queue_value } expect(response).to have_gitlab_http_status(:found) @@ -179,7 +179,7 @@ RSpec.describe Groups::RunnersController do new_desc = instance_runner.description.swapcase expect do - post :update, params: params_runner_instance.merge(runner: { description: new_desc } ) + post :update, params: params_runner_instance.merge(runner: { description: new_desc }) end.to not_change { instance_runner.ensure_runner_queue_value } .and not_change { instance_runner.description } @@ -190,7 +190,7 @@ RSpec.describe Groups::RunnersController do new_desc = project_runner.description.swapcase expect do - post :update, params: params_runner_project.merge(runner: { description: new_desc } ) + post :update, params: params_runner_project.merge(runner: { description: new_desc }) end.to change { project_runner.ensure_runner_queue_value } expect(response).to have_gitlab_http_status(:found) @@ -207,7 +207,7 @@ RSpec.describe Groups::RunnersController do old_desc = runner.description expect do - post :update, params: params.merge(runner: { description: old_desc.swapcase } ) + post :update, params: params.merge(runner: { description: old_desc.swapcase }) end.not_to change { runner.ensure_runner_queue_value } expect(response).to have_gitlab_http_status(:not_found) @@ -218,7 +218,7 @@ RSpec.describe Groups::RunnersController do old_desc = instance_runner.description expect do - post :update, params: params_runner_instance.merge(runner: { description: old_desc.swapcase } ) + post :update, params: params_runner_instance.merge(runner: { description: old_desc.swapcase }) end.not_to change { instance_runner.ensure_runner_queue_value } expect(response).to have_gitlab_http_status(:not_found) @@ -229,7 +229,7 @@ RSpec.describe Groups::RunnersController do old_desc = project_runner.description expect do - post :update, params: params_runner_project.merge(runner: { description: old_desc.swapcase } ) + post :update, params: params_runner_project.merge(runner: { description: old_desc.swapcase }) end.not_to change { project_runner.ensure_runner_queue_value } expect(response).to have_gitlab_http_status(:not_found) diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 5bbe236077c..c127a44a64d 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -672,7 +672,7 @@ RSpec.describe GroupsController, factory_default: :keep do end context 'when there is a conflicting group path' do - let!(:conflict_group) { create(:group, path: SecureRandom.hex(12) ) } + let!(:conflict_group) { create(:group, path: SecureRandom.hex(12)) } let!(:old_name) { group.name } it 'does not render references to the conflicting group' do diff --git a/spec/controllers/omniauth_callbacks_controller_spec.rb b/spec/controllers/omniauth_callbacks_controller_spec.rb index df5da29495e..0560ccb25dd 100644 --- a/spec/controllers/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/omniauth_callbacks_controller_spec.rb @@ -10,7 +10,7 @@ RSpec.describe OmniauthCallbacksController, type: :controller do let(:additional_info) { {} } before do - @original_env_config_omniauth_auth = mock_auth_hash(provider.to_s, extern_uid, user.email, additional_info: additional_info ) + @original_env_config_omniauth_auth = mock_auth_hash(provider.to_s, extern_uid, user.email, additional_info: additional_info) stub_omniauth_provider(provider, context: request) end diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb index 16a43bae674..5927f20df97 100644 --- a/spec/controllers/projects/environments_controller_spec.rb +++ b/spec/controllers/projects/environments_controller_spec.rb @@ -76,7 +76,7 @@ RSpec.describe Projects::EnvironmentsController do it 'handles search option properly' do get :index, params: environment_params(format: :json, search: 'staging/r') - expect(environments.map { |env| env['name'] } ).to contain_exactly('staging/review-1', 'staging/review-2') + expect(environments.map { |env| env['name'] }).to contain_exactly('staging/review-1', 'staging/review-2') expect(json_response['available_count']).to eq 2 expect(json_response['stopped_count']).to eq 1 end @@ -84,7 +84,7 @@ RSpec.describe Projects::EnvironmentsController do it 'ignores search option if is shorter than a minimum' do get :index, params: environment_params(format: :json, search: 'st') - expect(environments.map { |env| env['name'] } ).to contain_exactly('production', + expect(environments.map { |env| env['name'] }).to contain_exactly('production', 'staging/review-1', 'staging/review-2') expect(json_response['available_count']).to eq 3 @@ -233,7 +233,7 @@ RSpec.describe Projects::EnvironmentsController do search: 'staging-1.0/z' }, format: :json) - expect(environments.map { |env| env['name'] } ).to eq(['staging-1.0/zzz']) + expect(environments.map { |env| env['name'] }).to eq(['staging-1.0/zzz']) expect(json_response['available_count']).to eq 1 expect(json_response['stopped_count']).to eq 0 end @@ -705,7 +705,7 @@ RSpec.describe Projects::EnvironmentsController do expect(json_response).to have_key('all_dashboards') expect(json_response['all_dashboards']).to be_an_instance_of(Array) - expect(json_response['all_dashboards']).to all( include('path', 'default', 'display_name') ) + expect(json_response['all_dashboards']).to all(include('path', 'default', 'display_name')) end end diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index 0c3795540e0..55f76be3537 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -1291,7 +1291,7 @@ RSpec.describe Projects::IssuesController do let!(:last_spam_log) { spam_logs.last } def post_verified_issue - post_new_issue({}, { spam_log_id: last_spam_log.id, 'g-recaptcha-response': 'abc123' } ) + post_new_issue({}, { spam_log_id: last_spam_log.id, 'g-recaptcha-response': 'abc123' }) end before do @@ -1311,7 +1311,7 @@ RSpec.describe Projects::IssuesController do it 'does not mark spam log as recaptcha_verified when it does not belong to current_user' do spam_log = create(:spam_log) - expect { post_new_issue({}, { spam_log_id: spam_log.id, 'g-recaptcha-response': true } ) } + expect { post_new_issue({}, { spam_log_id: spam_log.id, 'g-recaptcha-response': true }) } .not_to change { last_spam_log.recaptcha_verified } end end diff --git a/spec/controllers/projects/registry/repositories_controller_spec.rb b/spec/controllers/projects/registry/repositories_controller_spec.rb index a5faaaf5969..e057c56fc53 100644 --- a/spec/controllers/projects/registry/repositories_controller_spec.rb +++ b/spec/controllers/projects/registry/repositories_controller_spec.rb @@ -137,7 +137,7 @@ RSpec.describe Projects::Registry::RepositoriesController do end end - def go_to_index(format: :html, params: {} ) + def go_to_index(format: :html, params: {}) get :index, params: params.merge({ namespace_id: project.namespace, project_id: project diff --git a/spec/controllers/projects/releases_controller_spec.rb b/spec/controllers/projects/releases_controller_spec.rb index b307bb357fa..2afd080344d 100644 --- a/spec/controllers/projects/releases_controller_spec.rb +++ b/spec/controllers/projects/releases_controller_spec.rb @@ -112,7 +112,7 @@ RSpec.describe Projects::ReleasesController do it "returns the project's releases as JSON, ordered by released_at" do get_index - expect(json_response.map { |release| release["id"] } ).to eq([release_2.id, release_1.id]) + expect(json_response.map { |release| release["id"] }).to eq([release_2.id, release_1.id]) end it_behaves_like 'common access controls' diff --git a/spec/controllers/projects/runners_controller_spec.rb b/spec/controllers/projects/runners_controller_spec.rb index 57d1695b842..1066c4ec9f6 100644 --- a/spec/controllers/projects/runners_controller_spec.rb +++ b/spec/controllers/projects/runners_controller_spec.rb @@ -25,7 +25,7 @@ RSpec.describe Projects::RunnersController do new_desc = runner.description.swapcase expect do - post :update, params: params.merge(runner: { description: new_desc } ) + post :update, params: params.merge(runner: { description: new_desc }) end.to change { runner.ensure_runner_queue_value } runner.reload diff --git a/spec/features/admin/admin_settings_spec.rb b/spec/features/admin/admin_settings_spec.rb index 94c5f397670..3474d4c3907 100644 --- a/spec/features/admin/admin_settings_spec.rb +++ b/spec/features/admin/admin_settings_spec.rb @@ -304,10 +304,12 @@ RSpec.describe 'Admin updates settings' do it 'changes the setting' do page.within('#js-jira_connect-settings') do fill_in 'Jira Connect Application ID', with: '1234' + fill_in 'Jira Connect Proxy URL', with: 'https://example.com' click_button 'Save changes' end expect(current_settings.jira_connect_application_key).to eq('1234') + expect(current_settings.jira_connect_proxy_url).to eq('https://example.com') expect(page).to have_content "Application settings saved successfully" end end diff --git a/spec/lib/atlassian/jira_connect/jwt/asymmetric_spec.rb b/spec/lib/atlassian/jira_connect/jwt/asymmetric_spec.rb index b3157dd15fb..86d672067a3 100644 --- a/spec/lib/atlassian/jira_connect/jwt/asymmetric_spec.rb +++ b/spec/lib/atlassian/jira_connect/jwt/asymmetric_spec.rb @@ -16,7 +16,8 @@ RSpec.describe Atlassian::JiraConnect::Jwt::Asymmetric do let(:jwt_headers) { { kid: public_key_id } } let(:jwt) { JWT.encode(jwt_claims, private_key, 'RS256', jwt_headers) } let(:public_key) { private_key.public_key } - let(:install_keys_url) { "https://connect-install-keys.atlassian.com/#{public_key_id}" } + let(:stub_asymmetric_jwt_cdn) { 'https://connect-install-keys.atlassian.com' } + let(:install_keys_url) { "#{stub_asymmetric_jwt_cdn}/#{public_key_id}" } let(:qsh) do Atlassian::Jwt.create_query_string_hash('https://gitlab.test/events/installed', 'POST', 'https://gitlab.test') end @@ -85,6 +86,38 @@ RSpec.describe Atlassian::JiraConnect::Jwt::Asymmetric do it { is_expected.not_to be_valid } end + + context 'with jira_connect_proxy_url setting' do + let(:stub_asymmetric_jwt_cdn) { 'https://example.com/-/jira_connect/public_keys' } + + before do + stub_application_setting(jira_connect_proxy_url: 'https://example.com') + end + + it 'requests the settings CDN' do + expect(JWT).to receive(:decode).twice.and_call_original + + expect(asymmetric_jwt).to be_valid + + expect(WebMock).to have_requested(:get, "https://example.com/-/jira_connect/public_keys/#{public_key_id}") + end + + context 'when jira_connect_oauth_self_managed disabled' do + let(:stub_asymmetric_jwt_cdn) { 'https://connect-install-keys.atlassian.com' } + + before do + stub_feature_flags(jira_connect_oauth_self_managed: false) + end + + it 'requests the default CDN' do + expect(JWT).to receive(:decode).twice.and_call_original + + expect(asymmetric_jwt).to be_valid + + expect(WebMock).to have_requested(:get, install_keys_url) + end + end + end end describe '#iss_claim' do diff --git a/spec/lib/gitlab/background_migration/batched_migration_job_spec.rb b/spec/lib/gitlab/background_migration/batched_migration_job_spec.rb index f03f90ddbbb..95be14cefb1 100644 --- a/spec/lib/gitlab/background_migration/batched_migration_job_spec.rb +++ b/spec/lib/gitlab/background_migration/batched_migration_job_spec.rb @@ -57,6 +57,71 @@ RSpec.describe Gitlab::BackgroundMigration::BatchedMigrationJob do end end + describe '.operation_name' do + subject(:perform_job) { job_instance.perform } + + let(:job_instance) do + job_class.new(start_id: 1, end_id: 10, + batch_table: '_test_table', + batch_column: 'id', + sub_batch_size: 2, + pause_ms: 1000, + job_arguments: %w(a b), + connection: connection) + end + + let(:job_class) do + Class.new(described_class) do + operation_name :update_all + end + end + + it 'defines method' do + expect(job_instance.operation_name).to eq(:update_all) + end + + context 'when `operation_name` is not defined' do + let(:job_class) do + Class.new(described_class) do + def perform + each_sub_batch do |sub_batch| + sub_batch.update_all('to_column = from_column') + end + end + end + end + + let(:test_table) { table(:_test_table) } + let(:test_insert_table) { table(:_test_insert_table) } + + before do + allow(job_instance).to receive(:sleep) + + connection.create_table :_test_table do |t| + t.timestamps_with_timezone null: false + t.integer :from_column, null: false + end + + connection.create_table :_test_insert_table, id: false do |t| + t.integer :to_column + t.index :to_column, unique: true + end + + test_table.create!(id: 1, from_column: 5) + test_table.create!(id: 2, from_column: 10) + end + + after do + connection.drop_table(:_test_table) + connection.drop_table(:_test_insert_table) + end + + it 'raises an exception' do + expect { perform_job }.to raise_error(RuntimeError, /Operation name is required/) + end + end + end + describe '.scope_to' do subject(:job_instance) do job_class.new(start_id: 1, end_id: 10, @@ -133,9 +198,10 @@ RSpec.describe Gitlab::BackgroundMigration::BatchedMigrationJob do context 'when the subclass uses sub-batching' do let(:job_class) do Class.new(described_class) do + operation_name :update + def perform(*job_arguments) each_sub_batch( - operation_name: :update, batching_arguments: { order_hint: :updated_at }, batching_scope: -> (relation) { relation.where.not(bar: nil) } ) do |sub_batch| @@ -177,10 +243,10 @@ RSpec.describe Gitlab::BackgroundMigration::BatchedMigrationJob do let(:job_class) do Class.new(described_class) do scope_to ->(r) { r.where('mod(id, 2) = 0') } + operation_name :update def perform(*job_arguments) each_sub_batch( - operation_name: :update, batching_arguments: { order_hint: :updated_at }, batching_scope: -> (relation) { relation.where.not(bar: nil) } ) do |sub_batch| @@ -237,8 +303,10 @@ RSpec.describe Gitlab::BackgroundMigration::BatchedMigrationJob do let(:job_class) do Class.new(described_class) do + operation_name :insert + def perform(*job_arguments) - distinct_each_batch(operation_name: :insert) do |sub_batch| + distinct_each_batch do |sub_batch| sub_batch.pluck(:from_column).each do |value| connection.execute("INSERT INTO _test_insert_table VALUES (#{value})") end @@ -291,9 +359,10 @@ RSpec.describe Gitlab::BackgroundMigration::BatchedMigrationJob do let(:job_class) do Class.new(described_class) do scope_to ->(r) { r.where.not(from_column: 10) } + operation_name :insert def perform(*job_arguments) - distinct_each_batch(operation_name: :insert) do |sub_batch| + distinct_each_batch do |sub_batch| end end end diff --git a/spec/lib/gitlab/ci/parsers/security/common_spec.rb b/spec/lib/gitlab/ci/parsers/security/common_spec.rb index 253abe38648..03cab021c17 100644 --- a/spec/lib/gitlab/ci/parsers/security/common_spec.rb +++ b/spec/lib/gitlab/ci/parsers/security/common_spec.rb @@ -400,9 +400,9 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do end describe 'parsing tracking' do + let(:finding) { report.findings.first } + context 'with invalid tracking information' do - let(:finding) { report.findings.first } - let(:number_of_findings) { report.findings.length } let(:tracking_data) do { 'type' => 'source', @@ -416,7 +416,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do } end - it 'ignores invalid algorithm types and logs warning' do + it 'ignores invalid algorithm types' do expect(finding.signatures.size).to eq(2) expect(finding.signatures.map(&:algorithm_type).to_set).to eq(Set['hash', 'location']) end @@ -437,7 +437,6 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do end it 'creates signatures for each signature algorithm' do - finding = report.findings.first expect(finding.signatures.size).to eq(3) expect(finding.signatures.map(&:algorithm_type)).to eq(%w[hash location scope_offset]) @@ -449,7 +448,6 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do end it 'sets the uuid according to the higest priority signature' do - finding = report.findings.first highest_signature = finding.signatures.max_by(&:priority) identifiers = if signatures_enabled diff --git a/spec/services/web_hook_service_spec.rb b/spec/services/web_hook_service_spec.rb index 551c3dbcc82..cc8f087cbb6 100644 --- a/spec/services/web_hook_service_spec.rb +++ b/spec/services/web_hook_service_spec.rb @@ -175,22 +175,6 @@ RSpec.describe WebHookService, :request_store, :clean_gitlab_redis_shared_state ).once end - context 'when webhooks_gitlab_instance_header flag is disabled' do - before do - stub_feature_flags(webhooks_gitlab_instance_header: false) - end - - it 'excludes the X-Gitlab-Instance header' do - stub_full_request(project_hook.url, method: :post) - - service_instance.execute - - expect(WebMock).to have_requested(:post, stubbed_hostname(project_hook.url)).with( - headers: headers.except('X-Gitlab-Instance') - ).once - end - end - context 'when the data is a Gitlab::DataBuilder::Pipeline' do let(:pipeline) { create(:ci_pipeline, project: project) } let(:data) { ::Gitlab::DataBuilder::Pipeline.new(pipeline) } diff --git a/spec/support/shared_examples/workers/batched_background_migration_worker_shared_examples.rb b/spec/support/shared_examples/workers/batched_background_migration_worker_shared_examples.rb index 3ba5f080a01..1e70bb31767 100644 --- a/spec/support/shared_examples/workers/batched_background_migration_worker_shared_examples.rb +++ b/spec/support/shared_examples/workers/batched_background_migration_worker_shared_examples.rb @@ -236,10 +236,10 @@ RSpec.shared_examples 'it runs batched background migration jobs' do |tracking_d let(:migration_class) do Class.new(Gitlab::BackgroundMigration::BatchedMigrationJob) do job_arguments :matching_status + operation_name :update_all def perform each_sub_batch( - operation_name: :update_all, batching_scope: -> (relation) { relation.where(status: matching_status) } ) do |sub_batch| sub_batch.update_all(some_column: 0) diff --git a/spec/views/admin/application_settings/_jira_connect.html.haml_spec.rb b/spec/views/admin/application_settings/_jira_connect.html.haml_spec.rb new file mode 100644 index 00000000000..7cfc2db5a41 --- /dev/null +++ b/spec/views/admin/application_settings/_jira_connect.html.haml_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'admin/application_settings/_jira_connect.html.haml' do + let_it_be(:admin) { create(:admin) } + let(:application_setting) { build(:application_setting) } + + before do + assign(:application_setting, application_setting) + allow(view).to receive(:expanded).and_return(true) + end + + it 'renders the application ID field' do + render + expect(rendered).to have_field('Jira Connect Application ID', type: 'text') + end + + it 'renders the asymmetric jwt cdn url field' do + render + expect(rendered).to have_field('Jira Connect Proxy URL', type: 'text') + end +end diff --git a/spec/views/admin/application_settings/general.html.haml_spec.rb b/spec/views/admin/application_settings/general.html.haml_spec.rb index a9c470e49df..a8c7bec36e3 100644 --- a/spec/views/admin/application_settings/general.html.haml_spec.rb +++ b/spec/views/admin/application_settings/general.html.haml_spec.rb @@ -69,8 +69,8 @@ RSpec.describe 'admin/application_settings/general.html.haml' do end end - describe 'jira connect application key' do - it 'shows the jira connect application key section' do + describe 'jira connect settings' do + it 'shows the jira connect settings section' do render expect(rendered).to have_css('#js-jira_connect-settings') @@ -81,7 +81,7 @@ RSpec.describe 'admin/application_settings/general.html.haml' do stub_feature_flags(jira_connect_oauth_self_managed_setting: false) end - it 'does not show the jira connect application key section' do + it 'does not show the jira connect settings section' do render expect(rendered).not_to have_css('#js-jira_connect-settings') |