Skip to content

Commit 3c2b3a8

Browse files
authored
feat: CVSS Scores - Vulnerabilities Table page (guacsec#991)
Signed-off-by: Bryan Ramos <bramos@redhat.com>
1 parent efe3b95 commit 3c2b3a8

File tree

5 files changed

+71
-9
lines changed

5 files changed

+71
-9
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { render, screen } from "@testing-library/react";
2+
import "@testing-library/jest-dom";
3+
4+
import type { ScoreType } from "@app/client";
5+
6+
import { CvssVersionBadge } from "./CvssVersionBadge";
7+
8+
describe("CvssVersionBadge", () => {
9+
it("renders nothing when version is undefined", () => {
10+
const { container } = render(<CvssVersionBadge version={undefined} />);
11+
expect(container).toBeEmptyDOMElement();
12+
});
13+
14+
it.each<ScoreType>([
15+
"2.0",
16+
"3.0",
17+
"3.1",
18+
"4.0",
19+
])("renders a label with 'v%s' for version '%s'", (version) => {
20+
render(<CvssVersionBadge version={version} />);
21+
expect(screen.getByText(`v${version}`)).toBeInTheDocument();
22+
});
23+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type React from "react";
2+
3+
import { Label } from "@patternfly/react-core";
4+
5+
import type { ScoreType } from "@app/client";
6+
7+
interface CvssVersionBadgeProps {
8+
version: ScoreType | undefined;
9+
}
10+
11+
export const CvssVersionBadge: React.FC<CvssVersionBadgeProps> = ({
12+
version,
13+
}) => {
14+
if (!version) {
15+
return null;
16+
}
17+
18+
return (
19+
<Label isCompact color="grey">
20+
v{version}
21+
</Label>
22+
);
23+
};

client/src/app/pages/vulnerability-list/vulnerability-table.tsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
Tr,
1212
} from "@patternfly/react-table";
1313

14+
import { Flex, FlexItem } from "@patternfly/react-core";
15+
1416
import { extendedSeverityFromSeverity } from "@app/api/models";
1517
import { SeverityShieldAndText } from "@app/components/SeverityShieldAndText";
1618
import { SimplePagination } from "@app/components/SimplePagination";
@@ -24,6 +26,7 @@ import { Paths } from "@app/Routes";
2426
import { formatDate } from "@app/utils/utils";
2527

2628
import { TdWithFocusStatus } from "@app/components/TdWithFocusStatus";
29+
import { CvssVersionBadge } from "./components/CvssVersionBadge";
2730
import { SbomsCount } from "./components/SbomsCount";
2831
import { VulnerabilitySearchContext } from "./vulnerability-context";
2932

@@ -55,7 +58,7 @@ export const VulnerabilityTable: React.FC = () => {
5558
{...getThProps({ columnKey: "severity" })}
5659
info={{
5760
tooltip:
58-
"The Common Vulnerability Scoring System measuring the severity of security flaws.",
61+
"Scores shown are the original CVSS records from the CVE Project. Refer to the SBOM view for product-specific impact assessments.",
5962
}}
6063
/>
6164
<Th {...getThProps({ columnKey: "published" })} />
@@ -115,14 +118,25 @@ export const VulnerabilityTable: React.FC = () => {
115118
)}
116119
</TdWithFocusStatus>
117120
<Td width={10} {...getTdProps({ columnKey: "severity" })}>
118-
<SeverityShieldAndText
119-
value={extendedSeverityFromSeverity(
120-
item.base_score?.severity,
121-
)}
122-
score={item.base_score?.score ?? null}
123-
showLabel
124-
showScore
125-
/>
121+
<Flex
122+
alignItems={{ default: "alignItemsCenter" }}
123+
gap={{ default: "gapSm" }}
124+
flexWrap={{ default: "nowrap" }}
125+
>
126+
<FlexItem>
127+
<SeverityShieldAndText
128+
value={extendedSeverityFromSeverity(
129+
item.base_score?.severity,
130+
)}
131+
score={item.base_score?.score ?? null}
132+
showLabel
133+
showScore
134+
/>
135+
</FlexItem>
136+
<FlexItem>
137+
<CvssVersionBadge version={item.base_score?.type} />
138+
</FlexItem>
139+
</Flex>
126140
</Td>
127141
<Td width={10} {...getTdProps({ columnKey: "published" })}>
128142
{formatDate(item.published)}

client/src/mocks/fileMock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "test-file-stub";

client/src/mocks/styleMock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};

0 commit comments

Comments
 (0)