Skip to content

Commit

Permalink
[8.x] [SecuritySolution] Fix schedule risk engine callout when engine…
Browse files Browse the repository at this point in the history
… 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)](#196496)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Pablo
Machado","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-16T10:29:26Z","message":"[SecuritySolution]
Fix schedule risk engine callout when engine is installed but disabled
(#196496)\n\n## Summary\r\n\r\nFix the visibility of the Schedule Risk
Engine Callout inside the asset\r\ncriticality bulk upload when the risk
engine is disabled.\r\nThe callout should not be displayed when the risk
engine is installed\r\nbut disabled.\r\n\r\n\r\n### How to test it?\r\n*
Open Kibana - Security Solution\r\n* Navigate to the risk engine page
and install the risk engine\r\n* On the same page, disable the risk
engine\r\n* Navigate to the asset criticality page\r\n* Successfully
upload a document \r\n* You should see a \"success\" but no risk engine
callout.\r\n\r\n![Screenshot 2024-10-16 at 10
41\r\n39](https://github.com/user-attachments/assets/5c8f078e-4588-434e-8c76-03d72b1c5a16)\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"1de6fb5b639ccfe044bf388cb301e99c19890f03","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","v9.0.0","Team:
SecuritySolution","backport:prev-major","Theme:
entity_analytics","Feature:Entity Analytics","Team:Entity
Analytics"],"title":"[SecuritySolution] Fix schedule risk engine callout
when engine is installed but
disabled","number":196496,"url":"https://github.com/elastic/kibana/pull/196496","mergeCommit":{"message":"[SecuritySolution]
Fix schedule risk engine callout when engine is installed but disabled
(#196496)\n\n## Summary\r\n\r\nFix the visibility of the Schedule Risk
Engine Callout inside the asset\r\ncriticality bulk upload when the risk
engine is disabled.\r\nThe callout should not be displayed when the risk
engine is installed\r\nbut disabled.\r\n\r\n\r\n### How to test it?\r\n*
Open Kibana - Security Solution\r\n* Navigate to the risk engine page
and install the risk engine\r\n* On the same page, disable the risk
engine\r\n* Navigate to the asset criticality page\r\n* Successfully
upload a document \r\n* You should see a \"success\" but no risk engine
callout.\r\n\r\n![Screenshot 2024-10-16 at 10
41\r\n39](https://github.com/user-attachments/assets/5c8f078e-4588-434e-8c76-03d72b1c5a16)\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"1de6fb5b639ccfe044bf388cb301e99c19890f03"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196496","number":196496,"mergeCommit":{"message":"[SecuritySolution]
Fix schedule risk engine callout when engine is installed but disabled
(#196496)\n\n## Summary\r\n\r\nFix the visibility of the Schedule Risk
Engine Callout inside the asset\r\ncriticality bulk upload when the risk
engine is disabled.\r\nThe callout should not be displayed when the risk
engine is installed\r\nbut disabled.\r\n\r\n\r\n### How to test it?\r\n*
Open Kibana - Security Solution\r\n* Navigate to the risk engine page
and install the risk engine\r\n* On the same page, disable the risk
engine\r\n* Navigate to the asset criticality page\r\n* Successfully
upload a document \r\n* You should see a \"success\" but no risk engine
callout.\r\n\r\n![Screenshot 2024-10-16 at 10
41\r\n39](https://github.com/user-attachments/assets/5c8f078e-4588-434e-8c76-03d72b1c5a16)\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"1de6fb5b639ccfe044bf388cb301e99c19890f03"}}]}]
BACKPORT-->

Co-authored-by: Pablo Machado <[email protected]>
  • Loading branch information
kibanamachine and machadoum authored Oct 16, 2024
1 parent 5f86c95 commit 114571d
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 114571d

Please sign in to comment.