Commit 27691c6c authored by Michał Zając's avatar Michał Zając

Simplify specs and constants

parent bc090b98
...@@ -28,15 +28,17 @@ module Gitlab ...@@ -28,15 +28,17 @@ module Gitlab
# These come from https://app.periscopedata.com/app/gitlab/895813/Secure-Scan-metrics?widget=12248944&udv=1385516 # These come from https://app.periscopedata.com/app/gitlab/895813/Secure-Scan-metrics?widget=12248944&udv=1385516
KNOWN_VERSIONS_TO_DEPRECATE = %w[0.1 1.0 1.0.0 1.2 1.3 10.0.0 12.1.0 13.1.0 2.0 2.1 2.1.0 2.3 2.3.0 2.4 3.0 3.0.0 3.0.6 3.13.2 V2.7.0].freeze KNOWN_VERSIONS_TO_DEPRECATE = %w[0.1 1.0 1.0.0 1.2 1.3 10.0.0 12.1.0 13.1.0 2.0 2.1 2.1.0 2.3 2.3.0 2.4 3.0 3.0.0 3.0.6 3.13.2 V2.7.0].freeze
VERSIONS_TO_DEPRECATE_IN_15_0 = (PREVIOUS_RELEASES + KNOWN_VERSIONS_TO_DEPRECATE).freeze
DEPRECATED_VERSIONS = { DEPRECATED_VERSIONS = {
cluster_image_scanning: PREVIOUS_RELEASES + KNOWN_VERSIONS_TO_DEPRECATE + %w[], cluster_image_scanning: VERSIONS_TO_DEPRECATE_IN_15_0,
container_scanning: PREVIOUS_RELEASES + KNOWN_VERSIONS_TO_DEPRECATE + %w[], container_scanning: VERSIONS_TO_DEPRECATE_IN_15_0,
coverage_fuzzing: PREVIOUS_RELEASES + KNOWN_VERSIONS_TO_DEPRECATE + %w[], coverage_fuzzing: VERSIONS_TO_DEPRECATE_IN_15_0,
dast: PREVIOUS_RELEASES + KNOWN_VERSIONS_TO_DEPRECATE + %w[], dast: VERSIONS_TO_DEPRECATE_IN_15_0,
api_fuzzing: PREVIOUS_RELEASES + KNOWN_VERSIONS_TO_DEPRECATE + %w[], api_fuzzing: VERSIONS_TO_DEPRECATE_IN_15_0,
dependency_scanning: PREVIOUS_RELEASES + KNOWN_VERSIONS_TO_DEPRECATE + %w[], dependency_scanning: VERSIONS_TO_DEPRECATE_IN_15_0,
sast: PREVIOUS_RELEASES + KNOWN_VERSIONS_TO_DEPRECATE + %w[], sast: VERSIONS_TO_DEPRECATE_IN_15_0,
secret_detection: PREVIOUS_RELEASES + KNOWN_VERSIONS_TO_DEPRECATE + %w[] secret_detection: VERSIONS_TO_DEPRECATE_IN_15_0
}.freeze }.freeze
class Schema class Schema
......
...@@ -4,24 +4,21 @@ require 'spec_helper' ...@@ -4,24 +4,21 @@ 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 describe 'SUPPORTED_VERSIONS' do
# This is not a stub, let is not accessible within context blocks schema_path = Rails.root.join("lib", "gitlab", "ci", "parsers", "security", "validators", "schemas")
# rubocop:disable RSpec/LeakyConstantDeclaration
SCHEMA_PATH = Rails.root.join("lib", "gitlab", "ci", "parsers", "security", "validators", "schemas")
# rubocop:enable RSpec/LeakyConstantDeclaration
it 'matches DEPRECATED_VERSIONS keys' do it 'matches DEPRECATED_VERSIONS keys' do
expect(described_class::SUPPORTED_VERSIONS.keys).to eq(described_class::DEPRECATED_VERSIONS.keys) expect(described_class::SUPPORTED_VERSIONS.keys).to eq(described_class::DEPRECATED_VERSIONS.keys)
end end
context 'files under SCHEMA_PATH are explicitly listed' do context 'files under schema path are explicitly listed' do
# We only care about the part that comes before report-format.json # We only care about the part that comes before report-format.json
# https://rubular.com/r/N8Juz7r8hYDYgD # https://rubular.com/r/N8Juz7r8hYDYgD
filename_regex = /(?<report_type>[-\w]*)\-report-format.json/ filename_regex = /(?<report_type>[-\w]*)\-report-format.json/
versions = Dir.glob(File.join(SCHEMA_PATH, "*", File::SEPARATOR)).map { |path| path.split("/").last } versions = Dir.glob(File.join(schema_path, "*", File::SEPARATOR)).map { |path| path.split("/").last }
versions.each do |version| versions.each do |version|
files = Dir[SCHEMA_PATH.join(version, "*.json")] files = Dir[schema_path.join(version, "*.json")]
files.each do |file| files.each do |file|
matches = filename_regex.match(file) matches = filename_regex.match(file)
...@@ -42,7 +39,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do ...@@ -42,7 +39,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
described_class::SUPPORTED_VERSIONS[report_type].each do |version| described_class::SUPPORTED_VERSIONS[report_type].each do |version|
it "#{report_type} #{version} schema file is present" do it "#{report_type} #{version} schema file is present" do
filename = "#{report_type.to_s.tr("_", "-")}-report-format.json" filename = "#{report_type.to_s.tr("_", "-")}-report-format.json"
full_path = SCHEMA_PATH.join(version, filename) full_path = schema_path.join(version, filename)
expect(File.file?(full_path)).to be true expect(File.file?(full_path)).to be true
end end
end end
...@@ -50,12 +47,6 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do ...@@ -50,12 +47,6 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do
end end
end end
describe 'DEPRECATED_VERSIONS' do
it 'matches SUPPORTED_VERSIONS keys' do
expect(described_class::DEPRECATED_VERSIONS.keys).to eq(described_class::SUPPORTED_VERSIONS.keys)
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