Skip to content

Commit e36ab37

Browse files
authored
fix: sort all outputs for cleanliness and consistency (#314)
1 parent c6f6e51 commit e36ab37

File tree

7 files changed

+113
-110
lines changed

7 files changed

+113
-110
lines changed

lib/model.ts

+24-20
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ class Model {
151151
| PartialPNPMAuditReportAudit
152152
) {
153153
/** NPM 6 & PNPM */
154-
155154
if ("advisories" in parsedOutput && parsedOutput.advisories) {
156155
for (const advisory of Object.values<
157156
DeepWriteable<
@@ -293,41 +292,46 @@ class Model {
293292
this.process(advisory);
294293
}
295294
}
296-
297295
return this.getSummary();
298296
}
299297

300298
getSummary(
301299
advisoryMapper: (advisory: any) => GitHubAdvisoryId = (a) =>
302300
a.github_advisory_id
303301
) {
302+
// Clean up the data structures for more consistent output.
303+
this.advisoriesFound.sort();
304+
this.advisoryPathsFound = [...new Set(this.advisoryPathsFound)].sort();
305+
this.allowlistedAdvisoriesFound.sort();
306+
this.allowlistedModulesFound.sort();
307+
this.allowlistedPathsFound.sort();
308+
304309
const foundSeverities = new Set<"low" | "moderate" | "high" | "critical">();
305310
for (const { severity } of this.advisoriesFound) {
306311
if (severity !== "info") {
307312
foundSeverities.add(severity);
308313
}
309314
}
310-
const failedLevelsFound = [...foundSeverities];
311-
failedLevelsFound.sort();
315+
const failedLevelsFound = [...foundSeverities].sort();
312316

313317
const advisoriesFound = [
314318
...new Set(this.advisoriesFound.map((a) => advisoryMapper(a))),
315-
];
316-
317-
const allowlistedAdvisoriesNotFound = this.allowlist.advisories.filter(
318-
(id) => !this.allowlistedAdvisoriesFound.includes(id)
319-
);
320-
const allowlistedModulesNotFound = this.allowlist.modules.filter(
321-
(id) => !this.allowlistedModulesFound.includes(id)
322-
);
323-
const allowlistedPathsNotFound = this.allowlist.paths.filter(
324-
(id) =>
325-
!this.allowlistedPathsFound.some((foundPath) =>
326-
matchString(id, foundPath)
327-
)
328-
);
329-
330-
this.advisoryPathsFound = [...new Set(this.advisoryPathsFound)];
319+
].sort();
320+
321+
const allowlistedAdvisoriesNotFound = this.allowlist.advisories
322+
.filter((id) => !this.allowlistedAdvisoriesFound.includes(id))
323+
.sort();
324+
const allowlistedModulesNotFound = this.allowlist.modules
325+
.filter((id) => !this.allowlistedModulesFound.includes(id))
326+
.sort();
327+
const allowlistedPathsNotFound = this.allowlist.paths
328+
.filter(
329+
(id) =>
330+
!this.allowlistedPathsFound.some((foundPath) =>
331+
matchString(id, foundPath)
332+
)
333+
)
334+
.sort();
331335

332336
const summary: Summary = {
333337
advisoriesFound,

test/allowlist.spec.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ describe("Allowlist", () => {
2525
it("can map config to advisories Allowlist", () => {
2626
const { advisories, modules, paths } = Allowlist.mapConfigToAllowlist({
2727
allowlist: [
28-
"GHSA-pw2r-vq6v-hr8c",
28+
"GHSA-42xw-2xvc-qx8m",
29+
"GHSA-4w2v-q235-vp99",
2930
"GHSA-74fj-2j2h-c42q",
3031
"GHSA-cph5-m8f7-6c5x",
31-
"GHSA-4w2v-q235-vp99",
32-
"GHSA-42xw-2xvc-qx8m",
32+
"GHSA-pw2r-vq6v-hr8c",
3333
],
3434
});
3535
expect(advisories).to.deep.equal([
36-
"GHSA-pw2r-vq6v-hr8c",
36+
"GHSA-42xw-2xvc-qx8m",
37+
"GHSA-4w2v-q235-vp99",
3738
"GHSA-74fj-2j2h-c42q",
3839
"GHSA-cph5-m8f7-6c5x",
39-
"GHSA-4w2v-q235-vp99",
40-
"GHSA-42xw-2xvc-qx8m",
40+
"GHSA-pw2r-vq6v-hr8c",
4141
]);
4242
expect(modules).to.deep.equal([]);
4343
expect(paths).to.deep.equal([]);
@@ -46,21 +46,21 @@ describe("Allowlist", () => {
4646
it("can map config to paths Allowlist", () => {
4747
const { advisories, modules, paths } = Allowlist.mapConfigToAllowlist({
4848
allowlist: [
49-
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
49+
"GHSA-42xw-2xvc-qx8m|axios",
50+
"GHSA-4w2v-q235-vp99|axios",
5051
"GHSA-74fj-2j2h-c42q|axios>follow-redirects",
5152
"GHSA-cph5-m8f7-6c5x|axios",
52-
"GHSA-4w2v-q235-vp99|axios",
53-
"GHSA-42xw-2xvc-qx8m|axios",
53+
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
5454
],
5555
});
5656
expect(advisories).to.deep.equal([]);
5757
expect(modules).to.deep.equal([]);
5858
expect(paths).to.deep.equal([
59-
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
59+
"GHSA-42xw-2xvc-qx8m|axios",
60+
"GHSA-4w2v-q235-vp99|axios",
6061
"GHSA-74fj-2j2h-c42q|axios>follow-redirects",
6162
"GHSA-cph5-m8f7-6c5x|axios",
62-
"GHSA-4w2v-q235-vp99|axios",
63-
"GHSA-42xw-2xvc-qx8m|axios",
63+
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
6464
]);
6565
});
6666

test/npm-auditer.spec.ts

+26-26
Original file line numberDiff line numberDiff line change
@@ -269,36 +269,36 @@ describe("npm-auditer", () => {
269269
directory: testDirectory("npm-allowlisted-path"),
270270
levels: { moderate: true },
271271
allowlist: new Allowlist([
272+
"*|github-build>axios",
272273
"GHSA-42xw-2xvc-qx8m|axios",
273274
"GHSA-42xw-2xvc-qx8m|github-build>*",
274275
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
275276
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
276-
"*|github-build>axios",
277277
]),
278278
}),
279279
(_summary) => _summary
280280
);
281281
expect(summary).to.eql(
282282
summaryWithDefault({
283283
advisoriesFound: [
284+
"GHSA-4w2v-q235-vp99",
284285
"GHSA-74fj-2j2h-c42q",
285286
"GHSA-cph5-m8f7-6c5x",
286-
"GHSA-4w2v-q235-vp99",
287287
],
288288
failedLevelsFound: ["high"],
289289
allowlistedPathsFound: [
290-
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
291-
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
292-
"GHSA-cph5-m8f7-6c5x|github-build>axios",
293-
"GHSA-4w2v-q235-vp99|github-build>axios",
294290
"GHSA-42xw-2xvc-qx8m|axios",
295291
"GHSA-42xw-2xvc-qx8m|github-build>axios",
292+
"GHSA-4w2v-q235-vp99|github-build>axios",
293+
"GHSA-cph5-m8f7-6c5x|github-build>axios",
294+
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
295+
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
296296
],
297297
advisoryPathsFound: [
298+
"GHSA-4w2v-q235-vp99|axios",
298299
"GHSA-74fj-2j2h-c42q|axios>follow-redirects",
299300
"GHSA-74fj-2j2h-c42q|github-build>axios>follow-redirects",
300301
"GHSA-cph5-m8f7-6c5x|axios",
301-
"GHSA-4w2v-q235-vp99|axios",
302302
],
303303
})
304304
);
@@ -310,33 +310,33 @@ describe("npm-auditer", () => {
310310
directory: testDirectory("npm-allowlisted-path"),
311311
levels: { moderate: true },
312312
allowlist: new Allowlist([
313-
"GHSA-cph5-m8f7-6c5x|axios",
314-
"GHSA-4w2v-q235-vp99|axios",
315313
"GHSA-42xw-2xvc-qx8m|axios",
316-
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
317-
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
314+
"GHSA-42xw-2xvc-qx8m|github-build>axios",
315+
"GHSA-4w2v-q235-vp99|axios",
316+
"GHSA-4w2v-q235-vp99|github-build>axios",
318317
"GHSA-74fj-2j2h-c42q|axios>follow-redirects",
319318
"GHSA-74fj-2j2h-c42q|github-build>axios>follow-redirects",
319+
"GHSA-cph5-m8f7-6c5x|axios",
320320
"GHSA-cph5-m8f7-6c5x|github-build>axios",
321-
"GHSA-4w2v-q235-vp99|github-build>axios",
322-
"GHSA-42xw-2xvc-qx8m|github-build>axios",
321+
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
322+
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
323323
]),
324324
}),
325325
(_summary) => _summary
326326
);
327327
expect(summary).to.eql(
328328
summaryWithDefault({
329329
allowlistedPathsFound: [
330-
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
331-
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
330+
"GHSA-42xw-2xvc-qx8m|axios",
331+
"GHSA-42xw-2xvc-qx8m|github-build>axios",
332+
"GHSA-4w2v-q235-vp99|axios",
333+
"GHSA-4w2v-q235-vp99|github-build>axios",
332334
"GHSA-74fj-2j2h-c42q|axios>follow-redirects",
333335
"GHSA-74fj-2j2h-c42q|github-build>axios>follow-redirects",
334336
"GHSA-cph5-m8f7-6c5x|axios",
335337
"GHSA-cph5-m8f7-6c5x|github-build>axios",
336-
"GHSA-4w2v-q235-vp99|axios",
337-
"GHSA-4w2v-q235-vp99|github-build>axios",
338-
"GHSA-42xw-2xvc-qx8m|axios",
339-
"GHSA-42xw-2xvc-qx8m|github-build>axios",
338+
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
339+
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
340340
],
341341
})
342342
);
@@ -347,23 +347,23 @@ describe("npm-auditer", () => {
347347
config({
348348
directory: testDirectory("npm-allowlisted-path"),
349349
levels: { moderate: true },
350-
allowlist: new Allowlist(["*|axios", "*|github-build>*", "*|axios>*"]),
350+
allowlist: new Allowlist(["*|axios", "*|axios>*", "*|github-build>*"]),
351351
}),
352352
(_summary) => _summary
353353
);
354354
expect(summary).to.eql(
355355
summaryWithDefault({
356356
allowlistedPathsFound: [
357-
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
358-
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
357+
"GHSA-42xw-2xvc-qx8m|axios",
358+
"GHSA-42xw-2xvc-qx8m|github-build>axios",
359+
"GHSA-4w2v-q235-vp99|axios",
360+
"GHSA-4w2v-q235-vp99|github-build>axios",
359361
"GHSA-74fj-2j2h-c42q|axios>follow-redirects",
360362
"GHSA-74fj-2j2h-c42q|github-build>axios>follow-redirects",
361363
"GHSA-cph5-m8f7-6c5x|axios",
362364
"GHSA-cph5-m8f7-6c5x|github-build>axios",
363-
"GHSA-4w2v-q235-vp99|axios",
364-
"GHSA-4w2v-q235-vp99|github-build>axios",
365-
"GHSA-42xw-2xvc-qx8m|axios",
366-
"GHSA-42xw-2xvc-qx8m|github-build>axios",
365+
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
366+
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
367367
],
368368
})
369369
);

test/npm7-auditer.spec.ts

+27-27
Original file line numberDiff line numberDiff line change
@@ -252,36 +252,36 @@ describe("npm7-auditer", () => {
252252
directory: testDirectory("npm-allowlisted-path"),
253253
levels: { moderate: true },
254254
allowlist: new Allowlist([
255+
"*|github-build>axios",
255256
"GHSA-42xw-2xvc-qx8m|axios",
256257
"GHSA-42xw-2xvc-qx8m|github-build>*",
257258
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
258259
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
259-
"*|github-build>axios",
260260
]),
261261
}),
262262
(_summary) => _summary
263263
);
264264
expect(summary).to.eql(
265265
summaryWithDefault({
266266
advisoriesFound: [
267-
"GHSA-cph5-m8f7-6c5x",
268267
"GHSA-4w2v-q235-vp99",
269268
"GHSA-74fj-2j2h-c42q",
269+
"GHSA-cph5-m8f7-6c5x",
270270
],
271271
failedLevelsFound: ["high"],
272272
allowlistedPathsFound: [
273-
"GHSA-cph5-m8f7-6c5x|github-build>axios",
274-
"GHSA-4w2v-q235-vp99|github-build>axios",
275273
"GHSA-42xw-2xvc-qx8m|axios",
276274
"GHSA-42xw-2xvc-qx8m|github-build>axios",
277-
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
275+
"GHSA-4w2v-q235-vp99|github-build>axios",
276+
"GHSA-cph5-m8f7-6c5x|github-build>axios",
278277
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
278+
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
279279
],
280280
advisoryPathsFound: [
281-
"GHSA-cph5-m8f7-6c5x|axios",
282281
"GHSA-4w2v-q235-vp99|axios",
283-
"GHSA-74fj-2j2h-c42q|github-build>axios>follow-redirects",
284282
"GHSA-74fj-2j2h-c42q|axios>follow-redirects",
283+
"GHSA-74fj-2j2h-c42q|github-build>axios>follow-redirects",
284+
"GHSA-cph5-m8f7-6c5x|axios",
285285
],
286286
})
287287
);
@@ -293,33 +293,33 @@ describe("npm7-auditer", () => {
293293
directory: testDirectory("npm-allowlisted-path"),
294294
levels: { moderate: true },
295295
allowlist: new Allowlist([
296-
"GHSA-cph5-m8f7-6c5x|axios",
297-
"GHSA-4w2v-q235-vp99|axios",
298296
"GHSA-42xw-2xvc-qx8m|axios",
299-
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
300-
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
297+
"GHSA-42xw-2xvc-qx8m|github-build>axios",
298+
"GHSA-4w2v-q235-vp99|axios",
299+
"GHSA-4w2v-q235-vp99|github-build>axios",
301300
"GHSA-74fj-2j2h-c42q|axios>follow-redirects",
302301
"GHSA-74fj-2j2h-c42q|github-build>axios>follow-redirects",
302+
"GHSA-cph5-m8f7-6c5x|axios",
303303
"GHSA-cph5-m8f7-6c5x|github-build>axios",
304-
"GHSA-4w2v-q235-vp99|github-build>axios",
305-
"GHSA-42xw-2xvc-qx8m|github-build>axios",
304+
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
305+
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
306306
]),
307307
}),
308308
(_summary) => _summary
309309
);
310310
expect(summary).to.eql(
311311
summaryWithDefault({
312312
allowlistedPathsFound: [
313-
"GHSA-cph5-m8f7-6c5x|axios",
314-
"GHSA-cph5-m8f7-6c5x|github-build>axios",
315-
"GHSA-4w2v-q235-vp99|axios",
316-
"GHSA-4w2v-q235-vp99|github-build>axios",
317313
"GHSA-42xw-2xvc-qx8m|axios",
318314
"GHSA-42xw-2xvc-qx8m|github-build>axios",
319-
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
320-
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
321-
"GHSA-74fj-2j2h-c42q|github-build>axios>follow-redirects",
315+
"GHSA-4w2v-q235-vp99|axios",
316+
"GHSA-4w2v-q235-vp99|github-build>axios",
322317
"GHSA-74fj-2j2h-c42q|axios>follow-redirects",
318+
"GHSA-74fj-2j2h-c42q|github-build>axios>follow-redirects",
319+
"GHSA-cph5-m8f7-6c5x|axios",
320+
"GHSA-cph5-m8f7-6c5x|github-build>axios",
321+
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
322+
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
323323
],
324324
})
325325
);
@@ -337,16 +337,16 @@ describe("npm7-auditer", () => {
337337
expect(summary).to.eql(
338338
summaryWithDefault({
339339
allowlistedPathsFound: [
340-
"GHSA-cph5-m8f7-6c5x|axios",
341-
"GHSA-cph5-m8f7-6c5x|github-build>axios",
342-
"GHSA-4w2v-q235-vp99|axios",
343-
"GHSA-4w2v-q235-vp99|github-build>axios",
344340
"GHSA-42xw-2xvc-qx8m|axios",
345341
"GHSA-42xw-2xvc-qx8m|github-build>axios",
346-
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
347-
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
348-
"GHSA-74fj-2j2h-c42q|github-build>axios>follow-redirects",
342+
"GHSA-4w2v-q235-vp99|axios",
343+
"GHSA-4w2v-q235-vp99|github-build>axios",
349344
"GHSA-74fj-2j2h-c42q|axios>follow-redirects",
345+
"GHSA-74fj-2j2h-c42q|github-build>axios>follow-redirects",
346+
"GHSA-cph5-m8f7-6c5x|axios",
347+
"GHSA-cph5-m8f7-6c5x|github-build>axios",
348+
"GHSA-pw2r-vq6v-hr8c|axios>follow-redirects",
349+
"GHSA-pw2r-vq6v-hr8c|github-build>axios>follow-redirects",
350350
],
351351
})
352352
);

0 commit comments

Comments
 (0)