Skip to content

Commit dc23c27

Browse files
authored
feat: add config for controlling number of vulns (#232)
* feat: add config for controlling number of vulns * chore: run linting * chore: fix broken specs
1 parent f6bade1 commit dc23c27

4 files changed

Lines changed: 66 additions & 20 deletions

File tree

e2e/scan/eol.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { describe, it } from 'node:test';
88
import { fileURLToPath } from 'node:url';
99
import { promisify } from 'node:util';
1010
import { runCommand } from '@oclif/test';
11+
import { config } from '../../src/config/constants';
1112

1213
const execAsync = promisify(exec);
1314

@@ -22,7 +23,11 @@ describe('default arguments', () => {
2223

2324
// Match table header
2425
match(stdout, /.*.*.*.*.*/, 'Should show table top border');
25-
match(stdout, / NAME\s* VERSION\s* EOL\s* DAYS EOL\s* TYPE\s* # OF VULNS*|/, 'Should show table headers');
26+
if (config.showVulnCount) {
27+
match(stdout, / NAME\s* VERSION\s* EOL\s* DAYS EOL\s* TYPE\s* # OF VULNS*|/, 'Should show table headers');
28+
} else {
29+
match(stdout, / NAME\s* VERSION\s* EOL\s* DAYS EOL\s* TYPE\s*|/, 'Should show table headers');
30+
}
2631
match(stdout, /.*.*.*.*.*/, 'Should show table header separator');
2732

2833
// Match table content
@@ -192,7 +197,11 @@ describe('scan:eol e2e', () => {
192197

193198
// Match table header
194199
match(stdout, /.*.*.*.*.*/, 'Should show table top border');
195-
match(stdout, / NAME\s* VERSION\s* EOL\s* DAYS EOL\s* TYPE\s* # OF VULNS*|/, 'Should show table headers');
200+
if (config.showVulnCount) {
201+
match(stdout, / NAME\s* VERSION\s* EOL\s* DAYS EOL\s* TYPE\s* # OF VULNS*|/, 'Should show table headers');
202+
} else {
203+
match(stdout, / NAME\s* VERSION\s* EOL\s* DAYS EOL\s* TYPE\s*|/, 'Should show table headers');
204+
}
196205
match(stdout, /.*.*.*.*.*/, 'Should show table header separator');
197206

198207
// Match table content

src/config/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export const config = {
66
eolReportUrl: process.env.EOL_REPORT_URL || EOL_REPORT_URL,
77
graphqlHost: process.env.GRAPHQL_HOST || GRAPHQL_HOST,
88
graphqlPath: process.env.GRAPHQL_PATH || GRAPHQL_PATH,
9+
showVulnCount: false,
910
};

src/ui/eol.ui.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
InsightsEolScanComponent,
88
InsightsEolScanComponentInfo,
99
} from '../api/types/nes.types.ts';
10+
import { config } from '../config/constants.ts';
1011
import { resolvePurlPackageName } from '../service/eol/eol.svc.ts';
1112
import { parseMomentToSimpleDate } from './date.ui.ts';
1213
import { INDICATORS, MAX_PURL_LENGTH, MAX_TABLE_COLUMN_WIDTH, STATUS_COLORS } from './shared.ui.ts';
@@ -44,13 +45,13 @@ function formatDetailedComponent(purl: string, info: InsightsEolScanComponentInf
4445
const eolAtString = parseMomentToSimpleDate(eolAt);
4546
const daysEolString = getDaysEolString(daysEol);
4647

47-
const output = [
48-
`${simpleComponent}`,
49-
` ⮑ EOL Date: ${eolAtString} (${daysEolString})`,
50-
` ⮑ # of Vulns: ${vulnCount ?? ''}`,
51-
]
52-
.filter(Boolean)
53-
.join('\n');
48+
const eolString = [`${simpleComponent}`, ` ⮑ EOL Date: ${eolAtString} (${daysEolString})`];
49+
50+
if (config.showVulnCount) {
51+
eolString.push(` ⮑ # of Vulns: ${vulnCount ?? ''}`);
52+
}
53+
54+
const output = eolString.filter(Boolean).join('\n');
5455

5556
return output;
5657
}
@@ -90,6 +91,19 @@ export function createTableForStatus(
9091
const data = grouped[status].map((component) => convertComponentToTableRow(component));
9192

9293
if (status === 'EOL' || status === 'SUPPORTED') {
94+
if (config.showVulnCount) {
95+
return makeTable({
96+
data,
97+
columns: [
98+
{ key: 'name', name: 'NAME', width: MAX_TABLE_COLUMN_WIDTH },
99+
{ key: 'version', name: 'VERSION', width: 10 },
100+
{ key: 'eol', name: 'EOL', width: 12 },
101+
{ key: 'daysEol', name: 'DAYS EOL', width: 10 },
102+
{ key: 'type', name: 'TYPE', width: 12 },
103+
{ key: 'vulnCount', name: '# OF VULNS', width: 12 },
104+
],
105+
});
106+
}
93107
return makeTable({
94108
data,
95109
columns: [
@@ -98,17 +112,28 @@ export function createTableForStatus(
98112
{ key: 'eol', name: 'EOL', width: 12 },
99113
{ key: 'daysEol', name: 'DAYS EOL', width: 10 },
100114
{ key: 'type', name: 'TYPE', width: 12 },
115+
],
116+
});
117+
}
118+
119+
if (config.showVulnCount) {
120+
return makeTable({
121+
data,
122+
columns: [
123+
{ key: 'name', name: 'NAME', width: MAX_TABLE_COLUMN_WIDTH },
124+
{ key: 'version', name: 'VERSION', width: 10 },
125+
{ key: 'type', name: 'TYPE', width: 12 },
101126
{ key: 'vulnCount', name: '# OF VULNS', width: 12 },
102127
],
103128
});
104129
}
130+
105131
return makeTable({
106132
data,
107133
columns: [
108134
{ key: 'name', name: 'NAME', width: MAX_TABLE_COLUMN_WIDTH },
109135
{ key: 'version', name: 'VERSION', width: 10 },
110136
{ key: 'type', name: 'TYPE', width: 12 },
111-
{ key: 'vulnCount', name: '# OF VULNS', width: 12 },
112137
],
113138
});
114139
}

test/ui/eol.ui.test.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert from 'node:assert';
22
import { describe, it } from 'node:test';
3+
import { config } from '../../src/config/constants.ts';
34
import {
45
convertComponentToTableRow,
56
createTableForStatus,
@@ -89,8 +90,12 @@ describe('EOL UI', () => {
8990
// Assert
9091
assert.strictEqual(typeof table, 'string');
9192
// Check that the table contains the expected data, ignoring exact formatting
92-
assert.match(table, /test1.*1.0.0.*2023-01-01.*365.*npm.*0/);
93-
assert.match(table, /test3.*3.0.0.*2023-02-01.*400.*npm.*0/);
93+
if (config.showVulnCount) {
94+
assert.match(table, /test1.*1.0.0.*2023-01-01.*365.*npm.*0/);
95+
} else {
96+
assert.match(table, /test1.*1.0.0.*2023-01-01.*365.*npm/);
97+
}
98+
assert.match(table, /test3.*3.0.0.*2023-02-01.*400.*npm/);
9499
});
95100

96101
it('returns empty table when no components match status', () => {
@@ -123,13 +128,16 @@ describe('EOL UI', () => {
123128
// Check that the table contains the expected columns in order
124129
const lines = table.split('\n');
125130
const headerLine = lines[1]; // Second line contains headers
126-
assert.match(headerLine, /NAME.*VERSION.*TYPE.*# OF VULNS/);
131+
if (config.showVulnCount) {
132+
assert.match(headerLine, /NAME.*VERSION.*TYPE.*# OF VULNS/);
133+
assert.match(table, /test1.*1.0.0.*npm.*0/);
134+
} else {
135+
assert.match(headerLine, /NAME.*VERSION.*TYPE/);
136+
assert.match(table, /test1.*1.0.0.*npm/);
137+
}
127138
// Verify EOL and DAYS EOL columns are not present
128139
assert.doesNotMatch(headerLine, /EOL/);
129140
assert.doesNotMatch(headerLine, /DAYS EOL/);
130-
// Check data rows
131-
assert.match(table, /test1.*1.0.0.*npm.*0/);
132-
assert.match(table, /test3.*3.0.0.*npm.*0/);
133141
});
134142

135143
it('creates a table for UNKNOWN status without EOL columns', () => {
@@ -149,13 +157,16 @@ describe('EOL UI', () => {
149157
// Check that the table contains the expected columns in order
150158
const lines = table.split('\n');
151159
const headerLine = lines[1]; // Second line contains headers
152-
assert.match(headerLine, /NAME.*VERSION.*TYPE.*# OF VULNS/);
160+
if (config.showVulnCount) {
161+
assert.match(headerLine, /NAME.*VERSION.*TYPE.*# OF VULNS/);
162+
assert.match(table, /test1.*1.0.0.*npm.*0/);
163+
} else {
164+
assert.match(headerLine, /NAME.*VERSION.*TYPE/);
165+
assert.match(table, /test1.*1.0.0.*npm/);
166+
}
153167
// Verify EOL and DAYS EOL columns are not present
154168
assert.doesNotMatch(headerLine, /EOL/);
155169
assert.doesNotMatch(headerLine, /DAYS EOL/);
156-
// Check data rows
157-
assert.match(table, /test1.*1.0.0.*npm.*0/);
158-
assert.match(table, /test3.*3.0.0.*npm.*0/);
159170
});
160171

161172
it('returns empty table when no components match status', () => {

0 commit comments

Comments
 (0)