-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Cloud Security] [Posture Dashboard] Update links to the findings page with groupBy option #176463
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import { AccountsEvaluatedWidget } from './accounts_evaluated_widget'; | ||
import { BenchmarkData } from '../../common/types_old'; | ||
import { TestProvider } from '../test/test_provider'; | ||
|
||
const mockNavToFindings = jest.fn(); | ||
jest.mock('../common/hooks/use_navigate_findings', () => ({ | ||
useNavigateFindings: () => mockNavToFindings, | ||
})); | ||
|
||
describe('AccountsEvaluatedWidget', () => { | ||
const benchmarkAssets = [ | ||
{ meta: { benchmarkId: 'cis_aws', assetCount: 10 } }, | ||
{ meta: { benchmarkId: 'cis_k8s', assetCount: 20 } }, | ||
] as BenchmarkData[]; | ||
|
||
it('renders the component with benchmark data correctly', () => { | ||
const { getByText } = render( | ||
<TestProvider> | ||
<AccountsEvaluatedWidget benchmarkAssets={benchmarkAssets} benchmarkAbbreviateAbove={999} /> | ||
</TestProvider> | ||
); | ||
|
||
expect(getByText('10')).toBeInTheDocument(); | ||
expect(getByText('20')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls navToFindingsByCloudProvider when a benchmark with provider is clicked', () => { | ||
const { getByText } = render( | ||
<TestProvider> | ||
<AccountsEvaluatedWidget benchmarkAssets={benchmarkAssets} benchmarkAbbreviateAbove={999} /> | ||
</TestProvider> | ||
); | ||
|
||
fireEvent.click(getByText('10')); | ||
|
||
expect(mockNavToFindings).toHaveBeenCalledWith( | ||
{ | ||
'cloud.provider': 'aws', | ||
}, | ||
['cloud.account.name'] | ||
); | ||
}); | ||
|
||
it('calls navToFindingsByCisBenchmark when a benchmark with benchmarkId is clicked', () => { | ||
const { getByText } = render( | ||
<TestProvider> | ||
<AccountsEvaluatedWidget benchmarkAssets={benchmarkAssets} benchmarkAbbreviateAbove={999} /> | ||
</TestProvider> | ||
); | ||
|
||
fireEvent.click(getByText('20')); | ||
|
||
expect(mockNavToFindings).toHaveBeenCalledWith( | ||
{ | ||
'rule.benchmark.id': 'cis_k8s', | ||
}, | ||
['orchestrator.cluster.name'] | ||
); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,38 +7,40 @@ | |
import React from 'react'; | ||
import { EuiFlexGroup, EuiFlexItem, useEuiTheme } from '@elastic/eui'; | ||
import { css } from '@emotion/react'; | ||
import { CLOUD_PROVIDERS, getBenchmarkApplicableTo } from '../../common/utils/helpers'; | ||
import { CIS_AWS, CIS_GCP, CIS_AZURE, CIS_K8S, CIS_EKS } from '../../common/constants'; | ||
import { CISBenchmarkIcon } from './cis_benchmark_icon'; | ||
import { CompactFormattedNumber } from './compact_formatted_number'; | ||
import { useNavigateFindings } from '../common/hooks/use_navigate_findings'; | ||
import { BenchmarkData } from '../../common/types_old'; | ||
import { FINDINGS_GROUPING_OPTIONS } from '../common/constants'; | ||
|
||
// order in array will determine order of appearance in the dashboard | ||
const benchmarks = [ | ||
{ | ||
type: CIS_AWS, | ||
name: 'Amazon Web Services (AWS)', | ||
provider: 'aws', | ||
name: getBenchmarkApplicableTo(CIS_AWS), | ||
provider: CLOUD_PROVIDERS.AWS, | ||
}, | ||
{ | ||
type: CIS_GCP, | ||
name: 'Google Cloud Platform (GCP)', | ||
provider: 'gcp', | ||
name: getBenchmarkApplicableTo(CIS_GCP), | ||
provider: CLOUD_PROVIDERS.GCP, | ||
}, | ||
{ | ||
type: CIS_AZURE, | ||
name: 'Azure', | ||
provider: 'azure', | ||
name: getBenchmarkApplicableTo(CIS_AZURE), | ||
provider: CLOUD_PROVIDERS.AZURE, | ||
}, | ||
{ | ||
type: CIS_K8S, | ||
name: 'Kubernetes', | ||
benchmarkId: 'cis_k8s', | ||
name: getBenchmarkApplicableTo(CIS_K8S), | ||
benchmarkId: CIS_K8S, | ||
}, | ||
{ | ||
type: CIS_EKS, | ||
name: 'Amazon Elastic Kubernetes Service (EKS)', | ||
benchmarkId: 'cis_eks', | ||
name: getBenchmarkApplicableTo(CIS_EKS), | ||
benchmarkId: CIS_EKS, | ||
Comment on lines
21
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i see that its not new, but can we change it so all of those uses benchmarkId to keep it consistent? not urgent |
||
}, | ||
]; | ||
|
||
|
@@ -59,11 +61,13 @@ export const AccountsEvaluatedWidget = ({ | |
const navToFindings = useNavigateFindings(); | ||
|
||
const navToFindingsByCloudProvider = (provider: string) => { | ||
navToFindings({ 'cloud.provider': provider }); | ||
navToFindings({ 'cloud.provider': provider }, [FINDINGS_GROUPING_OPTIONS.CLOUD_ACCOUNT_NAME]); | ||
}; | ||
|
||
const navToFindingsByCisBenchmark = (cisBenchmark: string) => { | ||
navToFindings({ 'rule.benchmark.id': cisBenchmark }); | ||
navToFindings({ 'rule.benchmark.id': cisBenchmark }, [ | ||
FINDINGS_GROUPING_OPTIONS.ORCHESTRATOR_CLUSTER_NAME, | ||
]); | ||
}; | ||
|
||
const benchmarkElements = benchmarks.map((benchmark) => { | ||
|
@@ -75,10 +79,10 @@ export const AccountsEvaluatedWidget = ({ | |
key={benchmark.type} | ||
onClick={() => { | ||
if (benchmark.provider) { | ||
navToFindingsByCloudProvider(benchmark.provider); | ||
return navToFindingsByCloudProvider(benchmark.provider); | ||
} | ||
if (benchmark.benchmarkId) { | ||
navToFindingsByCisBenchmark(benchmark.benchmarkId); | ||
return navToFindingsByCisBenchmark(benchmark.benchmarkId); | ||
Comment on lines
+82
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need to return here? no one takes in the value and the functions themselves do not return anything. i think this is redundant. |
||
} | ||
}} | ||
css={css` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be to read and use if this function will receive an object, not urgent since it will require some refactoring