@skyhook-io/radar-app 1.21.3 → 1.21.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/App.tsx +3 -0
- package/src/api/radarFeatures.ts +1 -0
- package/src/api/vulnerabilities.export.test.ts +44 -0
- package/src/api/vulnerabilities.ts +73 -4
- package/src/components/audit/VulnerabilitiesView.test.tsx +177 -0
- package/src/components/audit/VulnerabilitiesView.tsx +197 -48
- package/src/components/traffic/TrafficGraph.export.test.tsx +57 -0
- package/src/components/traffic/TrafficGraph.tsx +9 -4
- package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +1 -0
- package/src/components/traffic/TrafficView.tsx +17 -2
- package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.test.tsx +30 -1
- package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +3 -2
- package/src/components/vulnerabilities/parts.test.ts +59 -3
- package/src/components/vulnerabilities/parts.tsx +199 -5
- package/src/hooks/useDesktopDownload.test.tsx +57 -0
- package/src/hooks/useDesktopDownload.ts +31 -9
package/package.json
CHANGED
package/src/App.tsx
CHANGED
|
@@ -49,6 +49,7 @@ import { currentPageLabel } from './utils/page-links'
|
|
|
49
49
|
import { navigateFromPrimaryRail } from './components/nav/navigation'
|
|
50
50
|
import { useNavRailPinned } from './hooks/useNavRailPinned'
|
|
51
51
|
import { useMediaQuery } from './hooks/useMediaQuery'
|
|
52
|
+
import { useDesktopBlobDownload } from './hooks/useDesktopDownload'
|
|
52
53
|
import { ContextSwitchProvider, useContextSwitch } from './context/ContextSwitchContext'
|
|
53
54
|
import { ConnectionProvider, useConnection, refreshQueriesAfterReconnect } from './context/ConnectionContext'
|
|
54
55
|
import { DisconnectedView, FailedSwitchView } from './components/SwitchAwareConnectionError'
|
|
@@ -649,6 +650,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
649
650
|
|
|
650
651
|
// Topology live-update pause state
|
|
651
652
|
const [topologyPaused, setTopologyPaused] = useState(false)
|
|
653
|
+
const desktopBlobDownload = useDesktopBlobDownload()
|
|
652
654
|
const [displayedTopology, setDisplayedTopology] = useState<typeof topology>(null)
|
|
653
655
|
const pendingTopologyRef = useRef<typeof topology>(null)
|
|
654
656
|
|
|
@@ -2318,6 +2320,7 @@ function AppInner({ manageDocumentTitle = false, documentTitleSuffix, onClusterL
|
|
|
2318
2320
|
hideGroupHeader={hideGroupHeader}
|
|
2319
2321
|
onNodeClick={handleNodeClick}
|
|
2320
2322
|
selectedNodeId={selectedNodeId}
|
|
2323
|
+
onDownloadBlob={desktopBlobDownload}
|
|
2321
2324
|
paused={topologyPaused}
|
|
2322
2325
|
onTogglePause={handleTogglePause}
|
|
2323
2326
|
onMaximizeNamespace={(ns) => setActiveNamespace.mutate({ namespaces: [ns] })}
|
package/src/api/radarFeatures.ts
CHANGED
|
@@ -85,6 +85,7 @@ export const RADAR_FEATURES = {
|
|
|
85
85
|
agentSigninCheck: { label: 'Agent sign-in checks', flag: 'agentSigninCheck', flagShippedWithEndpoint: true },
|
|
86
86
|
podFileUpload: { label: 'Pod file uploads', flag: 'podFileUpload', flagShippedWithEndpoint: true },
|
|
87
87
|
vulnerabilities: { label: 'Vulnerability views', flag: 'vulnerabilities', flagShippedWithEndpoint: true },
|
|
88
|
+
vulnerabilitiesExport: { label: 'Vulnerability CSV downloads', flag: 'vulnerabilitiesExport', flagShippedWithEndpoint: true },
|
|
88
89
|
runtimeAdvisoryChecks: { label: 'Java4Shell checks', flag: 'runtimeAdvisoryChecks', flagShippedWithEndpoint: true },
|
|
89
90
|
runtimeAdvisoryProgress: { label: 'Java4Shell scan progress', flag: 'runtimeAdvisoryProgress', flagShippedWithEndpoint: true },
|
|
90
91
|
// Never blocks a control: an older Radar ignores the request body and names
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { ApiError } from './client'
|
|
3
|
+
import { fetchVulnerabilitiesCSV, vulnerabilitiesCSVFilename } from './vulnerabilities'
|
|
4
|
+
|
|
5
|
+
afterEach(() => vi.unstubAllGlobals())
|
|
6
|
+
|
|
7
|
+
describe('fetchVulnerabilitiesCSV', () => {
|
|
8
|
+
it('asks for the view and filters the table shows', async () => {
|
|
9
|
+
const fetch = vi.fn(async () => new Response('cluster,scanned,status\r\n', { status: 200 }))
|
|
10
|
+
vi.stubGlobal('fetch', fetch)
|
|
11
|
+
const csv = await fetchVulnerabilitiesCSV({
|
|
12
|
+
view: 'fix', namespaces: ['demo', 'prod'], severities: ['critical'], fixableOnly: true, query: ' nginx ',
|
|
13
|
+
workload: { kind: 'Deployment', group: 'apps', namespace: 'demo', name: 'web' },
|
|
14
|
+
})
|
|
15
|
+
expect(csv).toBe('cluster,scanned,status\r\n')
|
|
16
|
+
const url = new URL(String((fetch.mock.calls[0] as unknown[])[0]), 'http://radar')
|
|
17
|
+
expect(url.pathname).toMatch(/\/vulnerabilities\/export$/)
|
|
18
|
+
expect(Object.fromEntries(url.searchParams)).toEqual({
|
|
19
|
+
view: 'fix', namespaces: 'demo,prod', severity: 'critical', fixable: '1', q: 'nginx',
|
|
20
|
+
workloadKind: 'Deployment', workloadNamespace: 'demo', workloadName: 'web', workloadGroup: 'apps',
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('fails with the server message instead of saving an error page', async () => {
|
|
25
|
+
vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify({ error: 'vulnerability reports aren\'t ready yet', error_code: 'kind_sync_pending' }), {
|
|
26
|
+
status: 503, headers: { 'Content-Type': 'application/json' },
|
|
27
|
+
})))
|
|
28
|
+
const err = await fetchVulnerabilitiesCSV({ view: 'cve' }).catch((e: unknown) => e)
|
|
29
|
+
expect(err).toBeInstanceOf(ApiError)
|
|
30
|
+
expect((err as ApiError).status).toBe(503)
|
|
31
|
+
expect((err as ApiError).message).toBe('vulnerability reports aren\'t ready yet')
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
describe('vulnerabilitiesCSVFilename', () => {
|
|
36
|
+
const day = new Date(2026, 0, 5, 23, 30)
|
|
37
|
+
it('names the view, the cluster and the local date', () => {
|
|
38
|
+
expect(vulnerabilitiesCSVFilename('cve', 'k8sbox-rvuln', day)).toBe('vulnerabilities-by-cve-k8sbox-rvuln-2026-01-05.csv')
|
|
39
|
+
})
|
|
40
|
+
it('keeps the name filesystem-safe', () => {
|
|
41
|
+
expect(vulnerabilitiesCSVFilename('image', 'arn:aws:eks:us-east-1:123:cluster/prod', day)).toBe('vulnerabilities-by-image-arn-aws-eks-us-east-1-123-cluster-prod-2026-01-05.csv')
|
|
42
|
+
expect(vulnerabilitiesCSVFilename('fix', '../..', day)).toBe('vulnerabilities-by-fix-cluster-2026-01-05.csv')
|
|
43
|
+
})
|
|
44
|
+
})
|
|
@@ -30,6 +30,35 @@ export interface VulnerabilityWorkloadRef {
|
|
|
30
30
|
container?: string
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/** A route from outside the cluster to a workload. via: LoadBalancer, NodePort, Ingress or a Gateway API route kind. */
|
|
34
|
+
export interface VulnerabilityRoute {
|
|
35
|
+
via: string
|
|
36
|
+
namespace: string
|
|
37
|
+
name: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A workload with a route from outside the cluster; never a container. */
|
|
41
|
+
export interface ExposedWorkload {
|
|
42
|
+
kind: string
|
|
43
|
+
group: string
|
|
44
|
+
namespace: string
|
|
45
|
+
name: string
|
|
46
|
+
/** At most three in a list read; routesTotal counts them all. */
|
|
47
|
+
routes: VulnerabilityRoute[]
|
|
48
|
+
routesTotal?: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The row's workloads with a route from outside the cluster, capped in a list
|
|
53
|
+
* read; exposedTotal is the full count.
|
|
54
|
+
*/
|
|
55
|
+
export interface VulnerabilityExposure {
|
|
56
|
+
exposed?: ExposedWorkload[]
|
|
57
|
+
exposedTotal?: number
|
|
58
|
+
/** None of the row's workloads is known exposed, but some are where Radar couldn't read every route kind. */
|
|
59
|
+
exposureUnknown?: boolean
|
|
60
|
+
}
|
|
61
|
+
|
|
33
62
|
export interface VulnerabilityFinding {
|
|
34
63
|
id: string
|
|
35
64
|
severity: VulnerabilitySeverity
|
|
@@ -46,7 +75,7 @@ export interface VulnerabilityFinding {
|
|
|
46
75
|
link?: string
|
|
47
76
|
}
|
|
48
77
|
|
|
49
|
-
export interface VulnerableImage {
|
|
78
|
+
export interface VulnerableImage extends VulnerabilityExposure {
|
|
50
79
|
id: string
|
|
51
80
|
image: string
|
|
52
81
|
digest?: string
|
|
@@ -72,7 +101,7 @@ export interface VulnerabilityCVEImage {
|
|
|
72
101
|
workloadsTotal: number
|
|
73
102
|
}
|
|
74
103
|
|
|
75
|
-
export interface VulnerabilityCVE {
|
|
104
|
+
export interface VulnerabilityCVE extends VulnerabilityExposure {
|
|
76
105
|
id: string
|
|
77
106
|
severity: VulnerabilitySeverity
|
|
78
107
|
score?: number
|
|
@@ -87,7 +116,7 @@ export interface VulnerabilityCVE {
|
|
|
87
116
|
affected: VulnerabilityCVEImage[]
|
|
88
117
|
}
|
|
89
118
|
|
|
90
|
-
export interface VulnerabilityFix {
|
|
119
|
+
export interface VulnerabilityFix extends VulnerabilityExposure {
|
|
91
120
|
package: string
|
|
92
121
|
packageType?: string
|
|
93
122
|
/** The lowest listed release that fixes every listed CVE; absent when none can be chosen from the scanner's versions. */
|
|
@@ -123,6 +152,10 @@ export interface VulnerabilityWorkload {
|
|
|
123
152
|
counts: VulnerabilityCounts
|
|
124
153
|
fixable: VulnerabilityCounts
|
|
125
154
|
containers: VulnerabilityWorkloadContainer[]
|
|
155
|
+
routes?: VulnerabilityRoute[]
|
|
156
|
+
routesTotal?: number
|
|
157
|
+
/** No route seen, but Radar couldn't read every route kind that could reach it. */
|
|
158
|
+
exposureUnknown?: boolean
|
|
126
159
|
}
|
|
127
160
|
|
|
128
161
|
export interface VulnerabilitySummary {
|
|
@@ -154,7 +187,16 @@ export interface VulnerabilitiesResponse {
|
|
|
154
187
|
/** Workloads whose every container is scanned and clean. */
|
|
155
188
|
cleanWorkloads?: VulnerabilityWorkloadRef[]
|
|
156
189
|
/** otherBuildScanned: Trivy's report is of another build of this tag, as after the tag moved. */
|
|
157
|
-
unscanned?: { image: string; otherBuildScanned?: boolean; workloads: VulnerabilityWorkloadRef[]; workloadsTotal: number }[]
|
|
190
|
+
unscanned?: ({ image: string; otherBuildScanned?: boolean; workloads: VulnerabilityWorkloadRef[]; workloadsTotal: number } & VulnerabilityExposure)[]
|
|
191
|
+
/**
|
|
192
|
+
* Present when this Radar checks exposure; absent from an older Radar, where
|
|
193
|
+
* exposure is unknown, never none. gaps: route kinds Radar couldn't read.
|
|
194
|
+
*/
|
|
195
|
+
exposure?: {
|
|
196
|
+
gaps?: VulnerabilityGap[]
|
|
197
|
+
/** Route kinds this cluster serves that Radar doesn't follow (Istio, Traefik IngressRoute, Contour, Knative). */
|
|
198
|
+
unchecked?: { kind: string; group?: string }[]
|
|
199
|
+
}
|
|
158
200
|
coverage: {
|
|
159
201
|
complete: boolean
|
|
160
202
|
gaps: VulnerabilityGap[]
|
|
@@ -171,6 +213,8 @@ export interface VulnerabilitiesParams {
|
|
|
171
213
|
namespaces?: string[]
|
|
172
214
|
severities?: VulnerabilitySeverity[]
|
|
173
215
|
fixableOnly?: boolean
|
|
216
|
+
/** Only rows affecting a workload with a route from outside the cluster. */
|
|
217
|
+
exposed?: boolean
|
|
174
218
|
query?: string
|
|
175
219
|
workload?: { kind: string; group?: string; namespace: string; name: string }
|
|
176
220
|
}
|
|
@@ -340,6 +384,7 @@ export function vulnerabilitiesPath(p: VulnerabilitiesParams): string {
|
|
|
340
384
|
if (p.namespaces && p.namespaces.length > 0) params.set('namespaces', p.namespaces.join(','))
|
|
341
385
|
if (p.severities && p.severities.length > 0) params.set('severity', p.severities.join(','))
|
|
342
386
|
if (p.fixableOnly) params.set('fixable', '1')
|
|
387
|
+
if (p.exposed) params.set('exposed', '1')
|
|
343
388
|
if (p.query?.trim()) params.set('q', p.query.trim())
|
|
344
389
|
if (p.workload) {
|
|
345
390
|
params.set('workloadKind', p.workload.kind)
|
|
@@ -350,6 +395,30 @@ export function vulnerabilitiesPath(p: VulnerabilitiesParams): string {
|
|
|
350
395
|
return `/vulnerabilities?${params.toString()}`
|
|
351
396
|
}
|
|
352
397
|
|
|
398
|
+
// GET /api/vulnerabilities/export: the same view and filters as CSV, listing
|
|
399
|
+
// every row and every value the table shortens.
|
|
400
|
+
/** What a CSV export lists: a view's rows, or every finding (one row per CVE, image and workload). */
|
|
401
|
+
export type VulnerabilityExportView = VulnerabilityView | 'findings'
|
|
402
|
+
|
|
403
|
+
export async function fetchVulnerabilitiesCSV(p: VulnerabilitiesParams, as: VulnerabilityExportView = p.view): Promise<string> {
|
|
404
|
+
const query = new URLSearchParams(vulnerabilitiesPath(p).split('?')[1])
|
|
405
|
+
query.set('view', as)
|
|
406
|
+
const path = `/vulnerabilities/export?${query.toString()}`
|
|
407
|
+
const response = await apiFetch(`${getApiBase()}${path}`, { cache: 'no-store' })
|
|
408
|
+
if (!response.ok) {
|
|
409
|
+
const { body, unknownRoute } = await readErrorResponse(response)
|
|
410
|
+
throw new ApiError(body.error || httpStatusMessage(response.status, response.statusText), response.status, body, { unknownRoute })
|
|
411
|
+
}
|
|
412
|
+
return response.text()
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// vulnerabilities-by-<view>-<cluster>-<YYYY-MM-DD>.csv, on the local date.
|
|
416
|
+
export function vulnerabilitiesCSVFilename(view: VulnerabilityExportView, cluster: string, now = new Date()): string {
|
|
417
|
+
const safe = cluster.replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^[-.]+|-+$/g, '') || 'cluster'
|
|
418
|
+
const pad = (n: number) => String(n).padStart(2, '0')
|
|
419
|
+
return `vulnerabilities-${view === 'findings' ? 'findings' : `by-${view}`}-${safe}-${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}.csv`
|
|
420
|
+
}
|
|
421
|
+
|
|
353
422
|
// GET /api/vulnerabilities. Filters run server-side so the summary always
|
|
354
423
|
// describes the unfiltered scope and every surface (REST, MCP) filters alike.
|
|
355
424
|
export function useVulnerabilities(p: VulnerabilitiesParams, enabled = true) {
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { MemoryRouter, useLocation } from 'react-router-dom'
|
|
5
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
7
|
+
import { useVulnerabilities, type VulnerabilitiesResponse, type VulnerabilityWorkloadRef } from '../../api/vulnerabilities'
|
|
8
|
+
import { VulnerabilitiesView } from './VulnerabilitiesView'
|
|
9
|
+
|
|
10
|
+
vi.mock('../../api/client', async (importOriginal) => ({
|
|
11
|
+
...await importOriginal<typeof import('../../api/client')>(),
|
|
12
|
+
useCapabilities: () => ({ data: { features: {} } }),
|
|
13
|
+
useRadarFeature: () => ({ support: 'unsupported', guard: <T,>(fn: () => T) => fn() }),
|
|
14
|
+
}))
|
|
15
|
+
vi.mock('../../api/apiResources', () => ({ useAPIResources: () => ({ data: [{ group: 'aquasecurity.github.io', name: 'vulnerabilityreports' }] }) }))
|
|
16
|
+
vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { context: 'test', clusterName: 'test', state: 'connected' } }) }))
|
|
17
|
+
vi.mock('../../hooks/useDesktopDownload', () => ({ useDesktopDownload: () => undefined }))
|
|
18
|
+
vi.mock('./ChecksViewTabs', () => ({ ChecksViewTabs: () => null }))
|
|
19
|
+
vi.mock('../../api/vulnerabilities', async (importOriginal) => ({
|
|
20
|
+
...await importOriginal<typeof import('../../api/vulnerabilities')>(),
|
|
21
|
+
useVulnerabilities: vi.fn(),
|
|
22
|
+
}))
|
|
23
|
+
|
|
24
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
25
|
+
|
|
26
|
+
const zero = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0 }
|
|
27
|
+
const ref = (name: string, namespace = 'shop'): VulnerabilityWorkloadRef => ({ kind: 'Deployment', group: 'apps', namespace, name, container: 'app' })
|
|
28
|
+
const route = { via: 'LoadBalancer', namespace: 'shop', name: 'web' }
|
|
29
|
+
|
|
30
|
+
function response(view: VulnerabilitiesResponse['view'], withExposure: boolean): VulnerabilitiesResponse {
|
|
31
|
+
const base: VulnerabilitiesResponse = {
|
|
32
|
+
source: 'trivy',
|
|
33
|
+
view,
|
|
34
|
+
summary: { imagesScanned: 1, imagesClean: 0, imagesUnscanned: 0, imagesWithCritical: 1, fixableCriticalHighCves: 1, workloadsWithCriticalOrHigh: 2, workloads: 3, counts: { ...zero, critical: 1 } },
|
|
35
|
+
coverage: { complete: true, gaps: [], inactiveReports: 0 },
|
|
36
|
+
}
|
|
37
|
+
const exposed = withExposure ? { exposed: [{ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'web', routes: [route] }], exposedTotal: 1 } : {}
|
|
38
|
+
const image = {
|
|
39
|
+
id: 'img', image: 'example.com/shop/app:1', scannedAt: '2026-11-20T12:00:00Z', counts: { ...zero, critical: 1 }, fixable: { ...zero, critical: 1 },
|
|
40
|
+
matching: 1, workloads: [ref('web'), ref('worker')], workloadsTotal: 2, findings: [], findingsTotal: 1,
|
|
41
|
+
report: { kind: 'VulnerabilityReport', namespace: 'shop', name: 'r' }, ...exposed,
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
...base,
|
|
45
|
+
...(withExposure ? { exposure: { gaps: [{ code: 'user_forbidden', kinds: { count: 1, names: [{ kind: 'Ingress', group: 'networking.k8s.io' }] }, namespaces: { count: 1, names: ['hidden'] } }] } } : {}),
|
|
46
|
+
images: [image],
|
|
47
|
+
fixes: [{
|
|
48
|
+
package: 'zlib', from: ['1.0'], to: '1.1', severity: 'critical', counts: { ...zero, critical: 1 }, cves: ['CVE-1'], cvesTotal: 1, images: 1, workloads: 2,
|
|
49
|
+
affected: [{ imageId: 'img', image: image.image, installedVersions: ['1.0'], workloads: image.workloads, workloadsTotal: 2 }], ...exposed,
|
|
50
|
+
}],
|
|
51
|
+
workloads: [
|
|
52
|
+
{ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'web', counts: { ...zero, critical: 1 }, fixable: zero, containers: [], ...(withExposure ? { routes: [route, { via: 'Ingress', namespace: 'shop', name: 'web' }] } : {}) },
|
|
53
|
+
{ kind: 'Deployment', group: 'apps', namespace: 'hidden', name: 'secret', counts: { ...zero, critical: 1 }, fixable: zero, containers: [] },
|
|
54
|
+
{ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'worker', counts: { ...zero, critical: 1 }, fixable: zero, containers: [] },
|
|
55
|
+
],
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let container: HTMLDivElement
|
|
60
|
+
let root: Root
|
|
61
|
+
function Probe() {
|
|
62
|
+
return <output data-testid="location">{useLocation().search}</output>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const urlParams = () => new URLSearchParams(container.querySelector('[data-testid="location"]')!.textContent ?? '')
|
|
66
|
+
|
|
67
|
+
function render(path: string, withExposure = true) {
|
|
68
|
+
vi.mocked(useVulnerabilities).mockImplementation((p) => ({
|
|
69
|
+
data: response(p.view, withExposure), isLoading: false, isFetching: false, isPlaceholderData: false, error: null, dataUpdatedAt: 0, refetch: vi.fn(),
|
|
70
|
+
} as unknown as ReturnType<typeof useVulnerabilities>))
|
|
71
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false, enabled: false } } })
|
|
72
|
+
act(() => root.render(
|
|
73
|
+
<QueryClientProvider client={client}>
|
|
74
|
+
<MemoryRouter initialEntries={[path]}>
|
|
75
|
+
<VulnerabilitiesView namespaces={[]} onNavigateToResource={vi.fn()} />
|
|
76
|
+
<Probe />
|
|
77
|
+
</MemoryRouter>
|
|
78
|
+
</QueryClientProvider>,
|
|
79
|
+
))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const button = (label: string) => Array.from(container.querySelectorAll('button')).find((b) => b.textContent?.trim() === label)
|
|
83
|
+
const lastParams = () => vi.mocked(useVulnerabilities).mock.calls.at(-1)![0]
|
|
84
|
+
const marks = () => container.querySelectorAll('svg[aria-label^="Exposed via"]')
|
|
85
|
+
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
container = document.createElement('div')
|
|
88
|
+
document.body.appendChild(container)
|
|
89
|
+
root = createRoot(container)
|
|
90
|
+
vi.mocked(useVulnerabilities).mockReset()
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
afterEach(() => {
|
|
94
|
+
act(() => root.unmount())
|
|
95
|
+
container.remove()
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
describe('VulnerabilitiesView', () => {
|
|
99
|
+
it('opens By fix by default and sets by only for the other views', () => {
|
|
100
|
+
render('/checks/vulnerabilities')
|
|
101
|
+
expect(lastParams().view).toBe('fix')
|
|
102
|
+
expect(button('By fix')?.getAttribute('aria-pressed')).toBe('true')
|
|
103
|
+
|
|
104
|
+
act(() => button('By image')!.click())
|
|
105
|
+
expect(urlParams().get('by')).toBe('image')
|
|
106
|
+
expect(lastParams().view).toBe('image')
|
|
107
|
+
|
|
108
|
+
act(() => button('By fix')!.click())
|
|
109
|
+
expect(urlParams().has('by')).toBe(false)
|
|
110
|
+
expect(lastParams().view).toBe('fix')
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('filters to exposed rows through the URL and the request', () => {
|
|
114
|
+
render('/checks/vulnerabilities?by=cve')
|
|
115
|
+
expect(lastParams().exposed).toBe(false)
|
|
116
|
+
act(() => button('Exposed')!.click())
|
|
117
|
+
expect(urlParams().get('exposed')).toBe('1')
|
|
118
|
+
expect(lastParams().exposed).toBe(true)
|
|
119
|
+
act(() => button('Exposed')!.click())
|
|
120
|
+
expect(urlParams().has('exposed')).toBe(false)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('marks only the exposed workload when a row runs in both', () => {
|
|
124
|
+
render('/checks/vulnerabilities?by=image')
|
|
125
|
+
// Collapsed "Running in": web leads with the mark, worker has none.
|
|
126
|
+
expect(marks()).toHaveLength(1)
|
|
127
|
+
const running = marks()[0].closest('span.truncate')!
|
|
128
|
+
expect(running.textContent).toBe('web, worker')
|
|
129
|
+
act(() => container.querySelector<HTMLButtonElement>('button[aria-expanded]')!.click())
|
|
130
|
+
// Expanded: the mark sits beside web's link only.
|
|
131
|
+
const marked = Array.from(marks()).map((m) => m.closest('li')?.textContent ?? '').filter(Boolean)
|
|
132
|
+
expect(marked).toHaveLength(1)
|
|
133
|
+
expect(marked[0]).toContain('web')
|
|
134
|
+
expect(marked[0]).not.toContain('worker')
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('counts the exposed workloads beside the mark on rows that span workloads', () => {
|
|
138
|
+
render('/checks/vulnerabilities')
|
|
139
|
+
expect(container.textContent).toContain('1 exposed')
|
|
140
|
+
expect(container.textContent).not.toMatch(/\d+ of \d+ exposed/)
|
|
141
|
+
render('/checks/vulnerabilities', false)
|
|
142
|
+
expect(container.textContent).not.toContain('exposed')
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('shows the route, nothing, or Exposure unknown per workload', () => {
|
|
146
|
+
render('/checks/vulnerabilities?by=workload')
|
|
147
|
+
const rows = Array.from(container.querySelectorAll<HTMLButtonElement>('button[aria-expanded]'))
|
|
148
|
+
const cell = (i: number) => rows[i].querySelector('div.grid')!.children[2].textContent
|
|
149
|
+
expect(cell(0)).toBe('LoadBalancer shop/web and 1 more')
|
|
150
|
+
expect(cell(1)).toBe('Exposure unknown')
|
|
151
|
+
expect(cell(2)).toBe('')
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('leaves out the chip, sort hint, mark and route column when Radar reports no exposure', () => {
|
|
155
|
+
render('/checks/vulnerabilities', false)
|
|
156
|
+
expect(button('Exposed')).toBeUndefined()
|
|
157
|
+
expect(container.textContent).not.toContain('Severity, then exposure')
|
|
158
|
+
expect(marks()).toHaveLength(0)
|
|
159
|
+
|
|
160
|
+
render('/checks/vulnerabilities?by=workload', false)
|
|
161
|
+
expect(container.textContent).not.toContain('Exposed via')
|
|
162
|
+
expect(container.textContent).not.toContain('Exposure unknown')
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('keeps the sort rule in a hint, not a line above the table', () => {
|
|
166
|
+
render('/checks/vulnerabilities')
|
|
167
|
+
expect(container.textContent).toContain('Severity, then exposure')
|
|
168
|
+
expect(container.textContent).not.toContain('Sorted:')
|
|
169
|
+
expect(container.querySelector('[aria-label^="Sort: Most severe first"]')).not.toBeNull()
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
it('names the rebuild caveat on the Upgrade header instead of a line', () => {
|
|
173
|
+
render('/checks/vulnerabilities')
|
|
174
|
+
expect(container.textContent).not.toContain('Upgrading a package')
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
})
|