diff --git a/x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/service.ts b/x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/service.ts index 143426226eec8..e57e164f9a0f6 100644 --- a/x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/service.ts +++ b/x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/service.ts @@ -129,11 +129,16 @@ export async function updateOneHostIsolationExceptionItem( body: JSON.stringify(entry), }); } -export async function getHostIsolationExceptionSummary( - http: HttpStart -): Promise { +export async function getHostIsolationExceptionSummary({ + http, + filter, +}: { + http: HttpStart; + filter?: string; +}): Promise { return http.get(`${EXCEPTION_LIST_URL}/summary`, { query: { + filter, list_id: ENDPOINT_HOST_ISOLATION_EXCEPTIONS_LIST_ID, namespace_type: 'agnostic', }, diff --git a/x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/hooks.ts b/x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/hooks.ts index 05422adda6e9f..c0ea53af44a76 100644 --- a/x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/hooks.ts +++ b/x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/hooks.ts @@ -66,7 +66,7 @@ export function useCanSeeHostIsolationExceptionsMenu(): boolean { useEffect(() => { async function checkIfHasExceptions() { try { - const summary = await getHostIsolationExceptionSummary(http); + const summary = await getHostIsolationExceptionSummary({ http }); if (summary?.total > 0) { setCanSeeMenu(true); } diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_host_isolation_exceptions_card.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_host_isolation_exceptions_card.tsx index 286047d804ebf..251a7fc0bc33d 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_host_isolation_exceptions_card.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_host_isolation_exceptions_card.tsx @@ -41,7 +41,7 @@ export const FleetHostIsolationExceptionsCard = memo { try { - const summary = await getHostIsolationExceptionSummary(http); + const summary = await getHostIsolationExceptionSummary({ http }); if (isMounted.current) { setStats(summary); } diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_integration_host_isolation_exceptions_card.test.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_integration_host_isolation_exceptions_card.test.tsx index 495ec395b10a8..3d66a39f8a940 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_integration_host_isolation_exceptions_card.test.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_integration_host_isolation_exceptions_card.test.tsx @@ -10,13 +10,13 @@ import React from 'react'; import uuid from 'uuid'; import { createAppRootMockRenderer } from '../../../../../../../common/mock/endpoint'; import { useUserPrivileges } from '../../../../../../../common/components/user_privileges'; -import { getHostIsolationExceptionItems } from '../../../../../host_isolation_exceptions/service'; +import { getHostIsolationExceptionSummary } from '../../../../../host_isolation_exceptions/service'; import { FleetIntegrationHostIsolationExceptionsCard } from './fleet_integration_host_isolation_exceptions_card'; jest.mock('../../../../../host_isolation_exceptions/service'); jest.mock('../../../../../../../common/components/user_privileges'); -const getHostIsolationExceptionItemsMock = getHostIsolationExceptionItems as jest.Mock; +const getHostIsolationExceptionSummaryMock = getHostIsolationExceptionSummary as jest.Mock; const useUserPrivilegesMock = useUserPrivileges as jest.Mock; @@ -29,7 +29,7 @@ describe('Fleet host isolation exceptions card filters card', () => { ); }; afterEach(() => { - getHostIsolationExceptionItemsMock.mockReset(); + getHostIsolationExceptionSummaryMock.mockReset(); }); describe('With canIsolateHost privileges', () => { beforeEach(() => { @@ -41,17 +41,18 @@ describe('Fleet host isolation exceptions card filters card', () => { }); it('should call the API and render the card correctly', async () => { - getHostIsolationExceptionItemsMock.mockResolvedValue({ + getHostIsolationExceptionSummaryMock.mockResolvedValue({ + linux: 5, + macos: 5, total: 5, + windows: 5, }); const renderResult = renderComponent(); await waitFor(() => { - expect(getHostIsolationExceptionItemsMock).toHaveBeenCalledWith({ + expect(getHostIsolationExceptionSummaryMock).toHaveBeenCalledWith({ http: mockedContext.coreStart.http, filter: `(exception-list-agnostic.attributes.tags:"policy:${policyId}" OR exception-list-agnostic.attributes.tags:"policy:all")`, - page: 1, - perPage: 1, }); }); @@ -71,13 +72,16 @@ describe('Fleet host isolation exceptions card filters card', () => { }); it('should not render the card if there are no exceptions associated', async () => { - getHostIsolationExceptionItemsMock.mockResolvedValue({ + getHostIsolationExceptionSummaryMock.mockResolvedValue({ + linux: 0, + macos: 0, total: 0, + windows: 0, }); const renderResult = renderComponent(); await waitFor(() => { - expect(getHostIsolationExceptionItemsMock).toHaveBeenCalled(); + expect(getHostIsolationExceptionSummaryMock).toHaveBeenCalled(); }); expect( @@ -86,13 +90,16 @@ describe('Fleet host isolation exceptions card filters card', () => { }); it('should render the card if there are exceptions associated', async () => { - getHostIsolationExceptionItemsMock.mockResolvedValue({ + getHostIsolationExceptionSummaryMock.mockResolvedValue({ + linux: 1, + macos: 1, total: 1, + windows: 1, }); const renderResult = renderComponent(); await waitFor(() => { - expect(getHostIsolationExceptionItemsMock).toHaveBeenCalled(); + expect(getHostIsolationExceptionSummaryMock).toHaveBeenCalled(); }); expect( diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_integration_host_isolation_exceptions_card.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_integration_host_isolation_exceptions_card.tsx index 0eca6968cdd83..c30541f76fbe6 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_integration_host_isolation_exceptions_card.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_integration_host_isolation_exceptions_card.tsx @@ -19,7 +19,7 @@ import { import { useAppUrl, useHttp, useToasts } from '../../../../../../../common/lib/kibana'; import { getPolicyHostIsolationExceptionsPath } from '../../../../../../common/routing'; import { parsePoliciesToKQL } from '../../../../../../common/utils'; -import { getHostIsolationExceptionItems } from '../../../../../host_isolation_exceptions/service'; +import { getHostIsolationExceptionSummary } from '../../../../../host_isolation_exceptions/service'; import { ExceptionItemsSummary } from './exception_items_summary'; import { LinkWithIcon } from './link_with_icon'; import { StyledEuiFlexItem } from './styled_components'; @@ -86,20 +86,12 @@ export const FleetIntegrationHostIsolationExceptionsCard = memo<{ isMounted.current = true; const fetchStats = async () => { try { - const summary = await getHostIsolationExceptionItems({ + const summary = await getHostIsolationExceptionSummary({ http, - perPage: 1, - page: 1, filter: parsePoliciesToKQL([policyId, 'all']), }); if (isMounted.current) { - setStats({ - total: summary.total, - // the following properties are not relevant for this specific card - windows: 0, - linux: 0, - macos: 0, - }); + setStats(summary); } } catch (error) { if (isMounted.current) { diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_trusted_apps_card.test.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_trusted_apps_card.test.tsx index dec30f36869ac..f1ab47b2ea425 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_trusted_apps_card.test.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_trusted_apps_card.test.tsx @@ -114,7 +114,7 @@ describe('Fleet trusted apps card', () => { it('should render correctly with policyId', async () => { TrustedAppsHttpServiceMock.mockImplementationOnce(() => { return { - getTrustedAppsList: () => () => promise, + getTrustedAppsSummary: () => () => promise, }; }); const component = await renderComponent({ policyId: 'policy-1' });