Commit 2e12eb00 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '5979_rename_sast_container_gitlab_features' into 'master'

Rename 'sast_container' to 'container_scanning' in GITLAB_FEATURES

See merge request gitlab-org/gitlab-ee!7981
parents bf68a072 e2c64602
......@@ -19,12 +19,12 @@ module EE
# This structure describes feature levels
# to access the file types for given reports
LEGACY_REPORT_LICENSED_FEATURES = {
REPORT_LICENSED_FEATURES = {
codequality: nil,
sast: :sast,
dependency_scanning: :dependency_scanning,
container_scanning: :sast_container,
dast: :dast
sast: %i[sast],
dependency_scanning: %i[dependency_scanning],
container_scanning: %i[container_scanning sast_container],
dast: %i[dast]
}.freeze
# Deprecated, to be removed in 12.0
......@@ -112,8 +112,8 @@ module EE
private
def available_licensed_report_type?(file_type)
feature_name = LEGACY_REPORT_LICENSED_FEATURES.fetch(file_type)
feature_name.nil? || project.feature_available?(feature_name)
feature_names = REPORT_LICENSED_FEATURES.fetch(file_type)
feature_names.nil? || feature_names.any? { |feature| project.feature_available?(feature) }
end
def artifacts_with_files
......
......@@ -78,6 +78,7 @@ class License < ActiveRecord::Base
license_management
sast
sast_container
container_scanning
cluster_health
dast
epics
......
......@@ -153,20 +153,92 @@ describe Ci::Pipeline do
end
end
shared_examples 'unlicensed report type' do
context 'when there is no licensed feature for artifact file type' do
it 'returns the artifact' do
expect(subject).to eq(expected)
end
end
end
shared_examples 'licensed report type' do |feature|
context 'when licensed features is NOT available' do
it 'returns nil' do
allow(pipeline.project).to receive(:feature_available?)
.with(feature).and_return(false)
expect(subject).to be_nil
end
end
context 'when licensed feature is available' do
it 'returns the artifact' do
allow(pipeline.project).to receive(:feature_available?)
.with(feature).and_return(true)
expect(subject).to eq(expected)
end
end
end
shared_examples 'multi-licensed report type' do |features|
context 'when NONE of the licensed features are available' do
it 'returns nil' do
features.each do |feature|
allow(pipeline.project).to receive(:feature_available?)
.with(feature).and_return(false)
end
expect(subject).to be_nil
end
end
context 'when at least one licensed feature is available' do
features.each do |feature|
it 'returns the artifact' do
allow(pipeline.project).to receive(:feature_available?)
.with(feature).and_return(true)
features.reject { |f| f == feature }.each do |disabled_feature|
allow(pipeline.project).to receive(:feature_available?)
.with(disabled_feature).and_return(true)
end
expect(subject).to eq(expected)
end
end
end
end
describe '#report_artifact_for_file_type' do
let(:file_type) { :codequality }
let!(:build) { create(:ci_build, pipeline: pipeline) }
let!(:artifact) { create(:ci_job_artifact, :codequality, job: build) }
let!(:artifact) do
create(:ci_job_artifact,
job: build,
file_type: file_type,
file_format: ::Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS[file_type])
end
subject { pipeline.report_artifact_for_file_type(file_type) }
it 'returns the artifact' do
expect(subject).to eq(artifact)
described_class::REPORT_LICENSED_FEATURES.each do |file_type, licensed_features|
context "for file_type: #{file_type}" do
let(:file_type) { file_type }
let(:expected) { artifact }
if licensed_features.nil?
it_behaves_like 'unlicensed report type'
elsif licensed_features.size == 1
it_behaves_like 'licensed report type', licensed_features.first
else
it_behaves_like 'multi-licensed report type', licensed_features
end
end
end
end
describe '#legacy_report_artifact_for_file_type' do
let(:file_type) { :codequality }
let(:build_name) { ::EE::Ci::Pipeline::LEGACY_REPORT_FORMATS[file_type][:names].first }
let(:artifact_path) { ::EE::Ci::Pipeline::LEGACY_REPORT_FORMATS[file_type][:files].first }
......@@ -185,10 +257,21 @@ describe Ci::Pipeline do
)
end
subject { pipeline.legacy_report_artifact_for_file_type(:codequality) }
subject { pipeline.legacy_report_artifact_for_file_type(file_type) }
it 'returns the artifact' do
expect(subject).to eq(OpenStruct.new(build: build, path: artifact_path))
described_class::REPORT_LICENSED_FEATURES.each do |file_type, licensed_features|
context "for file_type: #{file_type}" do
let(:file_type) { file_type }
let(:expected) { OpenStruct.new(build: build, path: artifact_path) }
if licensed_features.nil?
it_behaves_like 'unlicensed report type'
elsif licensed_features.size == 1
it_behaves_like 'licensed report type', licensed_features.first
else
it_behaves_like 'multi-licensed report type', licensed_features
end
end
end
end
......
......@@ -210,7 +210,7 @@ container_scanning:
refs:
- branches
variables:
- $GITLAB_FEATURES =~ /\bsast_container\b/
- $GITLAB_FEATURES =~ /\bcontainer_scanning\b/
except:
variables:
- $CONTAINER_SCANNING_DISABLED
......
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