diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-11 21:14:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-11 21:14:04 +0300 |
commit | 11c2b8eff6ca5360fb0f732b23b764d2a0b81be5 (patch) | |
tree | 7f92622462127ff24023283133f81d9c4b2f6842 /spec | |
parent | e40f19ef830c5863089bc6a7a73e6695efa60a13 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
11 files changed, 249 insertions, 132 deletions
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index 382ce0feda0..0f1c6ae4c70 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -1408,7 +1408,7 @@ RSpec.describe Projects::IssuesController do end end - context 'when the endpoint receives requests above the limit' do + context 'when the endpoint receives requests above the limit', :freeze_time, :clean_gitlab_redis_rate_limiting do before do stub_application_setting(issues_create_limit: 5) end diff --git a/spec/experiments/change_continuous_onboarding_link_urls_experiment_spec.rb b/spec/experiments/change_continuous_onboarding_link_urls_experiment_spec.rb new file mode 100644 index 00000000000..815aaf7c397 --- /dev/null +++ b/spec/experiments/change_continuous_onboarding_link_urls_experiment_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ChangeContinuousOnboardingLinkUrlsExperiment, :snowplow do + before do + stub_experiments(change_continuous_onboarding_link_urls: 'control') + end + + describe '#track' do + context 'when no namespace has been set' do + it 'tracks the action as normal' do + subject.track(:some_action) + + expect_snowplow_event( + category: subject.name, + action: 'some_action', + namespace: nil, + context: [ + { + schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0', + data: an_instance_of(Hash) + } + ] + ) + end + end + + context 'when a namespace has been set' do + let_it_be(:namespace) { create(:namespace) } + + before do + subject.namespace = namespace + end + + it 'tracks the action and merges the namespace into the event args' do + subject.track(:some_action) + + expect_snowplow_event( + category: subject.name, + action: 'some_action', + namespace: namespace, + context: [ + { + schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0', + data: an_instance_of(Hash) + } + ] + ) + end + end + end +end diff --git a/spec/features/admin/admin_deploy_keys_spec.rb b/spec/features/admin/admin_deploy_keys_spec.rb index fd74a13deff..53caf0fac33 100644 --- a/spec/features/admin/admin_deploy_keys_spec.rb +++ b/spec/features/admin/admin_deploy_keys_spec.rb @@ -17,7 +17,7 @@ RSpec.describe 'admin deploy keys' do it 'show all public deploy keys' do visit admin_deploy_keys_path - page.within(find('.deploy-keys-list', match: :first)) do + page.within(find('[data-testid="deploy-keys-list"]', match: :first)) do expect(page).to have_content(deploy_key.title) expect(page).to have_content(another_deploy_key.title) end @@ -28,7 +28,7 @@ RSpec.describe 'admin deploy keys' do visit admin_deploy_keys_path - page.within(find('.deploy-keys-list', match: :first)) do + page.within(find('[data-testid="deploy-keys-list"]', match: :first)) do expect(page).to have_content(write_key.project.full_name) end end @@ -48,7 +48,7 @@ RSpec.describe 'admin deploy keys' do expect(current_path).to eq admin_deploy_keys_path - page.within(find('.deploy-keys-list', match: :first)) do + page.within(find('[data-testid="deploy-keys-list"]', match: :first)) do expect(page).to have_content('laptop') end end @@ -66,7 +66,7 @@ RSpec.describe 'admin deploy keys' do expect(current_path).to eq admin_deploy_keys_path - page.within(find('.deploy-keys-list', match: :first)) do + page.within(find('[data-testid="deploy-keys-list"]', match: :first)) do expect(page).to have_content('new-title') end end @@ -81,7 +81,7 @@ RSpec.describe 'admin deploy keys' do find('tr', text: deploy_key.title).click_link('Remove') expect(current_path).to eq admin_deploy_keys_path - page.within(find('.deploy-keys-list', match: :first)) do + page.within(find('[data-testid="deploy-keys-list"]', match: :first)) do expect(page).not_to have_content(deploy_key.title) end end diff --git a/spec/frontend/lib/apollo/suppress_network_errors_during_navigation_link_spec.js b/spec/frontend/lib/apollo/suppress_network_errors_during_navigation_link_spec.js index 852106db44e..7b604724977 100644 --- a/spec/frontend/lib/apollo/suppress_network_errors_during_navigation_link_spec.js +++ b/spec/frontend/lib/apollo/suppress_network_errors_during_navigation_link_spec.js @@ -47,107 +47,95 @@ describe('getSuppressNetworkErrorsDuringNavigationLink', () => { subscription = link.request(mockOperation).subscribe(observer); }; - describe('when disabled', () => { - it('returns null', () => { - expect(getSuppressNetworkErrorsDuringNavigationLink()).toBe(null); - }); + it('returns an ApolloLink', () => { + expect(getSuppressNetworkErrorsDuringNavigationLink()).toEqual(expect.any(ApolloLink)); }); - describe('when enabled', () => { - beforeEach(() => { - window.gon = { features: { suppressApolloErrorsDuringNavigation: true } }; - }); - - it('returns an ApolloLink', () => { - expect(getSuppressNetworkErrorsDuringNavigationLink()).toEqual(expect.any(ApolloLink)); - }); - - describe('suppression case', () => { - describe('when navigating away', () => { - beforeEach(() => { - isNavigatingAway.mockReturnValue(true); - }); - - describe('given a network error', () => { - it('does not forward the error', async () => { - const spy = jest.fn(); + describe('suppression case', () => { + describe('when navigating away', () => { + beforeEach(() => { + isNavigatingAway.mockReturnValue(true); + }); - createSubscription(makeMockNetworkErrorLink(), { - next: spy, - error: spy, - complete: spy, - }); + describe('given a network error', () => { + it('does not forward the error', async () => { + const spy = jest.fn(); - // It's hard to test for something _not_ happening. The best we can - // do is wait a bit to make sure nothing happens. - await waitForPromises(); - expect(spy).not.toHaveBeenCalled(); + createSubscription(makeMockNetworkErrorLink(), { + next: spy, + error: spy, + complete: spy, }); + + // It's hard to test for something _not_ happening. The best we can + // do is wait a bit to make sure nothing happens. + await waitForPromises(); + expect(spy).not.toHaveBeenCalled(); }); }); }); + }); - describe('non-suppression cases', () => { - describe('when not navigating away', () => { - beforeEach(() => { - isNavigatingAway.mockReturnValue(false); - }); + describe('non-suppression cases', () => { + describe('when not navigating away', () => { + beforeEach(() => { + isNavigatingAway.mockReturnValue(false); + }); - it('forwards successful requests', (done) => { - createSubscription(makeMockSuccessLink(), { - next({ data }) { - expect(data).toEqual({ foo: { id: 1 } }); - }, - error: () => done.fail('Should not happen'), - complete: () => done(), - }); + it('forwards successful requests', (done) => { + createSubscription(makeMockSuccessLink(), { + next({ data }) { + expect(data).toEqual({ foo: { id: 1 } }); + }, + error: () => done.fail('Should not happen'), + complete: () => done(), }); + }); - it('forwards GraphQL errors', (done) => { - createSubscription(makeMockGraphQLErrorLink(), { - next({ errors }) { - expect(errors).toEqual([{ message: 'foo' }]); - }, - error: () => done.fail('Should not happen'), - complete: () => done(), - }); + it('forwards GraphQL errors', (done) => { + createSubscription(makeMockGraphQLErrorLink(), { + next({ errors }) { + expect(errors).toEqual([{ message: 'foo' }]); + }, + error: () => done.fail('Should not happen'), + complete: () => done(), }); + }); - it('forwards network errors', (done) => { - createSubscription(makeMockNetworkErrorLink(), { - next: () => done.fail('Should not happen'), - error: (error) => { - expect(error.message).toBe('NetworkError'); - done(); - }, - complete: () => done.fail('Should not happen'), - }); + it('forwards network errors', (done) => { + createSubscription(makeMockNetworkErrorLink(), { + next: () => done.fail('Should not happen'), + error: (error) => { + expect(error.message).toBe('NetworkError'); + done(); + }, + complete: () => done.fail('Should not happen'), }); }); + }); - describe('when navigating away', () => { - beforeEach(() => { - isNavigatingAway.mockReturnValue(true); - }); + describe('when navigating away', () => { + beforeEach(() => { + isNavigatingAway.mockReturnValue(true); + }); - it('forwards successful requests', (done) => { - createSubscription(makeMockSuccessLink(), { - next({ data }) { - expect(data).toEqual({ foo: { id: 1 } }); - }, - error: () => done.fail('Should not happen'), - complete: () => done(), - }); + it('forwards successful requests', (done) => { + createSubscription(makeMockSuccessLink(), { + next({ data }) { + expect(data).toEqual({ foo: { id: 1 } }); + }, + error: () => done.fail('Should not happen'), + complete: () => done(), }); + }); - it('forwards GraphQL errors', (done) => { - createSubscription(makeMockGraphQLErrorLink(), { - next({ errors }) { - expect(errors).toEqual([{ message: 'foo' }]); - }, - error: () => done.fail('Should not happen'), - complete: () => done(), - }); + it('forwards GraphQL errors', (done) => { + createSubscription(makeMockGraphQLErrorLink(), { + next({ errors }) { + expect(errors).toEqual([{ message: 'foo' }]); + }, + error: () => done.fail('Should not happen'), + complete: () => done(), }); }); }); diff --git a/spec/frontend/pages/projects/learn_gitlab/components/__snapshots__/learn_gitlab_spec.js.snap b/spec/frontend/pages/projects/learn_gitlab/components/__snapshots__/learn_gitlab_spec.js.snap index 3aa0e99a858..3e371a8765f 100644 --- a/spec/frontend/pages/projects/learn_gitlab/components/__snapshots__/learn_gitlab_spec.js.snap +++ b/spec/frontend/pages/projects/learn_gitlab/components/__snapshots__/learn_gitlab_spec.js.snap @@ -135,6 +135,7 @@ exports[`Learn GitLab renders correctly 1`] = ` <a class="gl-link" data-track-action="click_link" + data-track-experiment="change_continuous_onboarding_link_urls" data-track-label="Set up CI/CD" data-track-property="Growth::Conversion::Experiment::LearnGitLab" href="http://example.com/" @@ -156,6 +157,7 @@ exports[`Learn GitLab renders correctly 1`] = ` <a class="gl-link" data-track-action="click_link" + data-track-experiment="change_continuous_onboarding_link_urls" data-track-label="Start a free Ultimate trial" data-track-property="Growth::Conversion::Experiment::LearnGitLab" href="http://example.com/" @@ -177,6 +179,7 @@ exports[`Learn GitLab renders correctly 1`] = ` <a class="gl-link" data-track-action="click_link" + data-track-experiment="change_continuous_onboarding_link_urls" data-track-label="Add code owners" data-track-property="Growth::Conversion::Experiment::LearnGitLab" href="http://example.com/" @@ -205,6 +208,7 @@ exports[`Learn GitLab renders correctly 1`] = ` <a class="gl-link" data-track-action="click_link" + data-track-experiment="change_continuous_onboarding_link_urls" data-track-label="Add merge request approval" data-track-property="Growth::Conversion::Experiment::LearnGitLab" href="http://example.com/" @@ -269,6 +273,7 @@ exports[`Learn GitLab renders correctly 1`] = ` <a class="gl-link" data-track-action="click_link" + data-track-experiment="change_continuous_onboarding_link_urls" data-track-label="Create an issue" data-track-property="Growth::Conversion::Experiment::LearnGitLab" href="http://example.com/" @@ -290,6 +295,7 @@ exports[`Learn GitLab renders correctly 1`] = ` <a class="gl-link" data-track-action="click_link" + data-track-experiment="change_continuous_onboarding_link_urls" data-track-label="Submit a merge request" data-track-property="Growth::Conversion::Experiment::LearnGitLab" href="http://example.com/" @@ -347,6 +353,7 @@ exports[`Learn GitLab renders correctly 1`] = ` <a class="gl-link" data-track-action="click_link" + data-track-experiment="change_continuous_onboarding_link_urls" data-track-label="Run a Security scan using CI/CD" data-track-property="Growth::Conversion::Experiment::LearnGitLab" href="http://example.com/" diff --git a/spec/lib/gitlab/content_security_policy/config_loader_spec.rb b/spec/lib/gitlab/content_security_policy/config_loader_spec.rb index 5892bae5c0b..c0476d38380 100644 --- a/spec/lib/gitlab/content_security_policy/config_loader_spec.rb +++ b/spec/lib/gitlab/content_security_policy/config_loader_spec.rb @@ -81,11 +81,11 @@ RSpec.describe Gitlab::ContentSecurityPolicy::ConfigLoader do end it 'adds CDN host to CSP' do - expect(directives['script_src']).to eq("'strict-dynamic' 'self' 'unsafe-inline' 'unsafe-eval' https://www.google.com/recaptcha/ https://www.recaptcha.net https://apis.google.com https://cdn.example.com") + expect(directives['script_src']).to eq(::Gitlab::ContentSecurityPolicy::Directives.script_src + " https://cdn.example.com") expect(directives['style_src']).to eq("'self' 'unsafe-inline' https://cdn.example.com") expect(directives['font_src']).to eq("'self' https://cdn.example.com") expect(directives['worker_src']).to eq('http://localhost/assets/ blob: data: https://cdn.example.com') - expect(directives['frame_src']).to eq("https://www.google.com/recaptcha/ https://www.recaptcha.net/ https://content.googleapis.com https://content-compute.googleapis.com https://content-cloudbilling.googleapis.com https://content-cloudresourcemanager.googleapis.com https://cdn.example.com http://localhost/admin/sidekiq http://localhost/admin/sidekiq/ http://localhost/-/speedscope/index.html") + expect(directives['frame_src']).to eq(::Gitlab::ContentSecurityPolicy::Directives.frame_src + " https://cdn.example.com http://localhost/admin/sidekiq http://localhost/admin/sidekiq/ http://localhost/-/speedscope/index.html") end end @@ -113,7 +113,7 @@ RSpec.describe Gitlab::ContentSecurityPolicy::ConfigLoader do end it 'does not add CUSTOMER_PORTAL_URL to CSP' do - expect(directives['frame_src']).to eq("https://www.google.com/recaptcha/ https://www.recaptcha.net/ https://content.googleapis.com https://content-compute.googleapis.com https://content-cloudbilling.googleapis.com https://content-cloudresourcemanager.googleapis.com http://localhost/admin/sidekiq http://localhost/admin/sidekiq/ http://localhost/-/speedscope/index.html") + expect(directives['frame_src']).to eq(::Gitlab::ContentSecurityPolicy::Directives.frame_src + " http://localhost/admin/sidekiq http://localhost/admin/sidekiq/ http://localhost/-/speedscope/index.html") end end @@ -123,7 +123,7 @@ RSpec.describe Gitlab::ContentSecurityPolicy::ConfigLoader do end it 'adds CUSTOMER_PORTAL_URL to CSP' do - expect(directives['frame_src']).to eq("https://www.google.com/recaptcha/ https://www.recaptcha.net/ https://content.googleapis.com https://content-compute.googleapis.com https://content-cloudbilling.googleapis.com https://content-cloudresourcemanager.googleapis.com http://localhost/rails/letter_opener/ https://customers.example.com http://localhost/admin/sidekiq http://localhost/admin/sidekiq/ http://localhost/-/speedscope/index.html") + expect(directives['frame_src']).to eq(::Gitlab::ContentSecurityPolicy::Directives.frame_src + " http://localhost/rails/letter_opener/ https://customers.example.com http://localhost/admin/sidekiq http://localhost/admin/sidekiq/ http://localhost/-/speedscope/index.html") end end end diff --git a/spec/lib/gitlab/database/partitioning_spec.rb b/spec/lib/gitlab/database/partitioning_spec.rb index 7855e0aabf9..154cc2b7972 100644 --- a/spec/lib/gitlab/database/partitioning_spec.rb +++ b/spec/lib/gitlab/database/partitioning_spec.rb @@ -30,6 +30,39 @@ RSpec.describe Gitlab::Database::Partitioning do end end + describe '.sync_partitions_ignore_db_error' do + it 'calls sync_partitions' do + expect(described_class).to receive(:sync_partitions) + + described_class.sync_partitions_ignore_db_error + end + + [ActiveRecord::ActiveRecordError, PG::Error].each do |error| + context "when #{error} is raised" do + before do + expect(described_class).to receive(:sync_partitions) + .and_raise(error) + end + + it 'ignores it' do + described_class.sync_partitions_ignore_db_error + end + end + end + + context 'when DISABLE_POSTGRES_PARTITION_CREATION_ON_STARTUP is set' do + before do + stub_env('DISABLE_POSTGRES_PARTITION_CREATION_ON_STARTUP', '1') + end + + it 'does not call sync_partitions' do + expect(described_class).to receive(:sync_partitions).never + + described_class.sync_partitions_ignore_db_error + end + end + end + describe '.sync_partitions' do let(:table_names) { %w[partitioning_test1 partitioning_test2] } let(:models) do diff --git a/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb b/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb index 942ac67c39d..93b3566b709 100644 --- a/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb +++ b/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb @@ -259,7 +259,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do end end - context 'when rate limiting is in effect', :clean_gitlab_redis_cache do + context 'when rate limiting is in effect', :freeze_time, :clean_gitlab_redis_rate_limiting do let(:receiver) { Gitlab::Email::Receiver.new(email_raw) } subject { 2.times { receiver.execute } } @@ -271,18 +271,14 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do context 'when too many requests are sent by one user' do it 'raises an error' do - freeze_time do - expect { subject }.to raise_error(RateLimitedService::RateLimitedError) - end + expect { subject }.to raise_error(RateLimitedService::RateLimitedError) end it 'creates 1 issue' do - freeze_time do - expect do - subject - rescue RateLimitedService::RateLimitedError - end.to change { Issue.count }.by(1) - end + expect do + subject + rescue RateLimitedService::RateLimitedError + end.to change { Issue.count }.by(1) end context 'when requests are sent by different users' do @@ -295,9 +291,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do end it 'creates 2 issues' do - freeze_time do - expect { subject }.to change { Issue.count }.by(2) - end + expect { subject }.to change { Issue.count }.by(2) end end end @@ -308,9 +302,7 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do end it 'creates 2 issues' do - freeze_time do - expect { subject }.to change { Issue.count }.by(2) - end + expect { subject }.to change { Issue.count }.by(2) end end end diff --git a/spec/policies/project_policy_spec.rb b/spec/policies/project_policy_spec.rb index 67d7e49f8db..2953c198af6 100644 --- a/spec/policies/project_policy_spec.rb +++ b/spec/policies/project_policy_spec.rb @@ -104,29 +104,71 @@ RSpec.describe ProjectPolicy do end context 'pipeline feature' do - let(:project) { private_project } + let(:project) { private_project } + let(:current_user) { developer } + let(:pipeline) { create(:ci_pipeline, project: project) } - before do - private_project.add_developer(current_user) + describe 'for confirmed user' do + it 'allows modify pipelines' do + expect_allowed(:create_pipeline) + expect_allowed(:update_pipeline) + expect_allowed(:create_pipeline_schedule) + end end describe 'for unconfirmed user' do - let(:current_user) { create(:user, confirmed_at: nil) } + let(:current_user) { project.owner.tap { |u| u.update!(confirmed_at: nil) } } it 'disallows to modify pipelines' do expect_disallowed(:create_pipeline) expect_disallowed(:update_pipeline) + expect_disallowed(:destroy_pipeline) expect_disallowed(:create_pipeline_schedule) end end - describe 'for confirmed user' do - let(:current_user) { developer } + describe 'destroy permission' do + describe 'for developers' do + it 'prevents :destroy_pipeline' do + expect(current_user.can?(:destroy_pipeline, pipeline)).to be_falsey + end + end - it 'allows modify pipelines' do - expect_allowed(:create_pipeline) - expect_allowed(:update_pipeline) - expect_allowed(:create_pipeline_schedule) + describe 'for maintainers' do + let(:current_user) { maintainer } + + it 'prevents :destroy_pipeline' do + project.add_maintainer(maintainer) + expect(current_user.can?(:destroy_pipeline, pipeline)).to be_falsey + end + end + + describe 'for project owner' do + let(:current_user) { project.owner } + + it 'allows :destroy_pipeline' do + expect(current_user.can?(:destroy_pipeline, pipeline)).to be_truthy + end + + context 'on archived projects' do + before do + project.update!(archived: true) + end + + it 'prevents :destroy_pipeline' do + expect(current_user.can?(:destroy_pipeline, pipeline)).to be_falsey + end + end + + context 'on archived pending_delete projects' do + before do + project.update!(archived: true, pending_delete: true) + end + + it 'allows :destroy_pipeline' do + expect(current_user.can?(:destroy_pipeline, pipeline)).to be_truthy + end + end end end end diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb index 3ea447b2384..57fcdf84163 100644 --- a/spec/services/issues/create_service_spec.rb +++ b/spec/services/issues/create_service_spec.rb @@ -302,7 +302,7 @@ RSpec.describe Issues::CreateService do described_class.new(project: project, current_user: user, params: opts, spam_params: spam_params).execute end - context 'when rate limiting is in effect', :clean_gitlab_redis_cache do + context 'when rate limiting is in effect', :freeze_time, :clean_gitlab_redis_rate_limiting do let(:user) { create(:user) } before do @@ -316,20 +316,16 @@ RSpec.describe Issues::CreateService do context 'when too many requests are sent by one user' do it 'raises an error' do - freeze_time do - expect do - subject - end.to raise_error(RateLimitedService::RateLimitedError) - end + expect do + subject + end.to raise_error(RateLimitedService::RateLimitedError) end it 'creates 1 issue' do - freeze_time do - expect do - subject - rescue RateLimitedService::RateLimitedError - end.to change { Issue.count }.by(1) - end + expect do + subject + rescue RateLimitedService::RateLimitedError + end.to change { Issue.count }.by(1) end end @@ -339,9 +335,7 @@ RSpec.describe Issues::CreateService do end it 'creates 2 issues' do - freeze_time do - expect { subject }.to change { Issue.count }.by(2) - end + expect { subject }.to change { Issue.count }.by(2) end end end diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb index 9bdd9800fcc..ac84614121a 100644 --- a/spec/services/projects/destroy_service_spec.rb +++ b/spec/services/projects/destroy_service_spec.rb @@ -331,6 +331,14 @@ RSpec.describe Projects::DestroyService, :aggregate_failures do end end end + + context 'for an archived project' do + before do + project.update!(archived: true) + end + + it_behaves_like 'deleting the project with pipeline and build' + end end describe 'container registry' do |