From 114571d3ff715a52c1288f9bec9eb71a1beec85d Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 16 Oct 2024 23:12:46 +1100 Subject: [PATCH] [8.x] [SecuritySolution] Fix schedule risk engine callout when engine is installed but disabled (#196496) (#196525) # Backport This will backport the following commits from `main` to `8.x`: - [[SecuritySolution] Fix schedule risk engine callout when engine is installed but disabled (#196496)](https://github.com/elastic/kibana/pull/196496) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Pablo Machado --- .../schedule_risk_engine_callout.test.tsx | 28 +++++++++++++++---- .../schedule_risk_engine_callout.tsx | 6 +++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/components/schedule_risk_engine_callout.test.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/components/schedule_risk_engine_callout.test.tsx index 0ce75c714f89f..fa22892f21db8 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/components/schedule_risk_engine_callout.test.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/components/schedule_risk_engine_callout.test.tsx @@ -8,6 +8,7 @@ import React from 'react'; import { render, fireEvent, waitFor } from '@testing-library/react'; import { TestProviders } from '../../../../common/mock'; import { ScheduleRiskEngineCallout } from './schedule_risk_engine_callout'; +import { RiskEngineStatusEnum } from '../../../../../common/api/entity_analytics'; const oneHourFromNow = () => { const date = new Date(); @@ -48,7 +49,7 @@ describe('ScheduleRiskEngineCallout', () => { mockUseRiskEngineStatus.mockReturnValue({ data: { isNewRiskScoreModuleInstalled: true, - + risk_engine_status: RiskEngineStatusEnum.ENABLED, risk_engine_task_status: { status: 'idle', runAt: oneHourFromNow().toISOString(), @@ -70,7 +71,7 @@ describe('ScheduleRiskEngineCallout', () => { mockUseRiskEngineStatus.mockReturnValue({ data: { isNewRiskScoreModuleInstalled: true, - + risk_engine_status: RiskEngineStatusEnum.ENABLED, risk_engine_task_status: { status: 'running', runAt: oneHourFromNow().toISOString(), @@ -89,7 +90,7 @@ describe('ScheduleRiskEngineCallout', () => { mockUseRiskEngineStatus.mockReturnValue({ data: { isNewRiskScoreModuleInstalled: true, - + risk_engine_status: RiskEngineStatusEnum.ENABLED, risk_engine_task_status: { status: 'idle', runAt: new Date().toISOString(), // past date @@ -110,7 +111,7 @@ describe('ScheduleRiskEngineCallout', () => { mockUseRiskEngineStatus.mockReturnValueOnce({ data: { isNewRiskScoreModuleInstalled: true, - + risk_engine_status: RiskEngineStatusEnum.ENABLED, risk_engine_task_status: { status: 'idle', runAt: oneHourFromNow(), @@ -127,7 +128,7 @@ describe('ScheduleRiskEngineCallout', () => { mockUseRiskEngineStatus.mockReturnValueOnce({ data: { isNewRiskScoreModuleInstalled: true, - + risk_engine_status: RiskEngineStatusEnum.ENABLED, risk_engine_task_status: { status: 'idle', runAt: thirtyMinutesFromNow(), @@ -143,7 +144,7 @@ describe('ScheduleRiskEngineCallout', () => { mockUseRiskEngineStatus.mockReturnValue({ data: { isNewRiskScoreModuleInstalled: true, - + risk_engine_status: RiskEngineStatusEnum.ENABLED, risk_engine_task_status: { status: 'idle', runAt: new Date().toISOString(), // past date @@ -173,4 +174,19 @@ describe('ScheduleRiskEngineCallout', () => { expect(queryByTestId('risk-engine-callout')).toBeNull(); }); + + it('should not show the callout if the risk engine is disabled', () => { + mockUseRiskEngineStatus.mockReturnValue({ + data: { + isNewRiskScoreModuleInstalled: true, + risk_engine_status: RiskEngineStatusEnum.DISABLED, + }, + }); + + const { queryByTestId } = render(, { + wrapper: TestProviders, + }); + + expect(queryByTestId('risk-engine-callout')).toBeNull(); + }); }); diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/components/schedule_risk_engine_callout.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/components/schedule_risk_engine_callout.tsx index 2e8722cd20005..432e03c231a4d 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/components/schedule_risk_engine_callout.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/asset_criticality_file_uploader/components/schedule_risk_engine_callout.tsx @@ -16,6 +16,7 @@ import React, { useCallback, useMemo } from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; +import { RiskEngineStatusEnum } from '../../../../../common/api/entity_analytics'; import { useAppToasts } from '../../../../common/hooks/use_app_toasts'; import { formatTimeFromNow } from '../helpers'; import { useScheduleNowRiskEngineMutation } from '../../../api/hooks/use_schedule_now_risk_engine_mutation'; @@ -76,7 +77,10 @@ export const ScheduleRiskEngineCallout: React.FC = () => { scheduleRiskEngineMutation(); }, [scheduleRiskEngineMutation]); - if (!riskEngineStatus?.isNewRiskScoreModuleInstalled) { + if ( + !riskEngineStatus?.isNewRiskScoreModuleInstalled || + riskEngineStatus?.risk_engine_status !== RiskEngineStatusEnum.ENABLED + ) { return null; }