Skip to content

Commit 735659a

Browse files
committed
Cleanup code and update dependencies
1 parent c2cac9d commit 735659a

File tree

14 files changed

+160
-135
lines changed

14 files changed

+160
-135
lines changed

package-lock.json

Lines changed: 101 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
"src/**/*.ejs"
3434
],
3535
"dependencies": {
36-
"axios": "^1.9.0",
36+
"axios": "^1.10.0",
3737
"ejs": "npm:neat-ejs@^3.1.10",
3838
"jsonpath-plus": "^10.3.0"
3939
},
4040
"devDependencies": {
41-
"@eslint/js": "^9.27.0",
41+
"@eslint/js": "^9.30.0",
4242
"c8": "^10.1.3",
43-
"eslint": "^9.27.0",
43+
"eslint": "^9.30.0",
4444
"express": "^5.1.0",
4545
"globals": "^16.2.0",
46-
"mocha": "^11.5.0",
46+
"mocha": "^11.7.1",
4747
"mocha-junit-reporter": "^2.2.1"
4848
},
4949
"engines": {

src/cli.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* CLI and environment handling service
44
*/
55

6-
import { existsSync } from "fs";
7-
import { readFile } from "fs/promises";
6+
import { existsSync } from "node:fs";
7+
import { readFile } from "node:fs/promises";
88

99
/**
1010
* Statuses expected for the "status" CLI option
@@ -113,7 +113,7 @@ export async function parseArgs() {
113113
// Extract options
114114
for (const opt of expectedOptions) {
115115
// From the command line
116-
const i = process.argv.findIndex(a => a == `--${opt.name}`);
116+
const i = process.argv.findIndex(a => a === `--${opt.name}`);
117117
let value = undefined;
118118
if (i >= 0 && i + 1 < process.argv.length) {
119119
value = process.argv[i + 1];
@@ -157,10 +157,9 @@ export class CliError extends Error {
157157
*
158158
* @param {number} exitCode Process exit code
159159
* @param {string} message Error message
160-
* @param {...any} args Other arguments
161160
*/
162-
constructor(exitCode = 1, message = "", ...args) {
163-
super(message, ...args);
161+
constructor(exitCode = 1, message = "") {
162+
super(message);
164163
this.exitCode = exitCode;
165164
}
166165

src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Tool configuration service
44
*/
55

6-
import { readFile } from "fs/promises";
6+
import { readFile } from "node:fs/promises";
77
import { JSONPath } from "jsonpath-plus";
88

99
/**

src/defectdojo.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export class DefectDojoApiClient {
5252
/**
5353
* Fetch engagements by product and name.
5454
*
55-
* @param {string} productId Product id
56-
* @param {string} name Engagement name (optional)
57-
* @returns Engagements
55+
* @param {string|number} productId Product id
56+
* @param {string} [name] Engagement name (optional)
57+
* @returns Promise<any> Engagements
5858
* @throws Request error
5959
*/
6060
async getEngagements(productId, name) {
@@ -81,7 +81,7 @@ export class DefectDojoApiClient {
8181
*
8282
* @param {string[]} engagements Engagements ids
8383
* @param {string[]} statuses Statuses to filter
84-
* @returns Vulnerabilities
84+
* @returns Promise<any> Vulnerabilities
8585
* @throws Request error
8686
*/
8787
async getFindings(engagements, statuses) {

src/exports.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*/
55

66
import ejs from "ejs";
7-
import { readFile, writeFile } from "fs/promises";
8-
import { dirname, join } from "path";
9-
import { fileURLToPath } from "url";
7+
import { readFile, writeFile } from "node:fs/promises";
8+
import { dirname, join } from "node:path";
9+
import { fileURLToPath } from "node:url";
1010
import { resolveField } from "./config.js";
1111

1212
/**

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
import { main } from "./main.js";
99

10-
main();
10+
await main();

src/main.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* Export a security debt from DefectDojo.
44
*/
55

6-
import { join } from "path";
6+
import assert from "node:assert/strict";
7+
import { join } from "node:path";
78
import { parseArgs } from "./cli.js";
89
import { loadConfig } from "./config.js";
910
import { DefectDojoApiClient } from "./defectdojo.js";
@@ -40,6 +41,8 @@ export async function main() {
4041
return [...results, ...engagements];
4142
}, []);
4243

44+
assert(engagements.length > 0, "No engagement found");
45+
4346
// Fetch vulnerabilities
4447
const findings = await defectDojo
4548
.getFindings(engagements.map(e => e.id), opts.status)
@@ -58,7 +61,7 @@ export async function main() {
5861
for (const finding of findings) {
5962
// Resultant criticity
6063
finding.severity = finding.severity?.toLowerCase();
61-
const i = Math.max(impacts.findIndex(i => i == finding.severity), 0);
64+
const i = Math.max(impacts.findIndex(i => i === finding.severity), 0);
6265
const e = easeTags.indexOf(finding.tags?.find(t => easeTags.includes(t)) ?? easeTags[0]);
6366
finding.ease_index = e;
6467
finding.ease = eases[e];
@@ -82,13 +85,13 @@ export async function main() {
8285
(f2.severity_index - f1.severity_index) || f1.title.localeCompare(f2.title));
8386

8487
console.log("[info] Vulnerabilities:", criticities.map(c =>
85-
findings.filter(f => f.criticity == c).length + " " + c).join(", "));
88+
findings.filter(f => f.criticity === c).length + " " + c).join(", "));
8689

8790
/*
8891
* Generate reports
8992
*/
9093

91-
const defaultReportName = "Security-Debt" + (products.length == 1 ? `_${products[0].name}` : "");
94+
const defaultReportName = "Security-Debt" + (products.length === 1 ? `_${products[0].name}` : "");
9295
const path = opts.output ?? join(process.cwd(), defaultReportName);
9396

9497
for (const format of opts.format) {

src/template.ejs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
td, th {
6565
padding: .3em .6em;
6666
border: 1px solid #dbdbdb;
67-
border-width: 1px;
6867
}
6968
thead th {
7069
border-width: 1px 1px 2px 1px;
@@ -130,9 +129,9 @@
130129
<%_ for (const finding of findings) { -%>
131130
<tr>
132131
<%_ for (const field of finding) { -%>
133-
<%_ if (field.type == "criticity") { -%>
132+
<%_ if (field.type === "criticity") { -%>
134133
<td class="criticity c<%= field.index %>"><%= field.value %></td>
135-
<%_ } else if (field.type == "boolean") { -%>
134+
<%_ } else if (field.type === "boolean") { -%>
136135
<td><%= field.value ? "Y" : "N" %></td>
137136
<%_ } else { -%>
138137
<td <%_ if (field.value?.length > 20) { %> title="<%= field.value %>" <% } %>><%= field.value -%></td>

test/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import assert from "assert";
1+
import assert from "node:assert/strict";
22
import { CliError, parseArgs } from "../src/cli.js";
33

44
describe("cli", function () {
@@ -38,7 +38,7 @@ describe("cli", function () {
3838
} else { // Success expected
3939
let opts;
4040
await assert.doesNotReject(async () => { opts = await parseArgs() });
41-
assert.strictEqual(Object.keys(opts).length, 8);
41+
assert.equal(Object.keys(opts).length, 8);
4242
}
4343
});
4444
}

0 commit comments

Comments
 (0)