summaryrefslogtreecommitdiff
path: root/spec/integration/rust/cargo_spec.rb
blob: 77ad447118673266def4ff4a000aa8faf0f42d1c (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
require 'spec_helper'

RSpec.describe "cargo" do
  subject { runner.scan(env: env) }

  let(:env) { {} }

  context "when scanning a cargo project" do
    before do
      runner.mount(dir: fixture_file('rust/cargo/hello_world'))
    end

    specify { expect(subject).to match_schema }

    specify do
      expect(subject.dependency_names).to match_array(%w[libc time])
    end

    specify { expect(subject.licenses_for('libc')).to match_array(['mit or apache-2.0']) }
    specify { expect(subject.licenses_for('time')).to match_array(['Apache-2.0', 'MIT']) }
  end

  context "when fetching dependencies from a custom registry" do
    before do
      add_host('cargo.test', '127.0.0.1')
      start_proxy_server
      runner.mount(dir: fixture_file('rust/cargo/custom-tls'))
    end

    context "when the CA certificate is provided" do
      let(:env) { { 'ADDITIONAL_CA_CERT_BUNDLE' => x509_certificate('wildcard.test').read } }

      specify do
        expect(subject).to match_schema
        expect(subject.dependency_names).to match_array(['libc'])
        expect(subject.licenses_for('libc')).to match_array(['mit or apache-2.0'])
      end
    end

    context "when the CA certificate is NOT provided" do
      let(:env) { {} }

      specify { expect(subject).to match_schema }
    end
  end

  context "when scanning a project with dev dependencies" do
    before do
      runner.mount(dir: fixture_file('rust/cargo/dev-dependencies'))
    end

    it 'excludes them from the report' do
      expect(subject).to match_schema
      expect(subject.dependency_names).to include('diesel')
      expect(subject.dependency_names).not_to include('pretty_assertions')
    end
  end
end