Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cyclonedx_properties_spec.rb « sbom « parsers « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c99cfa94aa62f17ab6b25098c6240fa2234e1a62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Parsers::Sbom::CyclonedxProperties do
  subject(:parse_source) { described_class.parse_source(properties) }

  context 'when properties are nil' do
    let(:properties) { nil }

    it { is_expected.to be_nil }
  end

  context 'when report does not have gitlab properties' do
    let(:properties) { ['name' => 'foo', 'value' => 'bar'] }

    it { is_expected.to be_nil }
  end

  context 'when schema_version is missing' do
    let(:properties) do
      [
        { 'name' => 'gitlab:dependency_scanning:dependency_file', 'value' => 'package-lock.json' },
        { 'name' => 'gitlab:dependency_scanning:package_manager_name', 'value' => 'npm' },
        { 'name' => 'gitlab:dependency_scanning:language', 'value' => 'JavaScript' }
      ]
    end

    it { is_expected.to be_nil }
  end

  context 'when schema version is unsupported' do
    let(:properties) do
      [
        { 'name' => 'gitlab:meta:schema_version', 'value' => '2' },
        { 'name' => 'gitlab:dependency_scanning:dependency_file', 'value' => 'package-lock.json' },
        { 'name' => 'gitlab:dependency_scanning:package_manager_name', 'value' => 'npm' },
        { 'name' => 'gitlab:dependency_scanning:language', 'value' => 'JavaScript' }
      ]
    end

    it { is_expected.to be_nil }
  end

  context 'when no dependency_scanning properties are present' do
    let(:properties) do
      [
        { 'name' => 'gitlab:meta:schema_version', 'value' => '1' }
      ]
    end

    it 'does not call dependency_scanning parser' do
      expect(Gitlab::Ci::Parsers::Sbom::Source::DependencyScanning).not_to receive(:parse_source)

      parse_source
    end
  end

  context 'when dependency_scanning properties are present' do
    let(:properties) do
      [
        { 'name' => 'gitlab:meta:schema_version', 'value' => '1' },
        { 'name' => 'gitlab:dependency_scanning:category', 'value' => 'development' },
        { 'name' => 'gitlab:dependency_scanning:input_file:path', 'value' => 'package-lock.json' },
        { 'name' => 'gitlab:dependency_scanning:source_file:path', 'value' => 'package.json' },
        { 'name' => 'gitlab:dependency_scanning:package_manager:name', 'value' => 'npm' },
        { 'name' => 'gitlab:dependency_scanning:language:name', 'value' => 'JavaScript' },
        { 'name' => 'gitlab:dependency_scanning:unsupported_property', 'value' => 'Should be ignored' }
      ]
    end

    let(:expected_input) do
      {
        'category' => 'development',
        'input_file' => { 'path' => 'package-lock.json' },
        'source_file' => { 'path' => 'package.json' },
        'package_manager' => { 'name' => 'npm' },
        'language' => { 'name' => 'JavaScript' }
      }
    end

    it 'passes only supported properties to the dependency scanning parser' do
      expect(Gitlab::Ci::Parsers::Sbom::Source::DependencyScanning).to receive(:source).with(expected_input)

      parse_source
    end
  end
end