Skip to content

Commit

Permalink
[SecuritySolution] Fix schedule risk engine callout when engine is in…
Browse files Browse the repository at this point in the history
…stalled but disabled (#196496)

## Summary

Fix the visibility of the Schedule Risk Engine Callout inside the asset
criticality bulk upload when the risk engine is disabled.
The callout should not be displayed when the risk engine is installed
but disabled.

### How to test it?
* Open Kibana - Security Solution
* Navigate to the risk engine page and install the risk engine
* On the same page, disable the risk engine
* Navigate to the asset criticality page
* Successfully upload a document
* You should see a "success" but no risk engine callout.

![Screenshot 2024-10-16 at 10 41
39](https://github.com/user-attachments/assets/5c8f078e-4588-434e-8c76-03d72b1c5a16)

### Checklist

- [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

(cherry picked from commit 1de6fb5)
  • Loading branch information
machadoum committed Oct 16, 2024
1 parent c986220 commit a2c3b7c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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
Expand All @@ -110,7 +111,7 @@ describe('ScheduleRiskEngineCallout', () => {
mockUseRiskEngineStatus.mockReturnValueOnce({
data: {
isNewRiskScoreModuleInstalled: true,

risk_engine_status: RiskEngineStatusEnum.ENABLED,
risk_engine_task_status: {
status: 'idle',
runAt: oneHourFromNow(),
Expand All @@ -127,7 +128,7 @@ describe('ScheduleRiskEngineCallout', () => {
mockUseRiskEngineStatus.mockReturnValueOnce({
data: {
isNewRiskScoreModuleInstalled: true,

risk_engine_status: RiskEngineStatusEnum.ENABLED,
risk_engine_task_status: {
status: 'idle',
runAt: thirtyMinutesFromNow(),
Expand All @@ -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
Expand Down Expand Up @@ -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(<ScheduleRiskEngineCallout />, {
wrapper: TestProviders,
});

expect(queryByTestId('risk-engine-callout')).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit a2c3b7c

Please sign in to comment.