@skyhook-io/radar-app 1.22.2 → 1.23.1
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 +8 -8
- package/src/App.tsx +49 -13
- package/src/RadarApp.basename.test.tsx +177 -0
- package/src/RadarApp.settings.test.tsx +33 -0
- package/src/api/agentSandbox.ts +259 -0
- package/src/api/client.autoPromConnect.test.tsx +43 -0
- package/src/api/client.metricsRelayCheck.test.tsx +134 -0
- package/src/api/client.ts +151 -27
- package/src/api/client.updateResource.secretExpiry.test.tsx +47 -0
- package/src/api/cloudInstallDiscover.test.tsx +76 -0
- package/src/api/diagnose.ts +4 -0
- package/src/api/kagent.test.ts +82 -0
- package/src/api/kagent.ts +230 -0
- package/src/api/poll.ts +78 -0
- package/src/api/prometheusCharts.ts +5 -0
- package/src/api/radarFeatures.test.ts +9 -0
- package/src/api/radarFeatures.ts +16 -0
- package/src/api/substrateWorkspace.test.ts +72 -0
- package/src/api/substrateWorkspace.ts +1394 -0
- package/src/api/vulnerabilities.ts +207 -9
- package/src/api/workloadSource.test.tsx +315 -0
- package/src/api/workloadSource.ts +128 -12
- package/src/components/CloudConnectFlow.tsx +46 -7
- package/src/components/CloudFunnelButton.test.tsx +193 -7
- package/src/components/CloudFunnelButton.tsx +128 -32
- package/src/components/SelfManagedStart.tsx +12 -2
- package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
- package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
- package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
- package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
- package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
- package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
- package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
- package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
- package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
- package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
- package/src/components/agentsandbox/data.ts +135 -0
- package/src/components/agentsandbox/host.test.ts +27 -0
- package/src/components/agentsandbox/host.tsx +85 -0
- package/src/components/agentsandbox/labels.test.ts +42 -0
- package/src/components/agentsandbox/labels.ts +146 -0
- package/src/components/agentsandbox/listFilters.ts +85 -0
- package/src/components/agentsandbox/lists.ts +52 -0
- package/src/components/agentsandbox/routes.ts +23 -0
- package/src/components/agentsandbox/shared.tsx +321 -0
- package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
- package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
- package/src/components/agentsandbox/workspace.tsx +258 -0
- package/src/components/agentsandbox/workspaceRoute.ts +18 -0
- package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
- package/src/components/applications/ApplicationsView.tsx +156 -3
- package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
- package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
- package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
- package/src/components/audit/VulnerabilitiesView.tsx +639 -199
- package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
- package/src/components/cloudHints/CloudHintLink.tsx +29 -0
- package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
- package/src/components/cloudHints/cloudHints.test.ts +126 -0
- package/src/components/cloudHints/cloudHints.ts +131 -0
- package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
- package/src/components/cloudHints/cloudLinks.test.ts +52 -0
- package/src/components/cloudHints/cloudLinks.ts +31 -0
- package/src/components/cloudHints/hintStorage.ts +28 -0
- package/src/components/cnpg/CNPGView.tsx +4 -7
- package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
- package/src/components/diagnose/DiagnoseContext.tsx +7 -0
- package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
- package/src/components/helm/HelmDrawerRouting.test.tsx +34 -1
- package/src/components/helm/HelmReleaseDrawer.tsx +6 -4
- package/src/components/helm/HelmView.tsx +4 -3
- package/src/components/helm/ObservedHelmNotice.tsx +39 -17
- package/src/components/helm/ObservedHelmRelease.test.tsx +62 -3
- package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +18 -0
- package/src/components/helm/ObservedHelmReleaseDrawer.tsx +4 -2
- package/src/components/home/HomeAgentBlock.tsx +2 -0
- package/src/components/home/HomeView.tsx +3 -3
- package/src/components/home/MCPSetupDialog.test.tsx +9 -0
- package/src/components/home/MCPSetupDialog.tsx +6 -2
- package/src/components/home/McpCloudLine.test.tsx +162 -0
- package/src/components/home/McpCloudLine.tsx +95 -0
- package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
- package/src/components/home/mcpToolCatalog.test.ts +10 -0
- package/src/components/home/mcpToolCatalog.ts +4 -4
- package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
- package/src/components/issues/IssuesPane.render.test.tsx +36 -1
- package/src/components/issues/IssuesPane.tsx +181 -23
- package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
- package/src/components/issues/SinceLastVisitRow.tsx +71 -0
- package/src/components/issues/sinceLastVisit.test.ts +266 -0
- package/src/components/issues/sinceLastVisit.ts +439 -0
- package/src/components/issues/uncheckedSources.test.ts +8 -0
- package/src/components/issues/uncheckedSources.ts +3 -0
- package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
- package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
- package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
- package/src/components/kagent/KagentAgentSessions.tsx +124 -0
- package/src/components/kagent/KagentDetailPage.tsx +106 -0
- package/src/components/kagent/KagentLists.tsx +412 -0
- package/src/components/kagent/KagentOverview.tsx +234 -0
- package/src/components/kagent/KagentPages.tsx +690 -0
- package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
- package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
- package/src/components/kagent/KagentSidebar.test.tsx +112 -0
- package/src/components/kagent/KagentView.tsx +109 -0
- package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
- package/src/components/kagent/host.tsx +144 -0
- package/src/components/kagent/routes.ts +31 -0
- package/src/components/kagent/shared.tsx +336 -0
- package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
- package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
- package/src/components/kagent/workspace.fixtures.ts +108 -0
- package/src/components/kagent/workspaceRoute.ts +18 -0
- package/src/components/nudges/activeNudges.test.ts +39 -0
- package/src/components/nudges/activeNudges.ts +76 -0
- package/src/components/poll/OssPoll.tsx +871 -0
- package/src/components/poll/mount.test.ts +12 -0
- package/src/components/poll/pollCloud.test.ts +23 -0
- package/src/components/poll/pollCloud.ts +6 -0
- package/src/components/poll/pollDefinition.ts +93 -0
- package/src/components/poll/pollFlow.test.ts +140 -0
- package/src/components/poll/pollFlow.ts +137 -0
- package/src/components/poll/pollSender.test.ts +137 -0
- package/src/components/poll/pollSender.ts +76 -0
- package/src/components/poll/pollStorage.test.ts +53 -0
- package/src/components/poll/pollStorage.ts +77 -0
- package/src/components/poll/round.json +350 -0
- package/src/components/product-hunt/ProductHuntNotice.tsx +2 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
- package/src/components/resource/MetricsNotConnected.tsx +10 -7
- package/src/components/resource/PrometheusCharts.tsx +10 -1
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
- package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
- package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
- package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
- package/src/components/resources/ImageFilesystemModal.test.tsx +21 -1
- package/src/components/resources/ImageFilesystemModal.tsx +42 -3
- package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
- package/src/components/resources/ResourcesView.tsx +24 -11
- package/src/components/resources/renderers/PodRenderer.tsx +8 -2
- package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
- package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
- package/src/components/settings/SettingsDialog.tsx +84 -16
- package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
- package/src/components/settings/SubstrateSettings.test.tsx +131 -0
- package/src/components/settings/SubstrateSettings.tsx +544 -0
- package/src/components/settings/settings-state.test.ts +21 -3
- package/src/components/settings/settings-state.ts +13 -3
- package/src/components/share/ShareLinkButton.test.tsx +360 -0
- package/src/components/share/ShareLinkButton.tsx +391 -0
- package/src/components/share/openShareInCloud.test.ts +29 -0
- package/src/components/share/openShareInCloud.ts +10 -0
- package/src/components/share/shareLink.test.ts +129 -0
- package/src/components/share/shareLink.ts +175 -0
- package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
- package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
- package/src/components/substrate/SubstrateActorPage.tsx +384 -0
- package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
- package/src/components/substrate/SubstrateActors.tsx +612 -0
- package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
- package/src/components/substrate/SubstrateConnect.tsx +88 -0
- package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
- package/src/components/substrate/SubstrateOverview.tsx +575 -0
- package/src/components/substrate/SubstratePages.test.tsx +478 -0
- package/src/components/substrate/SubstratePool.test.tsx +462 -0
- package/src/components/substrate/SubstratePoolPage.tsx +95 -0
- package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
- package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
- package/src/components/substrate/SubstrateStateBar.tsx +63 -0
- package/src/components/substrate/SubstrateTemplates.tsx +376 -0
- package/src/components/substrate/SubstrateView.tsx +173 -0
- package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
- package/src/components/substrate/SubstrateWorkers.tsx +389 -0
- package/src/components/substrate/attention.ts +81 -0
- package/src/components/substrate/contextPin.tsx +69 -0
- package/src/components/substrate/host.tsx +83 -0
- package/src/components/substrate/kubectlTarget.test.tsx +77 -0
- package/src/components/substrate/readings.test.ts +484 -0
- package/src/components/substrate/readings.ts +997 -0
- package/src/components/substrate/routes.ts +103 -0
- package/src/components/substrate/shared.tsx +426 -0
- package/src/components/substrate/substrate.fixtures.ts +325 -0
- package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
- package/src/components/substrate/workspaceRoute.ts +23 -0
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
- package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
- package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -5
- package/src/components/traffic/TrafficGraph.test.tsx +26 -0
- package/src/components/traffic/TrafficGraph.tsx +17 -14
- package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
- package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
- package/src/components/traffic/TrafficView.tsx +26 -56
- package/src/components/traffic/trafficFilters.test.ts +61 -1
- package/src/components/traffic/trafficFilters.ts +68 -8
- package/src/components/ui/UpdateNotification.tsx +2 -0
- package/src/components/usage-data/UsageDataPrompt.tsx +2 -0
- package/src/components/velero/VeleroOverview.tsx +2 -2
- package/src/components/velero/VeleroView.tsx +3 -6
- package/src/components/vulnerabilities/columns.tsx +132 -0
- package/src/components/vulnerabilities/filters.tsx +317 -0
- package/src/components/vulnerabilities/owner.test.ts +54 -0
- package/src/components/vulnerabilities/owner.tsx +163 -0
- package/src/components/vulnerabilities/parts.test.ts +126 -12
- package/src/components/vulnerabilities/parts.tsx +612 -52
- package/src/components/vulnerabilities/traffic.test.tsx +65 -0
- package/src/components/vulnerabilities/traffic.tsx +40 -0
- package/src/components/whats-new/WhatsNew.tsx +2 -0
- package/src/components/whats-new/releaseNotes.ts +75 -1
- package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
- package/src/components/workload/WorkloadView.tsx +52 -13
- package/src/components/workspace/layout.tsx +13 -7
- package/src/components/workspace/sidebar.test.ts +48 -0
- package/src/components/workspace/sidebar.ts +73 -3
- package/src/components/workspace/table.ts +2 -1
- package/src/contexts/RegistryAccessMode.test.tsx +51 -0
- package/src/contexts/RegistryAccessMode.tsx +25 -0
- package/src/integrations/resourceHost.ts +12 -6
- package/src/integrations/resourceHosts.test.tsx +27 -1
- package/src/integrations/resourceHosts.tsx +15 -7
- package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
- package/src/integrations/sidebarWorkspaces.ts +41 -0
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.ts +7 -1
- package/src/integrations/workspaceScreens.tsx +6 -0
|
@@ -0,0 +1,318 @@
|
|
|
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, vulnerabilitiesPath, type VulnerabilitiesResponse, type VulnerabilityWorkloadRef } from '../../api/vulnerabilities'
|
|
8
|
+
import { VulnerabilitiesView } from './VulnerabilitiesView'
|
|
9
|
+
import { riskLookup } from '../vulnerabilities/parts'
|
|
10
|
+
|
|
11
|
+
vi.mock('../../api/client', async (importOriginal) => ({
|
|
12
|
+
...await importOriginal<typeof import('../../api/client')>(),
|
|
13
|
+
useCapabilities: () => ({ data: { features: {} } }),
|
|
14
|
+
useRadarFeature: () => ({ support: 'unsupported', guard: <T,>(fn: () => T) => fn() }),
|
|
15
|
+
}))
|
|
16
|
+
vi.mock('../../api/apiResources', () => ({ useAPIResources: () => ({ data: [{ group: 'aquasecurity.github.io', name: 'vulnerabilityreports' }] }) }))
|
|
17
|
+
vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { context: 'test', clusterName: 'test', state: 'connected' } }) }))
|
|
18
|
+
vi.mock('../../hooks/useDesktopDownload', () => ({ useDesktopDownload: () => undefined }))
|
|
19
|
+
vi.mock('./ChecksViewTabs', () => ({ ChecksViewTabs: () => null }))
|
|
20
|
+
vi.mock('../../api/vulnerabilities', async (importOriginal) => ({
|
|
21
|
+
...await importOriginal<typeof import('../../api/vulnerabilities')>(),
|
|
22
|
+
useVulnerabilities: vi.fn(),
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
26
|
+
|
|
27
|
+
const zero = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0 }
|
|
28
|
+
const ref = (name: string): VulnerabilityWorkloadRef => ({ kind: 'Deployment', group: 'apps', namespace: 'shop', name, container: 'app' })
|
|
29
|
+
const PRIVILEGED = 'Container "app" runs in privileged mode'
|
|
30
|
+
|
|
31
|
+
// web runs privileged and may run as root; worker may run as root and binds
|
|
32
|
+
// a host port. Settings come only for factors the page marks.
|
|
33
|
+
function response(view: VulnerabilitiesResponse['view'], withRisk: boolean, counts = { privileged: 1, hostAccess: 0, runsAsRoot: 0, mayRunAsRoot: 2, dangerousCapabilities: 0, privilegeEscalation: 0, hostPort: 1 }): VulnerabilitiesResponse {
|
|
34
|
+
const risk = withRisk
|
|
35
|
+
? {
|
|
36
|
+
podRisk: {
|
|
37
|
+
counts,
|
|
38
|
+
workloads: [
|
|
39
|
+
{ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'web', factors: ['privileged' as const, 'mayRunAsRoot' as const], settings: [{ factor: 'privileged' as const, check: 'privileged', message: PRIVILEGED }] },
|
|
40
|
+
{ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'worker', factors: ['mayRunAsRoot' as const, 'hostPort' as const], settings: [] },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
: {}
|
|
45
|
+
const riskFactors = withRisk ? { riskFactors: ['privileged' as const, 'mayRunAsRoot' as const, 'hostPort' as const] } : {}
|
|
46
|
+
return {
|
|
47
|
+
source: 'trivy',
|
|
48
|
+
view,
|
|
49
|
+
summary: { imagesScanned: 1, imagesClean: 0, imagesUnscanned: 0, imagesWithCritical: 1, fixableCriticalHighCves: 1, workloadsWithCriticalOrHigh: 2, workloads: 2, counts: { ...zero, critical: 1 } },
|
|
50
|
+
coverage: { complete: true, gaps: [], inactiveReports: 0 },
|
|
51
|
+
...risk,
|
|
52
|
+
images: [{
|
|
53
|
+
id: 'img', image: 'example.com/shop/app:1', scannedAt: '2026-11-20T12:00:00Z', counts: { ...zero, critical: 1 }, fixable: { ...zero, critical: 1 },
|
|
54
|
+
matching: 1, workloads: [ref('web'), ref('worker')], workloadsTotal: 2, findings: [], findingsTotal: 1,
|
|
55
|
+
report: { kind: 'VulnerabilityReport', namespace: 'shop', name: 'r' }, ...riskFactors,
|
|
56
|
+
}],
|
|
57
|
+
workloads: [
|
|
58
|
+
{ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'web', counts: { ...zero, critical: 1 }, fixable: zero, containers: [], ...(withRisk ? { riskFactors: ['privileged' as const, 'mayRunAsRoot' as const] } : {}) },
|
|
59
|
+
{ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'worker', counts: { ...zero, critical: 1 }, fixable: zero, containers: [], ...(withRisk ? { riskFactors: ['mayRunAsRoot' as const, 'hostPort' as const] } : {}) },
|
|
60
|
+
],
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const navigate = vi.fn()
|
|
65
|
+
let container: HTMLDivElement
|
|
66
|
+
let root: Root
|
|
67
|
+
function Probe() {
|
|
68
|
+
return <output data-testid="location">{useLocation().search}</output>
|
|
69
|
+
}
|
|
70
|
+
const urlParams = () => new URLSearchParams(container.querySelector('[data-testid="location"]')!.textContent ?? '')
|
|
71
|
+
|
|
72
|
+
function render(path: string, withRisk = true, counts?: Parameters<typeof response>[2]) {
|
|
73
|
+
vi.mocked(useVulnerabilities).mockImplementation((p) => ({
|
|
74
|
+
data: response(p.view, withRisk, counts), isLoading: false, isFetching: false, isPlaceholderData: false, error: null, dataUpdatedAt: 0, refetch: vi.fn(),
|
|
75
|
+
} as unknown as ReturnType<typeof useVulnerabilities>))
|
|
76
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false, enabled: false } } })
|
|
77
|
+
act(() => root.render(
|
|
78
|
+
<QueryClientProvider client={client}>
|
|
79
|
+
<MemoryRouter initialEntries={[path]}>
|
|
80
|
+
<VulnerabilitiesView namespaces={[]} onNavigateToResource={navigate} />
|
|
81
|
+
<Probe />
|
|
82
|
+
</MemoryRouter>
|
|
83
|
+
</QueryClientProvider>,
|
|
84
|
+
))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const moreChip = () => Array.from(container.querySelectorAll<HTMLButtonElement>('button[aria-haspopup="dialog"]')).find((b) => b.textContent?.startsWith('More filters'))
|
|
88
|
+
const seriousChip = () => Array.from(container.querySelectorAll<HTMLButtonElement>('button[aria-pressed]')).find((b) => b.textContent?.trim() === 'Serious risk')
|
|
89
|
+
const menuButton = () => container.querySelector<HTMLButtonElement>('button[aria-label="More actions"]')
|
|
90
|
+
const openMore = () => act(() => moreChip()!.click())
|
|
91
|
+
const riskLabels = () => {
|
|
92
|
+
const section = Array.from(document.body.querySelectorAll('[role="dialog"] p')).find((p) => p.textContent === 'Risk factors')?.parentElement
|
|
93
|
+
return section ? Array.from(section.querySelectorAll('label')).map((l) => l.textContent) : undefined
|
|
94
|
+
}
|
|
95
|
+
const pick = (label: string) => Array.from(document.body.querySelectorAll('[role="dialog"] label')).find((l) => l.textContent?.startsWith(label))!.querySelector<HTMLInputElement>('input[type="checkbox"]')!
|
|
96
|
+
// A table row's summary: a click anywhere on it, off its controls, toggles the row.
|
|
97
|
+
const rows = () => Array.from(container.querySelectorAll<HTMLElement>('[data-row-summary]'))
|
|
98
|
+
const toggleOf = (row: Element) => row.querySelector<HTMLButtonElement>('button[aria-expanded]:not([aria-haspopup])')!
|
|
99
|
+
// The open risk popover, and its entries: the factor's line and its why line.
|
|
100
|
+
const popover = () => Array.from(document.body.querySelectorAll<HTMLElement>('[role="dialog"][aria-label="Risky settings"]')).find((p) => !p.hasAttribute('inert'))
|
|
101
|
+
const entries = () => Array.from(popover()!.querySelectorAll('li')).map((li) => Array.from(li.children).map((c) => c.textContent))
|
|
102
|
+
const lastParams = () => vi.mocked(useVulnerabilities).mock.calls.at(-1)![0]
|
|
103
|
+
// The one risk badge in an element: its words, or none.
|
|
104
|
+
const badgesIn = (el: Element) => Array.from(el.querySelectorAll('[data-risk-badge]')).map((m) => m.textContent)
|
|
105
|
+
beforeEach(() => {
|
|
106
|
+
localStorage.clear()
|
|
107
|
+
container = document.createElement('div')
|
|
108
|
+
document.body.appendChild(container)
|
|
109
|
+
root = createRoot(container)
|
|
110
|
+
vi.mocked(useVulnerabilities).mockReset()
|
|
111
|
+
navigate.mockReset()
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
afterEach(() => {
|
|
115
|
+
act(() => root.unmount())
|
|
116
|
+
container.remove()
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
describe('risky Pod settings', () => {
|
|
120
|
+
it('filters through the risk factors checklist in More filters, a count per factor, kept in the URL', () => {
|
|
121
|
+
render('/checks/vulnerabilities?by=image&severity=critical')
|
|
122
|
+
expect(moreChip()!.textContent).toBe('More filters')
|
|
123
|
+
openMore()
|
|
124
|
+
expect(riskLabels()).toEqual(['Privileged(1)', 'Host access(0)', 'Runs as root(0)', 'May run as root(2)', 'Dangerous capabilities(0)', 'Allows privilege escalation(0)', 'Host port(1)'])
|
|
125
|
+
act(() => pick('Host port').click())
|
|
126
|
+
expect(urlParams().get('risk')).toBe('hostPort')
|
|
127
|
+
expect(urlParams().get('severity')).toBe('critical')
|
|
128
|
+
expect(lastParams()).toMatchObject({ risk: ['hostPort'], severities: ['critical'] })
|
|
129
|
+
expect(moreChip()!.textContent).toBe('More filters · 1')
|
|
130
|
+
act(() => pick('Privileged').click())
|
|
131
|
+
expect(urlParams().get('risk')).toBe('privileged,hostPort')
|
|
132
|
+
// The risk factors count as one filter.
|
|
133
|
+
expect(moreChip()!.textContent).toBe('More filters · 1')
|
|
134
|
+
act(() => pick('Fix available').click())
|
|
135
|
+
expect(moreChip()!.textContent).toBe('More filters · 2')
|
|
136
|
+
expect(container.textContent).toMatch(/1 image match/)
|
|
137
|
+
act(() => Array.from(container.querySelectorAll('button')).find((b) => b.textContent === 'Clear filters')!.click())
|
|
138
|
+
expect(urlParams().has('risk')).toBe(false)
|
|
139
|
+
expect(urlParams().get('by')).toBe('image')
|
|
140
|
+
expect(vulnerabilitiesPath({ view: 'cve', risk: ['privileged', 'hostPort'] })).toBe('/vulnerabilities?view=cve&risk=privileged%2ChostPort')
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('folds a row\'s factors into one gray badge: the most serious, and how many more', () => {
|
|
144
|
+
render('/checks/vulnerabilities?by=image')
|
|
145
|
+
const row = rows()[0]
|
|
146
|
+
expect(badgesIn(row)).toEqual(['Privileged +2'])
|
|
147
|
+
// Gray with a mark: never a status colour.
|
|
148
|
+
const badge = row.querySelector<HTMLButtonElement>('[data-risk-badge]')!
|
|
149
|
+
expect(badge.querySelector('.badge-sm')!.className).toContain('text-theme-text-secondary')
|
|
150
|
+
expect(badge.querySelector('svg')).not.toBeNull()
|
|
151
|
+
// Named for what it holds, which the "+2" only counts.
|
|
152
|
+
expect(badge.getAttribute('aria-label')).toBe('Privileged and 2 more risky settings')
|
|
153
|
+
act(() => toggleOf(row).click())
|
|
154
|
+
const items = Array.from(container.querySelectorAll('li'))
|
|
155
|
+
const web = items.find((li) => li.textContent?.startsWith('web'))!
|
|
156
|
+
const worker = items.find((li) => li.textContent?.startsWith('worker'))!
|
|
157
|
+
expect(badgesIn(web)).toEqual(['Privileged +1'])
|
|
158
|
+
expect(web.querySelector('[data-risk-badge]')!.getAttribute('aria-label')).toBe('Privileged and 1 more risky setting')
|
|
159
|
+
// Only common factors: no badge.
|
|
160
|
+
expect(badgesIn(worker)).toEqual([])
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it('opens a popover from the badge, not the row, with each factor, what was found and why', () => {
|
|
164
|
+
render('/checks/vulnerabilities?by=image')
|
|
165
|
+
const row = rows()[0]
|
|
166
|
+
const badge = row.querySelector<HTMLButtonElement>('[data-risk-badge]')!
|
|
167
|
+
expect(badge.tagName).toBe('BUTTON')
|
|
168
|
+
expect(badge.getAttribute('aria-haspopup')).toBe('dialog')
|
|
169
|
+
act(() => badge.click())
|
|
170
|
+
expect(badge.getAttribute('aria-expanded')).toBe('true')
|
|
171
|
+
expect(toggleOf(row).getAttribute('aria-expanded')).toBe('false')
|
|
172
|
+
const panel = popover()!
|
|
173
|
+
expect(document.activeElement).toBe(panel)
|
|
174
|
+
// Serious first, then the others, muted.
|
|
175
|
+
expect(entries()).toEqual([
|
|
176
|
+
['Privileged: web', 'Full access to the node if compromised'],
|
|
177
|
+
['May run as root: runAsNonRoot not set in web +1 more', 'No user set, so the image decides'],
|
|
178
|
+
// No settings come for an unselected common factor: the workload is named.
|
|
179
|
+
['Host port: worker', 'Listens directly on a node port'],
|
|
180
|
+
])
|
|
181
|
+
const lines = Array.from(panel.querySelectorAll('li')).map((li) => li.firstElementChild!.className)
|
|
182
|
+
expect(lines[0]).toContain('text-theme-text-primary')
|
|
183
|
+
expect(lines.slice(1).every((c) => c.includes('text-theme-text-secondary'))).toBe(true)
|
|
184
|
+
// Escape closes it and gives focus back to the badge.
|
|
185
|
+
act(() => { window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' })) })
|
|
186
|
+
expect(badge.getAttribute('aria-expanded')).toBe('false')
|
|
187
|
+
expect(document.activeElement).toBe(badge)
|
|
188
|
+
// So does a click outside it, while focus is in it.
|
|
189
|
+
act(() => badge.click())
|
|
190
|
+
expect(document.activeElement).toBe(popover())
|
|
191
|
+
act(() => { document.body.dispatchEvent(new MouseEvent('pointerdown', { bubbles: true })) })
|
|
192
|
+
expect(badge.getAttribute('aria-expanded')).toBe('false')
|
|
193
|
+
expect(document.activeElement).toBe(badge)
|
|
194
|
+
// A click inside it keeps it open; the badge again closes it.
|
|
195
|
+
act(() => badge.click())
|
|
196
|
+
act(() => { popover()!.querySelector('li span')!.dispatchEvent(new MouseEvent('pointerdown', { bubbles: true })) })
|
|
197
|
+
expect(badge.getAttribute('aria-expanded')).toBe('true')
|
|
198
|
+
act(() => badge.click())
|
|
199
|
+
expect(badge.getAttribute('aria-expanded')).toBe('false')
|
|
200
|
+
expect(toggleOf(row).getAttribute('aria-expanded')).toBe('false')
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
it('opens a workload the popover names, and a click in the popover never toggles the row', () => {
|
|
204
|
+
render('/checks/vulnerabilities?by=image')
|
|
205
|
+
const row = rows()[0]
|
|
206
|
+
const badge = row.querySelector<HTMLButtonElement>('[data-risk-badge]')!
|
|
207
|
+
act(() => badge.click())
|
|
208
|
+
act(() => { popover()!.querySelector('li')!.dispatchEvent(new MouseEvent('click', { bubbles: true })) })
|
|
209
|
+
expect(toggleOf(row).getAttribute('aria-expanded')).toBe('false')
|
|
210
|
+
const link = Array.from(popover()!.querySelectorAll('button')).find((b) => b.textContent === 'web')!
|
|
211
|
+
act(() => link.click())
|
|
212
|
+
expect(navigate).toHaveBeenCalledWith({ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'web' })
|
|
213
|
+
expect(badge.getAttribute('aria-expanded')).toBe('false')
|
|
214
|
+
expect(toggleOf(row).getAttribute('aria-expanded')).toBe('false')
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
it('names a workload\'s own settings in its popover, and the workload only where they say nothing', () => {
|
|
218
|
+
render('/checks/vulnerabilities?by=workload&risk=hostPort')
|
|
219
|
+
const [web, worker] = rows()
|
|
220
|
+
act(() => web.querySelector<HTMLButtonElement>('[data-risk-badge]')!.click())
|
|
221
|
+
expect(entries()).toEqual([
|
|
222
|
+
['Privileged: web', 'Full access to the node if compromised'],
|
|
223
|
+
['May run as root: runAsNonRoot not set', 'No user set, so the image decides'],
|
|
224
|
+
])
|
|
225
|
+
act(() => { window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' })) })
|
|
226
|
+
act(() => worker.querySelector<HTMLButtonElement>('[data-risk-badge]')!.click())
|
|
227
|
+
expect(entries()).toContainEqual(['Host port: worker', 'Listens directly on a node port'])
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
it('puts the risk badge after the name, not in the workloads cell', () => {
|
|
231
|
+
render('/checks/vulnerabilities?by=image')
|
|
232
|
+
const cells = rows()[0].querySelector('div.grid')!.children
|
|
233
|
+
expect(badgesIn(cells[0].firstElementChild!)).toEqual(['Privileged +2'])
|
|
234
|
+
const count = Array.from(rows()[0].querySelectorAll('span.font-mono')).find((e) => e.textContent === '2')!.closest('span.flex')!
|
|
235
|
+
expect(badgesIn(count)).toEqual([])
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('brings up the badge for a common factor once the filter selects it', () => {
|
|
239
|
+
render('/checks/vulnerabilities?by=workload&risk=hostPort')
|
|
240
|
+
expect(rows().map(badgesIn)).toEqual([['Privileged +1'], ['Host port +1']])
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
const none = { privileged: 0, hostAccess: 0, runsAsRoot: 0, mayRunAsRoot: 0, dangerousCapabilities: 0, privilegeEscalation: 0, hostPort: 0 }
|
|
244
|
+
|
|
245
|
+
it('offers no risk filter when no workload in scope has a risk factor', () => {
|
|
246
|
+
render('/checks/vulnerabilities?by=image', true, none)
|
|
247
|
+
openMore()
|
|
248
|
+
expect(riskLabels()).toBeUndefined()
|
|
249
|
+
expect(seriousChip()).toBeUndefined()
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
it('still shows the checklist a link sets with other factors, whatever the counts', () => {
|
|
253
|
+
render('/checks/vulnerabilities?by=image&risk=privileged', true, none)
|
|
254
|
+
expect(moreChip()!.textContent).toBe('More filters · 1')
|
|
255
|
+
openMore()
|
|
256
|
+
expect(pick('Privileged').checked).toBe(true)
|
|
257
|
+
expect(seriousChip()).toBeUndefined()
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
it('turns the serious factors on and off with one chip, leaving the common ones out', () => {
|
|
261
|
+
render('/checks/vulnerabilities?by=image&severity=critical&exposed=1')
|
|
262
|
+
expect(seriousChip()!.getAttribute('aria-pressed')).toBe('false')
|
|
263
|
+
act(() => seriousChip()!.click())
|
|
264
|
+
expect(urlParams().get('risk')).toBe('privileged,hostAccess,runsAsRoot')
|
|
265
|
+
expect(urlParams().get('severity')).toBe('critical')
|
|
266
|
+
expect(urlParams().get('exposed')).toBe('1')
|
|
267
|
+
expect(lastParams()).toMatchObject({ risk: ['privileged', 'hostAccess', 'runsAsRoot'] })
|
|
268
|
+
expect(seriousChip()!.getAttribute('aria-pressed')).toBe('true')
|
|
269
|
+
// Its own selection doesn't count in More filters: the chip shows it.
|
|
270
|
+
expect(moreChip()!.textContent).toBe('More filters')
|
|
271
|
+
act(() => seriousChip()!.click())
|
|
272
|
+
expect(urlParams().has('risk')).toBe(false)
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
it('is on exactly when the URL selects the serious factors and nothing else', () => {
|
|
276
|
+
render('/checks/vulnerabilities?by=image&risk=runsAsRoot,privileged,hostAccess')
|
|
277
|
+
expect(seriousChip()!.getAttribute('aria-pressed')).toBe('true')
|
|
278
|
+
openMore()
|
|
279
|
+
expect(['Privileged', 'Host access', 'Runs as root'].every((f) => pick(f).checked)).toBe(true)
|
|
280
|
+
act(() => pick('Host port').click())
|
|
281
|
+
expect(urlParams().get('risk')).toBe('privileged,hostAccess,runsAsRoot,hostPort')
|
|
282
|
+
expect(seriousChip()!.getAttribute('aria-pressed')).toBe('false')
|
|
283
|
+
// Turning it on replaces the selection with the serious factors.
|
|
284
|
+
act(() => seriousChip()!.click())
|
|
285
|
+
expect(urlParams().get('risk')).toBe('privileged,hostAccess,runsAsRoot')
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
it('shows the serious chip only when a workload has a serious factor, or the URL sets it', () => {
|
|
289
|
+
const common = { ...none, mayRunAsRoot: 2, privilegeEscalation: 2 }
|
|
290
|
+
render('/checks/vulnerabilities?by=image', true, common)
|
|
291
|
+
expect(seriousChip()).toBeUndefined()
|
|
292
|
+
act(() => root.unmount())
|
|
293
|
+
root = createRoot(container)
|
|
294
|
+
render('/checks/vulnerabilities?by=image&risk=privileged,hostAccess,runsAsRoot', true, common)
|
|
295
|
+
expect(seriousChip()!.getAttribute('aria-pressed')).toBe('true')
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
it('keeps same-named workloads of different API groups apart', () => {
|
|
299
|
+
const lookup = riskLookup({
|
|
300
|
+
counts: { privileged: 1, hostAccess: 0, runsAsRoot: 0, mayRunAsRoot: 1, dangerousCapabilities: 0, privilegeEscalation: 0, hostPort: 0 },
|
|
301
|
+
workloads: [
|
|
302
|
+
{ kind: 'Rollout', group: 'argoproj.io', namespace: 'shop', name: 'web', factors: ['privileged'], settings: [] },
|
|
303
|
+
{ kind: 'Rollout', group: 'example.com', namespace: 'shop', name: 'web', factors: ['mayRunAsRoot'], settings: [] },
|
|
304
|
+
],
|
|
305
|
+
})
|
|
306
|
+
expect(lookup.size).toBe(2)
|
|
307
|
+
expect(lookup.get('argoproj.io/Rollout/shop/web')?.factors).toEqual(['privileged'])
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
it('shows no filter or badge when Radar sends no podRisk', () => {
|
|
311
|
+
render('/checks/vulnerabilities?by=image&risk=privileged', false)
|
|
312
|
+
expect(seriousChip()).toBeUndefined()
|
|
313
|
+
openMore()
|
|
314
|
+
expect(riskLabels()).toBeUndefined()
|
|
315
|
+
expect(menuButton()).toBeNull()
|
|
316
|
+
expect(badgesIn(container)).toEqual([])
|
|
317
|
+
})
|
|
318
|
+
})
|