diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-24 21:06:18 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-24 21:06:18 +0000 |
commit | 150effab274651b3a8d2041e64ced734d1f3a349 (patch) | |
tree | 7f887964a56bd15a87d58cd367ccc1fa45f98554 /spec | |
parent | 2ed368929ab5094fec5da8038f723463596a80cf (diff) | |
download | gitlab-ce-150effab274651b3a8d2041e64ced734d1f3a349.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
8 files changed, 213 insertions, 38 deletions
diff --git a/spec/frontend/helpers/test_constants.js b/spec/frontend/helpers/test_constants.js index 8dc4aef87e1..c97d47a6406 100644 --- a/spec/frontend/helpers/test_constants.js +++ b/spec/frontend/helpers/test_constants.js @@ -1,2 +1,7 @@ -// eslint-disable-next-line import/prefer-default-export +export const FIXTURES_PATH = `/fixtures`; export const TEST_HOST = 'http://test.host'; + +export const DUMMY_IMAGE_URL = `${FIXTURES_PATH}/static/images/one_white_pixel.png`; + +export const GREEN_BOX_IMAGE_URL = `${FIXTURES_PATH}/static/images/green_box.png`; +export const RED_BOX_IMAGE_URL = `${FIXTURES_PATH}/static/images/red_box.png`; diff --git a/spec/frontend/lib/utils/suppress_ajax_errors_during_navigation_spec.js b/spec/frontend/lib/utils/suppress_ajax_errors_during_navigation_spec.js new file mode 100644 index 00000000000..89e8459d594 --- /dev/null +++ b/spec/frontend/lib/utils/suppress_ajax_errors_during_navigation_spec.js @@ -0,0 +1,37 @@ +import suppressAjaxErrorsDuringNavigation from '~/lib/utils/suppress_ajax_errors_during_navigation'; +import waitForPromises from 'helpers/wait_for_promises'; + +describe('suppressAjaxErrorsDuringNavigation', () => { + const OTHER_ERR_CODE = 'foo'; + const NAV_ERR_CODE = 'ECONNABORTED'; + + it.each` + isFeatureFlagEnabled | isUserNavigating | code + ${false} | ${false} | ${OTHER_ERR_CODE} + ${false} | ${false} | ${NAV_ERR_CODE} + ${false} | ${true} | ${OTHER_ERR_CODE} + ${false} | ${true} | ${NAV_ERR_CODE} + ${true} | ${false} | ${OTHER_ERR_CODE} + ${true} | ${false} | ${NAV_ERR_CODE} + ${true} | ${true} | ${OTHER_ERR_CODE} + `('should return a rejected Promise', ({ isFeatureFlagEnabled, isUserNavigating, code }) => { + const err = { code }; + const actual = suppressAjaxErrorsDuringNavigation(err, isUserNavigating, isFeatureFlagEnabled); + + return expect(actual).rejects.toBe(err); + }); + + it('should return a Promise that never resolves', () => { + const err = { code: NAV_ERR_CODE }; + const actual = suppressAjaxErrorsDuringNavigation(err, true, true); + + const thenCallback = jest.fn(); + const catchCallback = jest.fn(); + actual.then(thenCallback).catch(catchCallback); + + return waitForPromises().then(() => { + expect(thenCallback).not.toHaveBeenCalled(); + expect(catchCallback).not.toHaveBeenCalled(); + }); + }); +}); diff --git a/spec/javascripts/frequent_items/components/app_spec.js b/spec/javascripts/frequent_items/components/app_spec.js index 6814f656f5d..36dd8604d08 100644 --- a/spec/javascripts/frequent_items/components/app_spec.js +++ b/spec/javascripts/frequent_items/components/app_spec.js @@ -236,8 +236,15 @@ describe('Frequent Items App Component', () => { .then(() => { expect(vm.$el.querySelector('.loading-animation')).toBeDefined(); }) + + // This test waits for multiple ticks in order to allow the responses to + // propagate through each interceptor installed on the Axios instance. + // This shouldn't be necessary; this test should be refactored to avoid this. + // https://gitlab.com/gitlab-org/gitlab/issues/32479 + .then(vm.$nextTick) .then(vm.$nextTick) .then(vm.$nextTick) + .then(() => { expect(vm.$el.querySelectorAll('.frequent-items-list-container li').length).toBe( mockSearchedProjects.length, diff --git a/spec/javascripts/test_constants.js b/spec/javascripts/test_constants.js index c97d47a6406..51c0716b99d 100644 --- a/spec/javascripts/test_constants.js +++ b/spec/javascripts/test_constants.js @@ -1,7 +1 @@ -export const FIXTURES_PATH = `/fixtures`; -export const TEST_HOST = 'http://test.host'; - -export const DUMMY_IMAGE_URL = `${FIXTURES_PATH}/static/images/one_white_pixel.png`; - -export const GREEN_BOX_IMAGE_URL = `${FIXTURES_PATH}/static/images/green_box.png`; -export const RED_BOX_IMAGE_URL = `${FIXTURES_PATH}/static/images/red_box.png`; +export * from '../frontend/helpers/test_constants'; diff --git a/spec/lib/gitlab/background_migration/update_vulnerability_confidence_spec.rb b/spec/lib/gitlab/background_migration/update_vulnerability_confidence_spec.rb new file mode 100644 index 00000000000..1217edfecc3 --- /dev/null +++ b/spec/lib/gitlab/background_migration/update_vulnerability_confidence_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::BackgroundMigration::UpdateVulnerabilityConfidence, :migration, schema: 20190909141517 do + let(:vulnerabilities) { table(:vulnerability_occurrences) } + let(:identifiers) { table(:vulnerability_identifiers) } + let(:scanners) { table(:vulnerability_scanners) } + let(:projects) { table(:projects) } + let(:vul1) { attributes_for(:vulnerabilities_occurrence) } + let(:vul2) { attributes_for(:vulnerabilities_occurrence) } + let(:vul3) { attributes_for(:vulnerabilities_occurrence) } + + it 'updates confidence level for container scanning reports' do + projects.create!(id: 123, namespace_id: 12, name: 'gitlab', path: 'gitlab') + + (1..3).to_a.each do |identifier_id| + identifiers.create!(id: identifier_id, + project_id: 123, + fingerprint: 'd432c2ad2953e8bd587a3a43b3ce309b5b0154c' + identifier_id.to_s, + external_type: 'SECURITY_ID', + external_id: 'SECURITY_0', + name: 'SECURITY_IDENTIFIER 0') + end + + scanners.create!(id: 6, project_id: 123, external_id: 'clair', name: 'Security Scanner') + + vulnerabilities.create!(container_scanning_vuln_params(vul1, 1)) + vulnerabilities.create!(container_scanning_vuln_params(vul2, 2)) + vulnerabilities.create!(container_scanning_vuln_params(vul3, 3).merge(report_type: 1)) + + expect(vulnerabilities.where(report_type: 2, confidence: 2).count). to eq(0) + expect(vulnerabilities.exists?(report_type: 2, confidence: 5)).to be_truthy + + described_class.new.perform(1, 3) + + expect(vulnerabilities.exists?(report_type: 2, confidence: 5)).to be_falsy + expect(vulnerabilities.where(report_type: 2, confidence: 2).count). to eq(2) + end + + def container_scanning_vuln_params(vul, primary_identifier_id) + { + id: vul[:id], + severity: 2, + confidence: 5, + report_type: 2, + project_id: 123, + scanner_id: 6, + primary_identifier_id: primary_identifier_id, + project_fingerprint: vul[:project_fingerprint], + location_fingerprint: vul[:location_fingerprint], + uuid: vul[:uuid], + name: vul[:name], + metadata_version: '1.3', + raw_metadata: vul3[:raw_metadata] + } + end +end diff --git a/spec/lib/gitlab/gl_repository/repo_type_spec.rb b/spec/lib/gitlab/gl_repository/repo_type_spec.rb index f06a2448ff7..9e09e1411ab 100644 --- a/spec/lib/gitlab/gl_repository/repo_type_spec.rb +++ b/spec/lib/gitlab/gl_repository/repo_type_spec.rb @@ -4,36 +4,6 @@ require 'spec_helper' describe Gitlab::GlRepository::RepoType do set(:project) { create(:project) } - shared_examples 'a repo type' do - describe "#identifier_for_subject" do - subject { described_class.identifier_for_subject(project) } - - it { is_expected.to eq(expected_identifier) } - end - - describe "#fetch_id" do - it "finds an id match in the identifier" do - expect(described_class.fetch_id(expected_identifier)).to eq(expected_id) - end - - it 'does not break on other identifiers' do - expect(described_class.fetch_id("wiki-noid")).to eq(nil) - end - end - - describe "#path_suffix" do - subject { described_class.path_suffix } - - it { is_expected.to eq(expected_suffix) } - end - - describe "#repository_for" do - it "finds the repository for the repo type" do - expect(described_class.repository_for(project)).to eq(expected_repository) - end - end - end - describe Gitlab::GlRepository::PROJECT do it_behaves_like 'a repo type' do let(:expected_identifier) { "project-#{project.id}" } diff --git a/spec/migrations/update_cs_vulnerability_confidence_column_spec.rb b/spec/migrations/update_cs_vulnerability_confidence_column_spec.rb new file mode 100644 index 00000000000..b8575dd9467 --- /dev/null +++ b/spec/migrations/update_cs_vulnerability_confidence_column_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20190909141517_update_cs_vulnerability_confidence_column.rb') + +describe UpdateCsVulnerabilityConfidenceColumn, :migration, :sidekiq do + let(:vulnerabilities) { table(:vulnerability_occurrences) } + let(:identifiers) { table(:vulnerability_identifiers) } + let(:scanners) { table(:vulnerability_scanners) } + let(:projects) { table(:projects) } + let(:vul1) { attributes_for(:vulnerabilities_occurrence, id: 1, report_type: 2, confidence: 5) } + let(:vul2) { attributes_for(:vulnerabilities_occurrence, id: 2, report_type: 2, confidence: 5) } + + before do + stub_const("#{described_class}::BATCH_SIZE", 2) + end + + it 'updates confidence levels for container scanning reports' do + projects.create!(id: 123, namespace_id: 12, name: 'gitlab', path: 'gitlab') + + identifiers.create!(id: 1, + project_id: 123, + fingerprint: 'd432c2ad2953e8bd587a3a43b3ce309b5b0154c2', + external_type: 'SECURITY_ID', + external_id: 'SECURITY_0', + name: 'SECURITY_IDENTIFIER 0') + + identifiers.create!(id: 2, + project_id: 123, + fingerprint: 'd432c2ad2953e8bd587a3a43b3ce309b5b0154c3', + external_type: 'SECURITY_ID', + external_id: 'SECURITY_0', + name: 'SECURITY_IDENTIFIER 0') + + scanners.create!(id: 6, project_id: 123, external_id: 'clair', name: 'Security Scanner') + + vulnerabilities.create!(id: vul1[:id], + severity: 2, + confidence: 5, + report_type: 2, + project_id: 123, + scanner_id: 6, + primary_identifier_id: 1, + project_fingerprint: vul1[:project_fingerprint], + location_fingerprint: vul1[:location_fingerprint], + uuid: vul1[:uuid], + name: vul1[:name], + metadata_version: '1.3', + raw_metadata: vul1[:raw_metadata]) + + vulnerabilities.create!(id: vul2[:id], + severity: 2, + confidence: 5, + report_type: 2, + project_id: 123, + scanner_id: 6, + primary_identifier_id: 2, + project_fingerprint: vul2[:project_fingerprint], + location_fingerprint: vul2[:location_fingerprint], + uuid: vul2[:uuid], + name: vul2[:name], + metadata_version: '1.3', + raw_metadata: vul2[:raw_metadata]) + + expect(vulnerabilities.where(report_type: 2, confidence: 2).count). to eq(0) + expect(vulnerabilities.exists?(report_type: 2, confidence: 5)).to be_truthy + + migrate! + + expect(vulnerabilities.exists?(report_type: 2, confidence: 5)).to be_falsy + expect(vulnerabilities.where(report_type: 2, confidence: 2).count). to eq(2) + end +end diff --git a/spec/support/shared_examples/repo_type_shared_examples.rb b/spec/support/shared_examples/repo_type_shared_examples.rb new file mode 100644 index 00000000000..dc9e3a73346 --- /dev/null +++ b/spec/support/shared_examples/repo_type_shared_examples.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +shared_examples 'a repo type' do + describe "#identifier_for_subject" do + subject { described_class.identifier_for_subject(project) } + + it { is_expected.to eq(expected_identifier) } + end + + describe "#fetch_id" do + it "finds an id match in the identifier" do + expect(described_class.fetch_id(expected_identifier)).to eq(expected_id) + end + + it 'does not break on other identifiers' do + expect(described_class.fetch_id("wiki-noid")).to eq(nil) + end + end + + describe "#path_suffix" do + subject { described_class.path_suffix } + + it { is_expected.to eq(expected_suffix) } + end + + describe "#repository_for" do + it "finds the repository for the repo type" do + expect(described_class.repository_for(project)).to eq(expected_repository) + end + end +end |