Commit d79f6b5b authored by Michał Zając's avatar Michał Zając

Add SUPPORTED_VERSIONS and DEPRECATED_VERSIONS to SchemaValidator

This will allow us to specify which security report schemas are
supported and which ones are marked as deprecated

Changelog: changed
parent 76e27733
...@@ -6,6 +6,24 @@ module Gitlab ...@@ -6,6 +6,24 @@ module Gitlab
module Security module Security
module Validators module Validators
class SchemaValidator class SchemaValidator
SUPPORTED_VERSIONS = {
container_scanning: %w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0],
coverage_fuzzing: %w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0],
dast: %w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0],
dependency_scanning: %w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0],
sast: %w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0],
secret_detection: %w[14.0.0 14.0.1 14.0.2 14.0.3 14.0.4 14.0.5 14.0.6 14.1.0]
}.freeze
DEPRECATED_VERSIONS = {
container_scanning: %w[],
coverage_fuzzing: %w[],
dast: %w[],
dependency_scanning: %w[],
sast: %w[],
secret_detection: %w[]
}.freeze
class Schema class Schema
def root_path def root_path
File.join(__dir__, 'schemas') File.join(__dir__, 'schemas')
......
...@@ -3,6 +3,38 @@ ...@@ -3,6 +3,38 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
describe 'SUPPORTED_VERSIONS' do
let(:schema_path) { Rails.root.join("lib", "gitlab", "ci", "parsers", "security", "validators", "schemas") }
let(:file_paths) do
described_class::SUPPORTED_VERSIONS.flat_map do |report_type, supported_versions|
type_name = report_type.to_s.tr("_", "-")
file_name = "#{type_name}-report-format.json"
supported_versions.map { |version| schema_path.join(version, file_name) }
end
end
it 'has a corresponding schema on the disk' do
existing_files = file_paths.map { |file_path| File.file?(file_path) }
expect(existing_files).to all(be true)
end
end
describe 'DEPRECATED_VERSIONS' do
let(:schema_path) { Rails.root.join("lib", "gitlab", "ci", "parsers", "security", "validators", "schemas") }
let(:file_paths) do
described_class::DEPRECATED_VERSIONS.flat_map do |report_type, supported_versions|
type_name = report_type.to_s.tr("_", "-")
file_name = "#{type_name}-report-format.json"
supported_versions.map { |version| schema_path.join(version, file_name) }
end
end
it 'has a corresponding schema on the disk' do
existing_files = file_paths.map { |file_path| File.file?(file_path) }
expect(existing_files).to all(be true)
end
end
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:report_type, :expected_errors, :valid_data) do where(:report_type, :expected_errors, :valid_data) 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