-
-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathadvisory_example.rb
More file actions
269 lines (212 loc) · 6.59 KB
/
Copy pathadvisory_example.rb
File metadata and controls
269 lines (212 loc) · 6.59 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
require 'spec_helper'
require 'versions_example'
require 'yaml'
shared_examples_for 'Advisory' do |path|
advisory = YAML.safe_load_file(path, permitted_classes: [Date])
describe path do
let(:filename) { File.basename(path) }
let(:filename_cve) do
if filename.start_with?('CVE-')
filename.gsub('CVE-','')
end
end
let(:filename_osvdb) do
if filename.start_with?('OSVDB-')
filename.gsub('OSVDB-','')
end
end
let(:filename_ghsa) do
if filename.start_with?('GHSA-')
filename.gsub('GHSA-','')
end
end
it "should be correctly named CVE-XXX or OSVDB-XXX or GHSA-XXX" do
expect(filename).to match(
/\A
(?:
CVE-\d{4}-(?:0\d{3}|[1-9]\d{3,})|
OSVDB-\d+|
GHSA(-[a-z0-9]{4}){3}
)\.yml\z
/x
)
end
it "should have CVE or OSVDB or GHSA" do
expect(advisory['cve'] || advisory['osvdb'] || advisory['ghsa']).not_to be_nil
end
it "should CVE-XXX if cve field has a value" do
if advisory['cve']
expect(filename).to start_with('CVE-')
elsif advisory['ghsa']
expect(filename).to start_with('GHSA-')
end
end
describe "platform" do
subject { advisory['platform'] }
it "may be nil or a String" do
expect(subject).to be_kind_of(String).or(be_nil)
end
end
describe "cve" do
subject { advisory['cve'] }
it "may be nil or a String" do
expect(subject).to be_kind_of(String).or(be_nil)
end
it "should be id in filename if filename is CVE-XXX" do
if filename_cve
expect(subject).to eq(filename_cve.chomp('.yml'))
end
end
end
describe "osvdb" do
subject { advisory['osvdb'] }
it "may be nil or a Integer" do
expect(subject).to be_kind_of(Integer).or(be_nil)
end
it "should be id in filename if filename is OSVDB-XXX" do
if filename_osvdb
expect(subject).to eq(filename_osvdb.to_i)
end
end
end
describe "ghsa" do
subject { advisory['ghsa'] }
it "may be nil or a String" do
expect(subject).to be_kind_of(String).or(be_nil)
end
it "should be id in filename if filename is GHSA-XXX" do
if filename_ghsa
expect(subject).to eq(filename_ghsa.chomp('.yml'))
end
end
end
describe "url" do
subject { advisory['url'] }
it { expect(subject).to be_kind_of(String) }
it { expect(subject).to_not match(%r{\Ahttp(s)?://osvdb\.org}) }
it { expect(subject).not_to be_empty }
it "has a filename that matches the root of the url field" do
url = advisory["url"]
filename_root = File.basename(path, ".yml")
# 5/24/2026: May 9, 2026 is earliest start date with no failed checks.
start_date = Date.new(2026, 5, 9)
if advisory["date"] >= start_date and !filename_root.start_with?("OSVDB")
expect(url).to include(filename_root)
end
end
end
describe "title" do
subject { advisory['title'] }
it { expect(subject).to be_kind_of(String) }
it { expect(subject).not_to be_empty }
it "must be one line" do
expect(subject).to_not include("\n")
end
it "must not start with or end with additional whitespace" do
expect(subject).to_not match(/\A\s|\s\z/)
end
end
describe "date" do
subject { advisory['date'] }
it { expect(subject).to be_kind_of(Date) }
end
describe "description" do
subject { advisory['description'] }
it "must not be one line" do
expect(subject).to include("\n")
end
it "must not have double embbedded newlines" do
expect(subject).to_not include("\\n\\n")
end
it "must not have PoC sections" do
expect(subject).to_not match(/(#+) *(?:poc\b|proof of concept)/i)
end
it { expect(subject).to be_kind_of(String) }
it { expect(subject).not_to be_empty }
end
describe "cvss_v2" do
subject { advisory['cvss_v2'] }
it "may be nil or a Float" do
expect(subject).to be_kind_of(Float).or(be_nil)
end
case advisory['cvss_v2']
when Float
context "when a Float" do
it { expect(subject).to be_between(0.0, 10.0) }
end
end
end
describe "cvss_v3" do
subject { advisory['cvss_v3'] }
it "may be nil or a Float" do
expect(subject).to be_kind_of(Float).or(be_nil)
end
case advisory['cvss_v3']
when Float
context "when a Float" do
it { expect(subject).to be_between(0.0, 10.0) }
end
end
if advisory['cvss_v2']
it "should also provide a cvss_v2 score" do
expect(advisory['cvss_v2']).to_not be_nil
end
end
end
describe "cvss_v4" do
subject { advisory['cvss_v4'] }
it "may be nil or a Float" do
expect(subject).to be_kind_of(Float).or(be_nil)
end
case advisory['cvss_v4']
when Float
context "when a Float" do
it { expect(subject).to be_between(0.0, 10.0) }
end
end
end
describe "patched_versions" do
subject { advisory['patched_versions'] }
it "may be nil or an Array" do
expect(subject).to be_kind_of(Array).or(be_nil)
end
if advisory['patched_versions'].kind_of?(Array)
include_examples "Versions", advisory['patched_versions']
end
end
describe "unaffected_versions" do
subject { advisory['unaffected_versions'] }
it "may be nil or an Array" do
expect(subject).to be_kind_of(Array).or(be_nil)
end
if advisory['unaffected_versions'].kind_of?(Array)
include_examples "Versions", advisory['unaffected_versions']
end
end
describe "related" do
subject { advisory['related'] }
it "may be nil or a Hash" do
expect(subject).to be_kind_of(Hash).or(be_nil)
end
case advisory["related"]
when Hash
advisory["related"].each_pair do |name,values|
describe(name) do
it "should be either a cve, an osvdb, a ghsa, or a url" do
expect(["cve", "osvdb", "ghsa", "url"]).to include(name)
end
it "should always contain an array" do
expect(values).to be_kind_of(Array)
end
end
end
end
end
describe "notes" do
subject { advisory['notes'] }
it "may be nil or a String" do
expect(subject).to be_kind_of(String).or(be_nil)
end
end
end
end