Skip to content

Commit 9280727

Browse files
committed
Pivot the validation error reporting by assigner.
1 parent 2aaaff5 commit 9280727

File tree

1 file changed

+49
-19
lines changed

1 file changed

+49
-19
lines changed

schema/v5.0/support/Node_Validator/reportValidation.js

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const docs= {
77
'/containers/cna/metrics/cvssV3_0:required': "CVSS objects are incomplete. Please provide a valid vectorString at the minimum in your CVE-JSON v4 submission."
88

99
}
10+
/*
1011
function cvePath(value) {
1112
var realId = value.match(/(CVE-(\d{4})-(\d{1,12})(\d{3}))/);
1213
if (realId) {
@@ -16,14 +17,16 @@ function cvePath(value) {
1617
return (year + '/' + bucket + 'xxx/' + id + '.json')
1718
}
1819
}
19-
20+
*/
2021
const validateCve = require('./dist/cve5validator.js')
2122
var errorStat = {};
23+
var warnStat = {};
2224
var errorCount = {};
2325
var yStat = {};
2426
var invalid = 0;
27+
var warns = 0;
2528
var total = 0;
26-
var ignore = { '': 1, '/cveMetadata/state': 1 }
29+
var ignore = { '': 1, '/cveMetadata/state': 1, '/containers/cna/references/url': 1}
2730
function validate(line) {
2831
if (line) {
2932
var parts = line.match(/(CVE-(\d+)-\d+)/);
@@ -37,7 +40,8 @@ function validate(line) {
3740
if (!fs.lstatSync(line).isDirectory()) {
3841
var cveFile = fs.readFileSync(line);
3942
var cve = JSON.parse(cveFile);
40-
delete cve.x_ValidationErrors;
43+
var warnings = cve.containers?.cna.x_ConverterErrors;
44+
//delete cve.x_ValidationErrors;
4145
var assigner = "default";
4246
try {
4347
assigner = cve.containers?.cna?.x_legacyV4Record?.CVE_data_meta?.ASSIGNER;
@@ -48,27 +52,52 @@ function validate(line) {
4852
console.error(e.message);
4953
}
5054
total++;
55+
56+
if(warnings) {
57+
warns++;
58+
errorCount[assigner]++;
59+
for (const key in warnings) {
60+
var w = 'Warning: ' + warnings[key].error;
61+
//console.log(key);
62+
if(!errorStat[assigner]) {
63+
errorStat[assigner] = {}
64+
errorCount[assigner] = 0
65+
}
66+
if(!errorStat[assigner][key]) {
67+
errorStat[assigner][key] = [];
68+
}
69+
if(!errorStat[assigner][key][w]) {
70+
errorStat[assigner][key][w] = [];
71+
}
72+
errorStat[assigner][key][w].push(id);
73+
}
74+
}
5175
var valid = validateCve(cve);
5276
if (!valid) {
53-
yStat[year] ? yStat[year]++ : (yStat[year] = 1);
54-
invalid++;
77+
var errseen = false;
5578
validateCve.errors.forEach(err => {
5679
var path = err.instancePath.replace(/\/\d+\/?/g, "/")
5780
if (!ignore[path]) {
58-
if (!errorStat[path]) {
59-
errorStat[path] = {}
60-
errorCount[path] = 0
81+
var e = 'Error: ' + err.keyword;
82+
if (!errorStat[assigner]) {
83+
errorStat[assigner] = {}
84+
errorCount[assigner] = 0
6185
}
62-
if (!errorStat[path][err.keyword]) {
63-
errorStat[path][err.keyword] = {}
86+
if (!errorStat[assigner][path]) {
87+
errorStat[assigner][path] = {}
6488
}
65-
if (!errorStat[path][err.keyword][assigner]) {
66-
errorStat[path][err.keyword][assigner] = []
89+
if (!errorStat[assigner][path][e]) {
90+
errorStat[assigner][path][e] = []
6791
}
68-
errorStat[path][err.keyword][assigner].push(id);
69-
errorCount[path]++;
92+
errorStat[assigner][path][e].push(id);
93+
errseen = true;
7094
}
7195
});
96+
if (errseen) {
97+
errorCount[assigner]++;
98+
invalid++;
99+
yStat[year] ? yStat[year]++ : (yStat[year] = 1);
100+
}
72101
}
73102
}
74103
} catch (e) {
@@ -107,24 +136,25 @@ function report() {
107136
}
108137
</style></head>
109138
<body><h2>
110-
Validation errors in ${invalid} out of ${total} upconverted CVEs.
139+
${warns} warnings and ${invalid} errors out of ${total} upconverted CVEs.
111140
</h2>
112141
`)
113142
for (const y in yStat) {
114143
console.log(`<li>year ${y} - ${yStat[y]}</li>`)
115144
}
145+
116146
Object.keys(errorStat).sort().forEach(x => {
117-
console.log(`<h3>${x} [${errorCount[x]}]</h3>`)
147+
console.log(`<h3 id=${x}>${x} <a href="#${x}">[link]</a></h3>`)
118148
for (const k in errorStat[x]) {
119149
var alist = errorStat[x][k];
120150
for (const a in alist) {
121-
console.log(`<details id="${x}-${k}-${a}"><summary>${k} error [${alist[a].length}] - ${a} <a href="#${x}-${k}-${a}">[link]</a>:</summary>`)
151+
var ids = [...new Set(alist[a])];
152+
console.log(`<details id="${x}-${k}-${a}"><summary>${a} ${k} [${ids.length}] <a href="#${x}-${k}-${a}">[link]</a>:</summary>`)
122153
if(docs[x + ':' + k]) {
123154
console.log(`<p>`+docs[x + ':' + k]+'</p>')
124155
}
125156
console.log('<blockquote class="grid">')
126-
for (const c of alist[a]) {
127-
var p = cvePath(c)
157+
for (const c of ids.sort()) {
128158
console.log(` <a href="https://vulnogram.github.io/seaview?${c}">${c}</a>`)
129159
}
130160
console.log('</blockquote></details>')

0 commit comments

Comments
 (0)