diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-29 18:10:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-29 18:10:07 +0300 |
commit | c5e4f06c597e7ef9b584595a55a82cb221804e4b (patch) | |
tree | 2db854553738bf601a40d427dbb9eaf5516be027 /spec | |
parent | db36dea03b0e56ed242eb290c51be88ca4c61a65 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
18 files changed, 251 insertions, 93 deletions
diff --git a/spec/config/object_store_settings_spec.rb b/spec/config/object_store_settings_spec.rb index 68b37197ca7..33443509e4a 100644 --- a/spec/config/object_store_settings_spec.rb +++ b/spec/config/object_store_settings_spec.rb @@ -74,6 +74,7 @@ RSpec.describe ObjectStoreSettings do expect(settings.artifacts['object_store']['proxy_download']).to be false expect(settings.artifacts['object_store']['remote_directory']).to eq('artifacts') expect(settings.artifacts['object_store']['consolidated_settings']).to be true + expect(settings.artifacts).to eq(settings['artifacts']) expect(settings.lfs['enabled']).to be true expect(settings.lfs['object_store']['enabled']).to be true @@ -83,15 +84,18 @@ RSpec.describe ObjectStoreSettings do expect(settings.lfs['object_store']['proxy_download']).to be true expect(settings.lfs['object_store']['remote_directory']).to eq('lfs-objects') expect(settings.lfs['object_store']['consolidated_settings']).to be true + expect(settings.lfs).to eq(settings['lfs']) expect(settings.pages['enabled']).to be true expect(settings.pages['object_store']['enabled']).to be true expect(settings.pages['object_store']['connection']).to eq(connection) expect(settings.pages['object_store']['remote_directory']).to eq('pages') expect(settings.pages['object_store']['consolidated_settings']).to be true + expect(settings.pages).to eq(settings['pages']) expect(settings.external_diffs['enabled']).to be false expect(settings.external_diffs['object_store']).to be_nil + expect(settings.external_diffs).to eq(settings['external_diffs']) end it 'raises an error when a bucket is missing' do diff --git a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb index 50f8942d9d5..41d3cac63a6 100644 --- a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb @@ -180,7 +180,8 @@ RSpec.describe Projects::MergeRequests::DiffsController do start_version: nil, start_sha: nil, commit: nil, - latest_diff: true + latest_diff: true, + only_context_commits: false } expect_next_instance_of(DiffsMetadataSerializer) do |instance| @@ -261,7 +262,8 @@ RSpec.describe Projects::MergeRequests::DiffsController do start_version: nil, start_sha: nil, commit: nil, - latest_diff: true + latest_diff: true, + only_context_commits: false } expect_next_instance_of(DiffsMetadataSerializer) do |instance| @@ -290,7 +292,8 @@ RSpec.describe Projects::MergeRequests::DiffsController do start_version: nil, start_sha: nil, commit: merge_request.diff_head_commit, - latest_diff: nil + latest_diff: nil, + only_context_commits: false } expect_next_instance_of(DiffsMetadataSerializer) do |instance| diff --git a/spec/factories/ci/pipeline_artifacts.rb b/spec/factories/ci/pipeline_artifacts.rb index 3250c7abb4b..85277ce6fbf 100644 --- a/spec/factories/ci/pipeline_artifacts.rb +++ b/spec/factories/ci/pipeline_artifacts.rb @@ -13,6 +13,10 @@ FactoryBot.define do Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage.json'), 'application/json') end + trait :unlocked do + association :pipeline, :unlocked, factory: :ci_pipeline + end + trait :checksummed do verification_checksum { 'abc' } end diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb index ce75d80e822..4fc7d945881 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -81,6 +81,10 @@ FactoryBot.define do status { :failed } end + trait :unlocked do + locked { Ci::Pipeline.lockeds[:unlocked] } + end + trait :protected do add_attribute(:protected) { true } end diff --git a/spec/features/user_can_display_performance_bar_spec.rb b/spec/features/user_can_display_performance_bar_spec.rb index b8f41925156..14b5964686f 100644 --- a/spec/features/user_can_display_performance_bar_spec.rb +++ b/spec/features/user_can_display_performance_bar_spec.rb @@ -47,7 +47,7 @@ RSpec.describe 'User can display performance bar', :js do end end - let(:group) { create(:group) } + let_it_be(:group) { create(:group) } before do allow(GitlabPerformanceBarStatsWorker).to receive(:perform_in) @@ -123,4 +123,38 @@ RSpec.describe 'User can display performance bar', :js do end end end + + context 'flamegraphs' do + let_it_be(:user) { create(:user) } + + before_all do + group.add_guest(user) + end + + context 'when user has access' do + before do + stub_application_setting(performance_bar_allowed_group_id: group.id) + + Warden.on_next_request do |proxy| + proxy.set_user(user) + end + end + + it 'renders flamegraph when requested' do + visit root_path(performance_bar: 'flamegraph') + + page.within_frame 'speedscope-iframe' do + expect(page).to have_content('Flamegraph for /') + end + end + end + + context 'when user does not have access' do + it 'renders the original page' do + visit root_path(performance_bar: 'flamegraph') + + expect(page).not_to have_selector('iframe#speedscope-iframe') + end + end + end end diff --git a/spec/frontend/boards/components/board_card_spec.js b/spec/frontend/boards/components/board_card_spec.js index 022f8c05e1e..e95cb17ee84 100644 --- a/spec/frontend/boards/components/board_card_spec.js +++ b/spec/frontend/boards/components/board_card_spec.js @@ -1,4 +1,5 @@ -import { createLocalVue, shallowMount } from '@vue/test-utils'; +import { GlLabel } from '@gitlab/ui'; +import { createLocalVue, shallowMount, mount } from '@vue/test-utils'; import Vuex from 'vuex'; import BoardCard from '~/boards/components/board_card.vue'; @@ -18,6 +19,7 @@ describe('Board card', () => { mockActions = { toggleBoardItem: jest.fn(), toggleBoardItemMultiSelection: jest.fn(), + performSearch: jest.fn(), }; store = new Vuex.Store({ @@ -35,12 +37,15 @@ describe('Board card', () => { }; // this particular mount component needs to be used after the root beforeEach because it depends on list being initialized - const mountComponent = ({ propsData = {}, provide = {} } = {}) => { - wrapper = shallowMount(BoardCard, { + const mountComponent = ({ + propsData = {}, + provide = {}, + mountFn = shallowMount, + stubs = { BoardCardInner }, + } = {}) => { + wrapper = mountFn(BoardCard, { localVue, - stubs: { - BoardCardInner, - }, + stubs, store, propsData: { list: mockLabelList, @@ -74,6 +79,17 @@ describe('Board card', () => { store = null; }); + describe('when GlLabel is clicked in BoardCardInner', () => { + it('doesnt call toggleBoardItem', () => { + createStore({ initialState: { isShowingLabels: true } }); + mountComponent({ mountFn: mount, stubs: {} }); + + wrapper.find(GlLabel).trigger('mouseup'); + + expect(mockActions.toggleBoardItem).toHaveBeenCalledTimes(0); + }); + }); + describe.each` isSwimlanesOn ${true} | ${false} diff --git a/spec/frontend/flash_spec.js b/spec/frontend/flash_spec.js index 6d482e5814d..6a5ac76a4d0 100644 --- a/spec/frontend/flash_spec.js +++ b/spec/frontend/flash_spec.js @@ -339,6 +339,20 @@ describe('Flash', () => { expect(actionConfig.clickHandler).toHaveBeenCalled(); }); }); + + describe('additional behavior', () => { + describe('close', () => { + it('clicks the close icon', () => { + const flash = createFlash({ ...defaultParams }); + const close = document.querySelector('.flash-alert .js-close-icon'); + + jest.spyOn(close, 'click'); + flash.close(); + + expect(close.click.mock.calls.length).toBe(1); + }); + }); + }); }); }); diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 124cdcec05d..a311d783996 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -400,25 +400,6 @@ RSpec.describe ProjectsHelper do helper.send(:get_project_nav_tabs, project, user) end - context 'Security & Compliance tabs' do - before do - allow(helper).to receive(:can?).with(user, :read_security_configuration, project).and_return(can_read_security_configuration) - end - - context 'when user cannot read security configuration' do - let(:can_read_security_configuration) { false } - - it { is_expected.not_to include(:security_configuration) } - end - - context 'when user can read security configuration' do - let(:can_read_security_configuration) { true } - let(:feature_flag_enabled) { true } - - it { is_expected.to include(:security_configuration) } - end - end - context 'when builds feature is enabled' do before do allow(project).to receive(:builds_enabled?).and_return(true) diff --git a/spec/lib/gitlab/import_export/command_line_util_spec.rb b/spec/lib/gitlab/import_export/command_line_util_spec.rb index 67cf13780c3..b00a2597681 100644 --- a/spec/lib/gitlab/import_export/command_line_util_spec.rb +++ b/spec/lib/gitlab/import_export/command_line_util_spec.rb @@ -16,10 +16,6 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do def initialize @shared = Gitlab::ImportExport::Shared.new(nil) end - - def execute_download(url) - download(url, 'path') - end end.new end @@ -39,29 +35,4 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do it 'has the right mask for uploads' do expect(file_permissions("#{path}/uploads")).to eq(0755) # originally 555 end - - context 'validates the URL before executing the download' do - before do - stub_application_setting(allow_local_requests_from_web_hooks_and_services: false) - end - - it 'raises error when the given URL is blocked' do - expect { subject.execute_download('http://localhost:3000/file') } - .to raise_error(Gitlab::UrlBlocker::BlockedUrlError, 'Requests to localhost are not allowed') - end - - it 'executes the download when the URL is allowed' do - expect_next_instance_of(URI::HTTP) do |uri| - expect(uri) - .to receive(:open) - .and_return('file content') - end - - expect(IO) - .to receive(:copy_stream) - .with('file content', instance_of(File)) - - subject.execute_download('http://some.url.remote/file') - end - end end diff --git a/spec/models/ci/pipeline_artifact_spec.rb b/spec/models/ci/pipeline_artifact_spec.rb index 3fe09f05cab..f65483d2290 100644 --- a/spec/models/ci/pipeline_artifact_spec.rb +++ b/spec/models/ci/pipeline_artifact_spec.rb @@ -50,6 +50,30 @@ RSpec.describe Ci::PipelineArtifact, type: :model do end end + describe 'scopes' do + describe '.unlocked' do + subject(:pipeline_artifacts) { described_class.unlocked } + + context 'when pipeline is locked' do + it 'returns an empty collection' do + expect(pipeline_artifacts).to be_empty + end + end + + context 'when pipeline is unlocked' do + before do + create(:ci_pipeline_artifact, :with_coverage_report) + end + + it 'returns unlocked artifacts' do + codequality_report = create(:ci_pipeline_artifact, :with_codequality_mr_diff_report, :unlocked) + + expect(pipeline_artifacts).to eq([codequality_report]) + end + end + end + end + describe 'file is being stored' do subject { create(:ci_pipeline_artifact, :with_coverage_report) } diff --git a/spec/models/context_commits_diff_spec.rb b/spec/models/context_commits_diff_spec.rb new file mode 100644 index 00000000000..6e03ea2745e --- /dev/null +++ b/spec/models/context_commits_diff_spec.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ContextCommitsDiff do + let_it_be(:sha1) { "33f3729a45c02fc67d00adb1b8bca394b0e761d9" } + let_it_be(:sha2) { "ae73cb07c9eeaf35924a10f713b364d32b2dd34f" } + let_it_be(:sha3) { "0b4bc9a49b562e85de7cc9e834518ea6828729b9" } + let_it_be(:merge_request) { create(:merge_request) } + let_it_be(:project) { merge_request.project } + let_it_be(:mrcc1) { create(:merge_request_context_commit, merge_request: merge_request, sha: sha1, committed_date: project.commit_by(oid: sha1).committed_date) } + let_it_be(:mrcc2) { create(:merge_request_context_commit, merge_request: merge_request, sha: sha2, committed_date: project.commit_by(oid: sha2).committed_date) } + let_it_be(:mrcc3) { create(:merge_request_context_commit, merge_request: merge_request, sha: sha3, committed_date: project.commit_by(oid: sha3).committed_date) } + + subject { merge_request.context_commits_diff } + + describe ".empty?" do + it 'checks if empty' do + expect(subject.empty?).to be(false) + end + end + + describe '.commits_count' do + it 'reports commits count' do + expect(subject.commits_count).to be(3) + end + end + + describe '.diffs' do + it 'returns instance of Gitlab::Diff::FileCollection::Compare' do + expect(subject.diffs).to be_a(Gitlab::Diff::FileCollection::Compare) + end + + it 'returns all diffs between first and last commits' do + expect(subject.diffs.diff_files.size).to be(5) + end + end + + describe '.raw_diffs' do + before do + allow(subject).to receive(:paths).and_return(["Gemfile.zip", "files/images/6049019_460s.jpg", "files/ruby/feature.rb"]) + end + + it 'returns instance of Gitlab::Git::DiffCollection' do + expect(subject.raw_diffs).to be_a(Gitlab::Git::DiffCollection) + end + + it 'returns only diff for files changed in the context commits' do + expect(subject.raw_diffs.size).to be(3) + end + end + + describe '.diff_refs' do + it 'returns correct sha' do + expect(subject.diff_refs.head_sha).to eq(sha3) + expect(subject.diff_refs.base_sha).to eq("913c66a37b4a45b9769037c55c2d238bd0942d2e") + end + end +end diff --git a/spec/serializers/context_commits_diff_entity_spec.rb b/spec/serializers/context_commits_diff_entity_spec.rb new file mode 100644 index 00000000000..e8f38527f5b --- /dev/null +++ b/spec/serializers/context_commits_diff_entity_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ContextCommitsDiffEntity do + let_it_be(:merge_request) { create(:merge_request) } + let_it_be(:mrcc1) { create(:merge_request_context_commit, merge_request: merge_request, sha: "cfe32cf61b73a0d5e9f13e774abde7ff789b1660") } + let_it_be(:mrcc2) { create(:merge_request_context_commit, merge_request: merge_request, sha: "ae73cb07c9eeaf35924a10f713b364d32b2dd34f") } + + context 'as json' do + subject { ContextCommitsDiffEntity.represent(merge_request.context_commits_diff).as_json } + + it 'exposes commits_count' do + expect(subject[:commits_count]).to eq(2) + end + + it 'exposes showing_context_commits_diff' do + expect(subject).to have_key(:showing_context_commits_diff) + end + + it 'exposes diffs_path' do + expect(subject[:diffs_path]).to eq(Gitlab::Routing.url_helpers.diffs_project_merge_request_path(merge_request.project, merge_request, only_context_commits: true)) + end + end +end diff --git a/spec/serializers/diffs_metadata_entity_spec.rb b/spec/serializers/diffs_metadata_entity_spec.rb index f6993d4652e..b1cbe7e216e 100644 --- a/spec/serializers/diffs_metadata_entity_spec.rb +++ b/spec/serializers/diffs_metadata_entity_spec.rb @@ -28,7 +28,7 @@ RSpec.describe DiffsMetadataEntity do :start_version, :latest_diff, :latest_version_path, :added_lines, :removed_lines, :render_overflow_warning, :email_patch_path, :plain_diff_path, - :merge_request_diffs, :context_commits, + :merge_request_diffs, :context_commits, :context_commits_diff, :definition_path_prefix, :source_branch_exists, :can_merge, :conflict_resolution_path, :has_conflicts, :project_name, :project_path, :user_full_name, :username, diff --git a/spec/services/ci/pipeline_artifacts/destroy_all_expired_service_spec.rb b/spec/services/ci/pipeline_artifacts/destroy_all_expired_service_spec.rb index 3dc4f35df22..eb664043567 100644 --- a/spec/services/ci/pipeline_artifacts/destroy_all_expired_service_spec.rb +++ b/spec/services/ci/pipeline_artifacts/destroy_all_expired_service_spec.rb @@ -30,7 +30,7 @@ RSpec.describe Ci::PipelineArtifacts::DestroyAllExpiredService do stub_const('::Ci::PipelineArtifacts::DestroyAllExpiredService::LOOP_LIMIT', 1) stub_const('::Ci::PipelineArtifacts::DestroyAllExpiredService::BATCH_SIZE', 1) - create_list(:ci_pipeline_artifact, 2, expire_at: 1.week.ago) + create_list(:ci_pipeline_artifact, 2, :unlocked, expire_at: 1.week.ago) end it 'destroys one artifact' do @@ -46,7 +46,7 @@ RSpec.describe Ci::PipelineArtifacts::DestroyAllExpiredService do before do stub_const('Ci::PipelineArtifacts::DestroyAllExpiredService::BATCH_SIZE', 1) - create_list(:ci_pipeline_artifact, 2, expire_at: 1.week.ago) + create_list(:ci_pipeline_artifact, 2, :unlocked, expire_at: 1.week.ago) end it 'destroys all expired artifacts' do @@ -60,7 +60,21 @@ RSpec.describe Ci::PipelineArtifacts::DestroyAllExpiredService do context 'when artifacts are not expired' do before do - create(:ci_pipeline_artifact, expire_at: 2.days.from_now) + create(:ci_pipeline_artifact, :unlocked, expire_at: 2.days.from_now) + end + + it 'does not destroy pipeline artifacts' do + expect { subject }.not_to change { Ci::PipelineArtifact.count } + end + + it 'reports the number of destroyed artifacts' do + is_expected.to eq(0) + end + end + + context 'when pipeline is locked' do + before do + create(:ci_pipeline_artifact, expire_at: 2.weeks.ago) end it 'does not destroy pipeline artifacts' do diff --git a/spec/support/helpers/gitaly_setup.rb b/spec/support/helpers/gitaly_setup.rb index a93a28a20df..2ce4bcfa943 100644 --- a/spec/support/helpers/gitaly_setup.rb +++ b/spec/support/helpers/gitaly_setup.rb @@ -22,6 +22,10 @@ module GitalySetup File.expand_path('../../../tmp/tests/gitaly', __dir__) end + def tmp_tests_gitaly_bin_dir + File.join(tmp_tests_gitaly_dir, '_build', 'bin') + end + def tmp_tests_gitlab_shell_dir File.expand_path('../../../tmp/tests/gitlab-shell', __dir__) end @@ -110,7 +114,7 @@ module GitalySetup end def start(service) - args = ["#{tmp_tests_gitaly_dir}/#{service_binary(service)}"] + args = ["#{tmp_tests_gitaly_bin_dir}/#{service_binary(service)}"] args.push("-config") if service == :praefect args.push(config_path(service)) pid = spawn(env, *args, [:out, :err] => "log/#{service}-test.log") diff --git a/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb b/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb index 16362aed1cd..72b5b31bb7a 100644 --- a/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb +++ b/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb @@ -315,6 +315,36 @@ RSpec.describe 'layouts/nav/sidebar/_project' do end end + describe 'Security and Compliance' do + describe 'when user does not have permissions' do + before do + allow(view).to receive(:current_user).and_return(nil) + end + + it 'top level navigation link is not visible' do + render + + expect(rendered).not_to have_link('Security & Compliance') + end + end + + context 'when user has permissions' do + before do + allow(view).to receive(:current_user).and_return(user) + + render + end + + it 'top level navigation link is visible' do + expect(rendered).to have_link('Security & Compliance') + end + + it 'security configuration link is visible' do + expect(rendered).to have_link('Configuration', href: project_security_configuration_path(project)) + end + end + end + describe 'packages tab' do before do stub_container_registry_config(enabled: true) diff --git a/spec/views/layouts/nav/sidebar/_project_security_link.html.haml_spec.rb b/spec/views/layouts/nav/sidebar/_project_security_link.html.haml_spec.rb deleted file mode 100644 index d3fb35bff6d..00000000000 --- a/spec/views/layouts/nav/sidebar/_project_security_link.html.haml_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'layouts/nav/sidebar/_project_security_link' do - let_it_be_with_reload(:project) { create(:project) } - context 'on security configuration' do - before do - assign(:project, project) - allow(controller).to receive(:controller_name).and_return('configuration') - allow(controller).to receive(:controller_path).and_return('projects/security/configuration') - allow(controller).to receive(:action_name).and_return('show') - allow(view).to receive(:any_project_nav_tab?).and_return(true) - allow(view).to receive(:project_nav_tab?).and_return(true) - end - - it 'activates Security & Compliance tab' do - render - - expect(rendered).to have_css('li.active', text: 'Security & Compliance') - end - - it 'activates Configuration sub tab' do - render - - expect(rendered).to have_css('.sidebar-sub-level-items > li.active', text: 'Configuration') - end - end -end diff --git a/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb b/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb index ad9c08d02cb..274f848ad88 100644 --- a/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb +++ b/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Ci::PipelineArtifacts::ExpireArtifactsWorker do describe '#perform' do let_it_be(:pipeline_artifact) do - create(:ci_pipeline_artifact, :with_coverage_report, expire_at: 1.week.ago) + create(:ci_pipeline_artifact, :with_coverage_report, :unlocked, expire_at: 1.week.ago) end it 'executes a service' do |