[8.8] [Cloud Security] Fix findings by resource filtering (#157013) (#157186)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Cloud Security] Fix findings by resource filtering
(#157013)](https://github.com/elastic/kibana/pull/157013)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Paulo
Henrique","email":"paulo.henrique@elastic.co"},"sourceCommit":{"committedDate":"2023-05-09T14:59:15Z","message":"[Cloud
Security] Fix findings by resource filtering (#157013)\n\n##
Summary\r\n\r\nThis PR re-adds the query parameter passed to the
`useResourceFindings`\r\nfetching the resources. It fixes
[this\r\nissue](https://github.com/elastic/kibana/issues/156305) that
was\r\npreventing the filter and search from working.\r\n\r\n- A unit
test was added to the `ResourceFindings` container to prevent\r\nsimilar
regressions in the future.\r\n\r\n\r\n### Screenshot\r\n\r\n<img
width=\"1275\"
alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/19270322/236866284-1f2d7aab-93b2-4639-83c8-9b574617cf2c.png\">","sha":"0676f49b873ddb4318e0390b2b346ca1ee7be1f2","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Cloud
Security","backport:prev-minor","v8.8.0","v8.9.0"],"number":157013,"url":"https://github.com/elastic/kibana/pull/157013","mergeCommit":{"message":"[Cloud
Security] Fix findings by resource filtering (#157013)\n\n##
Summary\r\n\r\nThis PR re-adds the query parameter passed to the
`useResourceFindings`\r\nfetching the resources. It fixes
[this\r\nissue](https://github.com/elastic/kibana/issues/156305) that
was\r\npreventing the filter and search from working.\r\n\r\n- A unit
test was added to the `ResourceFindings` container to prevent\r\nsimilar
regressions in the future.\r\n\r\n\r\n### Screenshot\r\n\r\n<img
width=\"1275\"
alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/19270322/236866284-1f2d7aab-93b2-4639-83c8-9b574617cf2c.png\">","sha":"0676f49b873ddb4318e0390b2b346ca1ee7be1f2"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/157013","number":157013,"mergeCommit":{"message":"[Cloud
Security] Fix findings by resource filtering (#157013)\n\n##
Summary\r\n\r\nThis PR re-adds the query parameter passed to the
`useResourceFindings`\r\nfetching the resources. It fixes
[this\r\nissue](https://github.com/elastic/kibana/issues/156305) that
was\r\npreventing the filter and search from working.\r\n\r\n- A unit
test was added to the `ResourceFindings` container to prevent\r\nsimilar
regressions in the future.\r\n\r\n\r\n### Screenshot\r\n\r\n<img
width=\"1275\"
alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/19270322/236866284-1f2d7aab-93b2-4639-83c8-9b574617cf2c.png\">","sha":"0676f49b873ddb4318e0390b2b346ca1ee7be1f2"}}]}]
BACKPORT-->

Co-authored-by: Paulo Henrique <paulo.henrique@elastic.co>
This commit is contained in:
Kibana Machine 2023-05-09 21:39:59 -04:00 committed by GitHub
parent c791371015
commit 27c63e9ce3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,50 @@
/*
* 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 { TestProvider } from '../../../../test/test_provider';
import { useResourceFindings } from './use_resource_findings';
import { FindingsBaseProps } from '../../../../common/types';
import { ResourceFindings } from './resource_findings_container';
jest.mock('./use_resource_findings', () => ({
useResourceFindings: jest.fn().mockReturnValue({
data: undefined,
error: false,
}),
}));
describe('<ResourceFindings />', () => {
it('should fetch resources with the correct parameters', async () => {
const props: FindingsBaseProps = {
dataView: {} as any,
};
render(
<TestProvider>
<ResourceFindings {...props} />
</TestProvider>
);
expect(useResourceFindings).toHaveBeenNthCalledWith(1, {
enabled: true,
query: {
bool: {
filter: [],
must: [],
must_not: [],
should: [],
},
},
resourceId: 'undefined',
sort: {
direction: 'asc',
field: 'result.evaluation',
},
});
});
});

View file

@ -98,6 +98,7 @@ export const ResourceFindings = ({ dataView }: FindingsBaseProps) => {
const {
pageIndex,
sort,
query,
queryError,
pageSize,
setTableOptions,
@ -117,6 +118,7 @@ export const ResourceFindings = ({ dataView }: FindingsBaseProps) => {
sort,
resourceId: decodedResourceId,
enabled: !queryError,
query,
});
const error = resourceFindings.error || queryError;