Commit fd8678ff authored by Tetiana Chupryna's avatar Tetiana Chupryna Committed by Shinya Maeda

Add license_scanning factory

Add tests for license_scanning
parent bd3f5d88
......@@ -50,6 +50,13 @@ module EE
scope :metrics_reports, -> do
with_file_types(METRICS_REPORT_FILE_TYPES)
end
def self.associated_file_types_for(file_type)
return unless file_types.include?(file_type)
return LICENSE_SCANNING_REPORT_FILE_TYPES if LICENSE_SCANNING_REPORT_FILE_TYPES.include?(file_type)
[file_type]
end
end
def log_geo_deleted_event
......
......@@ -46,6 +46,7 @@ module EE
dast: %i[dast],
performance: %i[merge_request_performance_metrics],
license_management: %i[license_management],
license_scanning: %i[license_management],
metrics: %i[metrics_reports]
}.freeze
......@@ -107,21 +108,23 @@ module EE
def batch_lookup_report_artifact_for_file_type(file_type)
return unless available_licensed_report_type?(file_type)
latest_report_artifacts[file_type.to_s]&.last
latest_report_artifacts
.values_at(*::Ci::JobArtifact.associated_file_types_for(file_type.to_s))
.flatten
.compact
.last
end
def any_report_artifact_for_type(file_type)
report_artifact_for_file_type(file_type)
end
def report_artifact_for_file_type(file_type)
return unless available_licensed_report_type?(file_type)
job_artifacts.where(file_type: ::Ci::JobArtifact.file_types[file_type]).last
end
def expose_license_scanning_data?
any_report_artifact_for_type(:license_management)
return unless available_licensed_report_type?(:license_management)
batch_lookup_report_artifact_for_file_type(:license_scanning).present?
end
def security_reports
......
......@@ -185,7 +185,7 @@ module EE
container_scanning: report_type_enabled?(:container_scanning),
dast: report_type_enabled?(:dast),
dependency_scanning: report_type_enabled?(:dependency_scanning),
license_management: report_type_enabled?(:license_management)
license_management: report_type_enabled?(:license_scanning)
}
end
......
......@@ -6,7 +6,7 @@ FactoryBot.define do
failure_reason { Ci::Build.failure_reasons[:protected_environment_failure] }
end
%i[sast codequality dependency_scanning container_scanning dast performance license_management].each do |report_type|
%i[codequality container_scanning dast dependency_scanning license_management license_scanning performance sast].each do |report_type|
trait "legacy_#{report_type}".to_sym do
success
artifacts
......
......@@ -7,7 +7,7 @@ FactoryBot.define do
config_source { :webide_source }
end
%i[license_management dependency_list dependency_scanning sast dast container_scanning].each do |report_type|
%i[container_scanning dast dependency_list dependency_scanning license_management license_scanning sast].each do |report_type|
trait "with_#{report_type}_report".to_sym do
status { :success }
......
......@@ -85,6 +85,18 @@ FactoryBot.define do
end
end
trait :with_license_scanning_reports do
after(:build) do |merge_request|
merge_request.head_pipeline = build(
:ee_ci_pipeline,
:success,
:with_license_scanning_report,
project: merge_request.source_project,
ref: merge_request.source_branch,
sha: merge_request.diff_head_sha)
end
end
trait :with_container_scanning_reports do
after(:build) do |merge_request|
merge_request.head_pipeline = build(
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
describe Ci::Pipeline do
using RSpec::Parameterized::TableSyntax
let(:user) { create(:user) }
let_it_be(:project) { create(:project) }
......@@ -117,7 +119,60 @@ describe Ci::Pipeline do
end
end
describe '#report_artifact_for_file_type' do
describe '#batch_lookup_report_artifact_for_file_type' do
subject(:artifact) { pipeline.batch_lookup_report_artifact_for_file_type(file_type) }
let!(:build) { create(:ee_ci_build, artifact_type, :success, pipeline: pipeline) }
context 'with security report artifact' do
let!(:build) { create(:ee_ci_build, :dependency_scanning, :success, pipeline: pipeline) }
let(:file_type) { :dependency_scanning }
before do
stub_licensed_features(dependency_scanning: true)
end
it 'returns right kind of artifacts' do
expect(artifact.file_type).to eq file_type.to_s
end
context 'when looking for other type of artifact' do
let(:file_type) { :codequality }
it 'returns nothing' do
is_expected.to be_nil
end
end
end
context 'with license compliance artifact' do
before do
stub_licensed_features(license_management: true)
end
[:license_management, :license_scanning].each do |artifact_type|
let!(:build) { create(:ee_ci_build, artifact_type, :success, pipeline: pipeline) }
context 'when looking for license_scanning' do
let(:file_type) { :license_scanning }
it 'returns artifact' do
is_expected.to be_kind_of Ci::JobArtifact
end
end
context 'when looking for license_management' do
let(:file_type) { :license_management }
it 'returns artifact' do
is_expected.to be_kind_of Ci::JobArtifact
end
end
end
end
end
describe '#any_report_artifact_for_type' do
let!(:build) { create(:ci_build, pipeline: pipeline) }
let!(:artifact) do
......@@ -127,7 +182,7 @@ describe Ci::Pipeline do
file_format: ::Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS[file_type])
end
subject { pipeline.report_artifact_for_file_type(file_type) }
subject { pipeline.any_report_artifact_for_type(file_type) }
described_class::REPORT_LICENSED_FEATURES.each do |file_type, licensed_features|
context "for file_type: #{file_type}" do
......@@ -145,6 +200,20 @@ describe Ci::Pipeline do
end
end
describe '#expose_license_scanning_data?' do
subject { pipeline.expose_license_scanning_data? }
before do
stub_licensed_features(license_management: true)
end
[:license_scanning, :license_management].each do |artifact_type|
let!(:build) { create(:ee_ci_build, artifact_type, pipeline: pipeline) }
it { is_expected.to be_truthy }
end
end
describe '#security_reports' do
subject { pipeline.security_reports }
......
......@@ -34,4 +34,20 @@ describe EE::Ci::JobArtifact do
it { is_expected.to be_empty }
end
end
describe '.associated_file_types_for' do
using RSpec::Parameterized::TableSyntax
subject { Ci::JobArtifact.associated_file_types_for(file_type) }
where(:file_type, :result) do
'license_scanning' | %w(license_management license_scanning)
'codequality' | %w(codequality)
'quality' | nil
end
with_them do
it { is_expected.to eq result }
end
end
end
......@@ -121,19 +121,20 @@ describe MergeRequest do
describe '#enabled_reports' do
let(:project) { create(:project, :repository) }
where(:report_type, :with_reports) do
:sast | :with_sast_reports
:container_scanning | :with_container_scanning_reports
:dast | :with_dast_reports
:dependency_scanning | :with_dependency_scanning_reports
:license_management | :with_license_management_reports
where(:report_type, :with_reports, :feature) do
:sast | :with_sast_reports | :sast
:container_scanning | :with_container_scanning_reports | :container_scanning
:dast | :with_dast_reports | :dast
:dependency_scanning | :with_dependency_scanning_reports | :dependency_scanning
:license_management | :with_license_management_reports | :license_management
:license_management | :with_license_scanning_reports | :license_management
end
with_them do
subject { merge_request.enabled_reports[report_type] }
before do
stub_licensed_features({ report_type => true })
stub_licensed_features({ feature => true })
end
context "when head pipeline has reports" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment