-
-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathconfiguration_spec.rb
More file actions
142 lines (109 loc) · 4.89 KB
/
Copy pathconfiguration_spec.rb
File metadata and controls
142 lines (109 loc) · 4.89 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
require 'spec_helper'
require 'bundler/audit/configuration'
describe Bundler::Audit::Configuration do
describe "when building from a yaml file" do
let(:fixtures_dir) { File.expand_path('../fixtures/config',__FILE__) }
subject { described_class.load(path) }
context "when the file does not exist" do
let(:path) { File.join(fixtures_dir,'bad','does_not_exist.yml') }
it 'raises an error' do
expect { subject }.to raise_error(described_class::FileNotFound, /Configuration file '.*' does not exist/)
end
end
context "when the file does exist" do
let(:path) { File.join(fixtures_dir,'valid.yml') }
it { should be_a(described_class) }
end
context "validations" do
context "when the file is empty" do
let(:path) { File.join(fixtures_dir,'bad','empty.yml') }
it 'raises a validation error' do
expect { subject }.to raise_error(described_class::InvalidConfigurationError)
end
end
context "when ignore is not an array" do
let(:path) { File.join(fixtures_dir,'bad','ignore_is_not_an_array.yml') }
it 'raises a validation error' do
expect { subject }.to raise_error(described_class::InvalidConfigurationError)
end
end
context 'when ignore is an array' do
context 'when ignore only contains strings' do
let(:path) { File.join(fixtures_dir,'valid.yml') }
it { should be_a(described_class) }
end
describe "when ignore contains non-strings" do
let(:path) { File.join(fixtures_dir,'bad','ignore_contains_a_non_string.yml') }
it "raises a validation error" do
expect { subject }.to raise_error(described_class::InvalidConfigurationError)
end
end
end
context "when inherit_from is not an Array" do
let(:path) { File.join(fixtures_dir,'bad','inherit_from_is_not_an_array.yml') }
it "raises a validation error" do
expect { subject }.to raise_error(described_class::InvalidConfigurationError,
/'inherit_from' key found in config file, but is not an Array/)
end
end
context "when inherit_from array contains a non-String" do
let(:path) { File.join(fixtures_dir,'bad','inherit_from_contains_a_non_string.yml') }
it "raises a validation error" do
expect { subject }.to raise_error(described_class::InvalidConfigurationError,
/'inherit_from' array in config file contains a non-String/)
end
end
context "when an inherited file does not exist" do
let(:path) { File.join(fixtures_dir,'bad','inherit_from_missing_target.yml') }
it "raises a FileNotFound error" do
expect { subject }.to raise_error(described_class::FileNotFound,
/Configuration file '.*does_not_exist\.yml' does not exist/)
end
end
context "when the inherit_from chain forms a cycle" do
let(:path) { File.join(fixtures_dir,'bad','inherit_from_cycle_a.yml') }
it "raises a validation error identifying the cycle" do
expect { subject }.to raise_error(described_class::InvalidConfigurationError,
/Cycle detected in 'inherit_from'/)
end
end
end
context "when a file inherits another" do
let(:path) { File.join(fixtures_dir,'inherit_from','child.yml') }
it { should be_a(described_class) }
it "must merge the parent's ignore list with the child's" do
expect(subject.ignore).to eq(Set.new(%w[CVE-BASE-1 CVE-BASE-2 CVE-CHILD-1]))
end
end
context "when the inherit_from chain is 3 deep" do
let(:path) { File.join(fixtures_dir,'inherit_from','grandchild.yml') }
it "must transitively merge the ignore lists" do
expect(subject.ignore).to eq(Set.new(%w[CVE-BASE-1 CVE-BASE-2 CVE-MIDDLE-1 CVE-GRANDCHILD-1]))
end
end
context "when the inherit_from path is relative" do
let(:path) { File.join(fixtures_dir,'inherit_from','child.yml') }
it "must resolve inherited paths relative to the including file" do
Dir.chdir('/tmp') do
expect(subject.ignore).to eq(Set.new(%w[CVE-BASE-1 CVE-BASE-2 CVE-CHILD-1]))
end
end
end
end
describe "#initialize" do
context "when given no arguments" do
it "must set @ignore to an empty Set" do
expect(subject.ignore).to be_kind_of(Set)
expect(subject.ignore).to be_empty
end
end
context "when given :ignore" do
let(:advisory_ids) { %w[CVE-123 CVE-456] }
subject { described_class.new(ignore: advisory_ids) }
it "must initialize @ignore to contain :ignore" do
expect(subject.ignore).to be_kind_of(Set)
expect(subject.ignore).to be == Set.new(advisory_ids)
end
end
end
end