-
-
Notifications
You must be signed in to change notification settings - Fork 442
Expand file tree
/
Copy pathvalidate
More file actions
executable file
·147 lines (133 loc) · 4.96 KB
/
Copy pathvalidate
File metadata and controls
executable file
·147 lines (133 loc) · 4.96 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
#!/usr/bin/env node
var fs = require("fs");
var validateRepository = require("../node/lib/repo.js").validateRepository;
var evaluateLicense = require("../node/lib/license.js").evaluateLicense;
function exitWithError(...msg) {
console.warn(...msg);
process.exit(1);
}
console.log(
"Checking that jsrepository-master and jsonrepository are synced..."
);
const convert = require("./convertFormat.js").convertToOldFormat;
const data = require("./jsrepository-master.json");
const current = require("./jsrepository.json");
const converted = JSON.stringify(convert(data), null, 2);
const currentString = JSON.stringify(current, null, 2);
if (converted != currentString) {
exitWithError("jsrepository.json is has not been converted");
}
console.log(
"Checking that jsrepository-master and jsonrepository-v2 are synced..."
);
const currentV2 = require("./jsrepository-v2.json");
const convertedV2 = JSON.stringify(convert(data, { includeQueries: true }), null, 2);
const currentV2String = JSON.stringify(currentV2, null, 2);
if (convertedV2 != currentV2String) {
exitWithError("jsrepository-v2.json is has not been converted");
}
console.log(
"Checking that jsrepository-master and jsonrepository-v3 are synced..."
);
const currentV3 = require("./jsrepository-v3.json");
const convertedV3 = JSON.stringify(convert(data, { includeQueries: true, includeBackdoored: true, includeLicenses: true }), null, 2);
const currentV3String = JSON.stringify(currentV3, null, 2);
if (convertedV3 != currentV3String) {
exitWithError("jsrepository-v3.json is has not been converted");
}
console.log(
"Checking that jsrepository-master and jsonrepository-v4 are synced..."
);
const currentV4 = require("./jsrepository-v4.json");
const convertedV4 = JSON.stringify(convert(data, { includeQueries: true, includeLicenses: true }), null, 2);
const currentV4String = JSON.stringify(currentV4, null, 2);
if (convertedV4 != currentV4String) {
exitWithError("jsrepository-v4.json is has not been converted");
}
console.log(
"Checking that jsrepository-master and jsonrepository-v5 are synced..."
);
const currentV5 = require("./jsrepository-v5.json");
const convertedV5 = JSON.stringify(convert(data, { includeQueries: true, includeLicenses: true, includeExcludes: true }), null, 2);
const currentV5String = JSON.stringify(currentV5, null, 2);
if (convertedV5 != currentV5String) {
exitWithError("jsrepository-v5.json is has not been converted");
}
console.log(
"Checking that jsrepository-master and jsonrepository-v6 are synced..."
);
const currentV6 = require("./jsrepository-v6.json");
const convertedV6 = JSON.stringify(convert(data, { includeQueries: true, includeLicenses: true, includeExcludes: true, includeDetails: true }), null, 2);
const currentV6String = JSON.stringify(currentV6, null, 2);
if (convertedV6 != currentV6String) {
exitWithError("jsrepository-v6.json is has not been converted");
}
console.log("Done");
console.log("Validating repo format...");
const vStart = Date.now();
const validationResult = validateRepository(currentV4);
const vEnd = Date.now();
if (!validationResult.success) {
const errorMessage = JSON.stringify(
validationResult.error.format(),
(key, value) =>
Array.isArray(value) && value.length === 0 ? undefined : value,
2
);
exitWithError(errorMessage);
}
const jsRepo = validationResult.data;
console.log("Done: " + (vEnd - vStart) + "ms");
console.log("Checking for identifiers and verifying license strings...");
let maxRetId = "0";
let seenRetId = {};
const retIdMapping = new Map();
Object.entries(jsRepo).forEach(([k, val]) => {
if (val.licenses) {
try {
evaluateLicense(val.licenses, "1.0.0");
} catch (e) {
console.warn("WARN: Invalid license for " + k + ": " + e.message);
}
}
(val.vulnerabilities || [])
.filter((v) => {
let ids = v.identifiers;
if (!ids) return true;
if (ids.CVE && ids.CVE.length > 0) return false;
if (ids.bug) return false;
if (ids.blog) return false;
if (ids.gist) return false;
if (ids.issue) return false;
if (ids.PR) return false;
if (ids.tenable) return false;
if (ids.githubID) return false;
if (ids.osvdb && ids.osvdb.length > 0) return false;
if (ids.retid) {
if (
retIdMapping.has(ids.retid) &&
retIdMapping.get(ids.retid) != ids.githubID
) {
console.warn(
`retid ${ids.retid} is mapped to ${retIdMapping.get(
ids.retid
)} and ${ids.githubID}`
);
}
retIdMapping.set(ids.retid, ids.githubID);
if (seenRetId[ids.retid])
console.warn("Already seen retid: " + ids.retid);
seenRetId[ids.retid] = true;
if (parseInt(ids.retid) > parseInt(maxRetId)) maxRetId = ids.retid;
return false;
}
return true;
})
.forEach((v) => {
console.warn(
"WARN: " + k + " Missing identifiers for :" + JSON.stringify(v)
);
});
});
console.log("Max retId: " + maxRetId);
console.log("Success");