-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cloud Security] exclude unknown findings from compliance score calcu…
…lation (#197829) ## Summary Findings from 3rd party date can have `result.evaluation: unknown`. This leads to incorrect posture/compliance score in our flows. This PR removes these findings from the score calculation and graphical representation. properly introducing `unknown` in the compliance score UX flows will be solved separately - fixes elastic/security-team#10913 ### Screenshots <img width="1473" alt="Screenshot 2024-10-25 at 14 19 03" src="https://github.com/user-attachments/assets/c69e45b0-7da1-4eb8-b83a-f895e7b7c3a4"> ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [x] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
- Loading branch information
Showing
7 changed files
with
181 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/cloud_security_posture/public/components/compliance_score_bar.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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, screen } from '@testing-library/react'; | ||
import { ComplianceScoreBar } from './compliance_score_bar'; | ||
import { | ||
COMPLIANCE_SCORE_BAR_UNKNOWN, | ||
COMPLIANCE_SCORE_BAR_PASSED, | ||
COMPLIANCE_SCORE_BAR_FAILED, | ||
} from './test_subjects'; | ||
|
||
describe('<ComplianceScoreBar />', () => { | ||
it('should display 0% compliance score with status unknown when both passed and failed are 0', () => { | ||
render(<ComplianceScoreBar totalPassed={0} totalFailed={0} />); | ||
expect(screen.getByText('0%')).toBeInTheDocument(); | ||
expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_UNKNOWN)).not.toBeNull(); | ||
expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_FAILED)).toBeNull(); | ||
expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_PASSED)).toBeNull(); | ||
}); | ||
|
||
it('should display 100% compliance score when passed is greater than 0 and failed is 0', () => { | ||
render(<ComplianceScoreBar totalPassed={10} totalFailed={0} />); | ||
expect(screen.getByText('100%')).toBeInTheDocument(); | ||
expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_PASSED)).not.toBeNull(); | ||
expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_FAILED)).toBeNull(); | ||
expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_UNKNOWN)).toBeNull(); | ||
}); | ||
|
||
it('should display 0% compliance score when passed is 0 and failed is greater than 0', () => { | ||
render(<ComplianceScoreBar totalPassed={0} totalFailed={10} />); | ||
expect(screen.getByText('0%')).toBeInTheDocument(); | ||
expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_FAILED)).not.toBeNull(); | ||
expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_PASSED)).toBeNull(); | ||
expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_UNKNOWN)).toBeNull(); | ||
}); | ||
|
||
it('should display 50% compliance score when passed is equal to failed', () => { | ||
render(<ComplianceScoreBar totalPassed={5} totalFailed={5} />); | ||
expect(screen.getByText('50%')).toBeInTheDocument(); | ||
expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_FAILED)).not.toBeNull(); | ||
expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_PASSED)).not.toBeNull(); | ||
expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_UNKNOWN)).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...sture/public/pages/configurations/latest_findings/latest_findings_group_renderer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* 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 } from '@testing-library/react'; | ||
import { useEuiTheme } from '@elastic/eui'; | ||
import { ComplianceBarComponent } from './latest_findings_group_renderer'; | ||
import { RawBucket } from '@kbn/grouping/src'; | ||
import { FindingsGroupingAggregation } from './use_grouped_findings'; | ||
import { ComplianceScoreBar } from '../../../components/compliance_score_bar'; | ||
|
||
jest.mock('@elastic/eui', () => { | ||
const actual = jest.requireActual('@elastic/eui'); | ||
return { | ||
...actual, | ||
useEuiTheme: jest.fn(), | ||
}; | ||
}); | ||
|
||
jest.mock('../../../components/compliance_score_bar', () => ({ | ||
ComplianceScoreBar: jest.fn(() => null), | ||
})); | ||
|
||
jest.mock('../../../components/cloud_security_grouping'); | ||
|
||
describe('<ComplianceBarComponent />', () => { | ||
beforeEach(() => { | ||
(useEuiTheme as jest.Mock).mockReturnValue({ euiTheme: { size: { s: 's' } } }); | ||
(ComplianceScoreBar as jest.Mock).mockClear(); | ||
}); | ||
|
||
it('renders ComplianceScoreBar with correct totalFailed and totalPassed, when total = failed+passed', () => { | ||
const bucket = { | ||
doc_count: 10, | ||
failedFindings: { | ||
doc_count: 4, | ||
}, | ||
passedFindings: { | ||
doc_count: 6, | ||
}, | ||
} as RawBucket<FindingsGroupingAggregation>; | ||
|
||
render(<ComplianceBarComponent bucket={bucket} />); | ||
|
||
expect(ComplianceScoreBar).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
totalFailed: 4, | ||
totalPassed: 6, | ||
}), | ||
{} | ||
); | ||
}); | ||
|
||
it('renders ComplianceScoreBar with correct totalFailed and totalPassed, when there are unknown findings', () => { | ||
const bucket = { | ||
doc_count: 10, | ||
failedFindings: { | ||
doc_count: 3, | ||
}, | ||
passedFindings: { | ||
doc_count: 6, | ||
}, | ||
} as RawBucket<FindingsGroupingAggregation>; | ||
|
||
render(<ComplianceBarComponent bucket={bucket} />); | ||
|
||
expect(ComplianceScoreBar).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
totalFailed: 3, | ||
totalPassed: 6, | ||
}), | ||
{} | ||
); | ||
}); | ||
|
||
it('renders ComplianceScoreBar with correct totalFailed and totalPassed, when there are no findings', () => { | ||
const bucket = { | ||
doc_count: 10, | ||
failedFindings: { | ||
doc_count: 0, | ||
}, | ||
passedFindings: { | ||
doc_count: 0, | ||
}, | ||
} as RawBucket<FindingsGroupingAggregation>; | ||
|
||
render(<ComplianceBarComponent bucket={bucket} />); | ||
|
||
expect(ComplianceScoreBar).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
totalFailed: 0, | ||
totalPassed: 0, | ||
}), | ||
{} | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters