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

source_spec.rb « sbom « reports « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 09a601833ad9163c4c3f298b608c249677750c50 (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
89
90
91
92
93
94
95
96
97
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::Ci::Reports::Sbom::Source, feature_category: :dependency_management do
  let(:attributes) do
    {
      type: type,
      data: { 'category' => 'development',
              'package_manager' => { 'name' => 'npm' },
              'language' => { 'name' => 'JavaScript' } }.merge(extra_attributes)
    }
  end

  subject(:source) { described_class.new(**attributes) }

  shared_examples_for 'it has correct common attributes' do
    it 'has correct type and data' do
      expect(subject).to have_attributes(
        source_type: type,
        data: attributes[:data]
      )
    end

    describe '#packager' do
      it 'returns the correct package manager name' do
        expect(subject.packager).to eq("npm")
      end
    end

    describe '#language' do
      it 'returns the correct language' do
        expect(subject.language).to eq("JavaScript")
      end
    end
  end

  context 'when dependency scanning' do
    let(:type) { :dependency_scanning }
    let(:extra_attributes) do
      {
        'input_file' => { 'path' => 'package-lock.json' },
        'source_file' => { 'path' => 'package.json' }
      }
    end

    it_behaves_like 'it has correct common attributes'

    describe '#source_file_path' do
      it 'returns the correct source_file_path' do
        expect(subject.source_file_path).to eq('package.json')
      end
    end

    describe '#input_file_path' do
      it 'returns the correct input_file_path' do
        expect(subject.input_file_path).to eq("package-lock.json")
      end
    end
  end

  context 'when container scanning' do
    let(:type) { :container_scanning }
    let(:extra_attributes) do
      {
        "image" => { "name" => "rhel", "tag" => "7.1" },
        "operating_system" => { "name" => "Red Hat Enterprise Linux", "version" => "7" }
      }
    end

    it_behaves_like 'it has correct common attributes'

    describe "#image_name" do
      subject { source.image_name }

      it { is_expected.to eq("rhel") }
    end

    describe "#image_tag" do
      subject { source.image_tag }

      it { is_expected.to eq("7.1") }
    end

    describe "#operating_system_name" do
      subject { source.operating_system_name }

      it { is_expected.to eq("Red Hat Enterprise Linux") }
    end

    describe "#operating_system_version" do
      subject { source.operating_system_version }

      it { is_expected.to eq("7") }
    end
  end
end