From f04af4533ec72c70ebda8560f33ffa1884b571b2 Mon Sep 17 00:00:00 2001 From: CAWilson94 Date: Wed, 30 Oct 2024 21:48:27 +0000 Subject: [PATCH 01/11] updated all rounding on risk scores to use custom formatter to 2DP --- .../components/entity_analytics_risk_score/columns.tsx | 3 ++- .../components/entity_analytics_risk_score/index.tsx | 2 +- .../entity_store/hooks/use_entities_list_columns.tsx | 2 +- .../components/host_risk_score_table/columns.tsx | 3 ++- .../components/user_risk_score_table/columns.tsx | 3 ++- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/columns.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/columns.tsx index e6ac30f15c5b0..9459953b6d1d0 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/columns.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/columns.tsx @@ -30,6 +30,7 @@ import { SecurityCellActionType, } from '../../../common/components/cell_actions'; import { FormattedRelativePreferenceDate } from '../../../common/components/formatted_date'; +import { formatRiskScore } from '../../common'; type HostRiskScoreColumns = Array>; @@ -128,7 +129,7 @@ export const getRiskScoreColumns = ( if (riskScore != null) { return ( - {Math.round(riskScore)} + {formatRiskScore(riskScore)} ); } diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/index.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/index.tsx index ffa1afffdf21b..b2310768ac860 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/index.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/index.tsx @@ -55,7 +55,7 @@ const EntityAnalyticsRiskScoresComponent = ({ riskEntity }: { riskEntity: RiskSc openAlertsPageWithFilters([ { title: getRiskEntityTranslation(riskEntity), - selectedOptions: [entityName], + selectedOptions: ['entityName'], fieldName: riskEntity === RiskScoreEntity.host ? 'host.name' : 'user.name', }, ]); diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx index 974a80454ee21..a12e284f731bf 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx @@ -149,7 +149,7 @@ export const useEntitiesListColumns = (): EntitiesListColumns => { if (riskScore != null) { return ( - {Math.round(riskScore)} + {formatRiskScore(riskScore)} ); } diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/host_risk_score_table/columns.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/host_risk_score_table/columns.tsx index e1509a03a9a90..ac85589736336 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/host_risk_score_table/columns.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/host_risk_score_table/columns.tsx @@ -23,6 +23,7 @@ import { RiskScoreLevel } from '../severity/common'; import { ENTITY_RISK_LEVEL } from '../risk_score/translations'; import { CELL_ACTIONS_TELEMETRY } from '../risk_score/constants'; import { FormattedRelativePreferenceDate } from '../../../common/components/formatted_date'; +import { formatRiskScore } from '../../common'; export const getHostRiskScoreColumns = ({ dispatchSeverityUpdate, @@ -82,7 +83,7 @@ export const getHostRiskScoreColumns = ({ if (riskScore != null) { return ( - {Math.round(riskScore)} + {formatRiskScore(riskScore)} ); } diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/user_risk_score_table/columns.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/user_risk_score_table/columns.tsx index 49eaf7b3cc26b..0cb7960ecabba 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/user_risk_score_table/columns.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/user_risk_score_table/columns.tsx @@ -24,6 +24,7 @@ import { UsersTableType } from '../../../explore/users/store/model'; import { ENTITY_RISK_LEVEL } from '../risk_score/translations'; import { CELL_ACTIONS_TELEMETRY } from '../risk_score/constants'; import { FormattedRelativePreferenceDate } from '../../../common/components/formatted_date'; +import { formatRiskScore } from '../../common'; export const getUserRiskScoreColumns = ({ dispatchSeverityUpdate, @@ -85,7 +86,7 @@ export const getUserRiskScoreColumns = ({ if (riskScore != null) { return ( - {Math.round(riskScore)} + {formatRiskScore(riskScore)} ); } From 847f3f9f651f73bd6e715c39f7e3290b23b6d6f4 Mon Sep 17 00:00:00 2001 From: Charlotte Alexandra Wilson Date: Thu, 31 Oct 2024 10:58:02 +0000 Subject: [PATCH 02/11] Update index.tsx amended mistake quotations in selectedOption entityName --- .../components/entity_analytics_risk_score/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/index.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/index.tsx index b2310768ac860..ffa1afffdf21b 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/index.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/index.tsx @@ -55,7 +55,7 @@ const EntityAnalyticsRiskScoresComponent = ({ riskEntity }: { riskEntity: RiskSc openAlertsPageWithFilters([ { title: getRiskEntityTranslation(riskEntity), - selectedOptions: ['entityName'], + selectedOptions: [entityName], fieldName: riskEntity === RiskScoreEntity.host ? 'host.name' : 'user.name', }, ]); From be2a037f7afcd9001d8ab1a0d47275a81230d9a7 Mon Sep 17 00:00:00 2001 From: CAWilson94 Date: Thu, 31 Oct 2024 11:00:03 +0000 Subject: [PATCH 03/11] commit import for formatRiskScore on hook use entities list column --- .../components/entity_store/hooks/use_entities_list_columns.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx index a12e284f731bf..657543092d524 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx @@ -21,6 +21,7 @@ import { type CriticalityLevels } from '../../../../../common/constants'; import { ENTITIES_LIST_TABLE_ID } from '../constants'; import { isUserEntity, sourceFieldToText } from '../helpers'; import { CRITICALITY_LEVEL_TITLE } from '../../asset_criticality/translations'; +import { formatRiskScore } from '../../../common'; export type EntitiesListColumns = [ Columns, From f23502c9623faa4b3c6c7d7e5a140ff4c2bbe690 Mon Sep 17 00:00:00 2001 From: CAWilson94 Date: Fri, 1 Nov 2024 16:34:24 +0000 Subject: [PATCH 04/11] custom field formatter for alerts risk score with helper --- .../timeline/body/renderers/constants.tsx | 1 + .../timeline/body/renderers/formatted_field.tsx | 10 +++++++++- .../body/renderers/formatted_field_helpers.tsx | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/constants.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/constants.tsx index 030005b45ac62..a51763ba61137 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/constants.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/constants.tsx @@ -21,4 +21,5 @@ export const SIGNAL_STATUS_FIELD_NAME = 'kibana.alert.workflow_status'; export const AGENT_STATUS_FIELD_NAME = 'agent.status'; export const QUARANTINED_PATH_FIELD_NAME = 'quarantined.path'; export const REASON_FIELD_NAME = 'kibana.alert.reason'; +export const RISK_SCORE = 'kibana.alert.risk_score'; export const EVENT_SUMMARY_FIELD_NAME = 'eventSummary'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx index 299bb736ec4f2..423c40effa996 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx @@ -39,12 +39,18 @@ import { IP_FIELD_TYPE, MESSAGE_FIELD_NAME, REFERENCE_URL_FIELD_NAME, + RISK_SCORE, RULE_REFERENCE_FIELD_NAME, SIGNAL_RULE_NAME_FIELD_NAME, SIGNAL_STATUS_FIELD_NAME, USER_NAME_FIELD_NAME, } from './constants'; -import { renderEventModule, RenderRuleName, renderUrl } from './formatted_field_helpers'; +import { + renderEventModule, + RenderRiskScore, + RenderRuleName, + renderUrl, +} from './formatted_field_helpers'; import { RuleStatus } from './rule_status'; import { HostName } from './host_name'; import { UserName } from './user_name'; @@ -239,6 +245,8 @@ const FormattedFieldValueComponent: React.FC<{ value={value} /> ); + } else if (fieldName === RISK_SCORE) { + return value ? : null; } else if (fieldName === EVENT_MODULE_FIELD_NAME) { return renderEventModule({ contextId, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field_helpers.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field_helpers.tsx index d41c0238ce592..1a1f8f22500cf 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field_helpers.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field_helpers.tsx @@ -12,6 +12,7 @@ import type { SyntheticEvent } from 'react'; import React, { useCallback, useMemo, useContext } from 'react'; import styled from 'styled-components'; import { useExpandableFlyoutApi } from '@kbn/expandable-flyout'; +import { formatRiskScore } from '../../../../../entity_analytics/common'; import { DefaultDraggable } from '../../../../../common/components/draggables'; import { getEmptyTagValue } from '../../../../../common/components/empty_value'; import { getRuleDetailsUrl } from '../../../../../common/components/link_to/redirect_to_detection_engine'; @@ -382,3 +383,16 @@ export const renderUrl = ({ getEmptyTagValue() ); }; + +interface RenderRiskScoreProps { + value: number | string; +} + +export const RenderRiskScore: React.FC = ({ value }) => { + return ( + + {/* Usually is a string */} + {formatRiskScore(Number(value))} + + ); +}; From a20a24b7437e890a8d3fd84e322f30ad8de64ba6 Mon Sep 17 00:00:00 2001 From: CAWilson94 Date: Tue, 5 Nov 2024 13:09:54 +0000 Subject: [PATCH 05/11] removed unused imports --- .../timeline/body/renderers/formatted_field.tsx | 14 +++++++------- .../body/renderers/formatted_field_helpers.tsx | 14 -------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx index 423c40effa996..2660b577d956a 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx @@ -13,6 +13,7 @@ import { isEmpty, isNumber } from 'lodash/fp'; import React from 'react'; import { css } from '@emotion/css'; import type { FieldSpec } from '@kbn/data-plugin/common'; +import { formatRiskScore } from '../../../../../entity_analytics/common'; import { getAgentTypeForAgentIdField } from '../../../../../common/lib/endpoint/utils/get_agent_type_for_agent_id_field'; import { ALERT_HOST_CRITICALITY, @@ -45,12 +46,7 @@ import { SIGNAL_STATUS_FIELD_NAME, USER_NAME_FIELD_NAME, } from './constants'; -import { - renderEventModule, - RenderRiskScore, - RenderRuleName, - renderUrl, -} from './formatted_field_helpers'; +import { renderEventModule, RenderRuleName, renderUrl } from './formatted_field_helpers'; import { RuleStatus } from './rule_status'; import { HostName } from './host_name'; import { UserName } from './user_name'; @@ -246,7 +242,11 @@ const FormattedFieldValueComponent: React.FC<{ /> ); } else if (fieldName === RISK_SCORE) { - return value ? : null; + return value ? ( + + {formatRiskScore(Number(value))} + + ) : null; } else if (fieldName === EVENT_MODULE_FIELD_NAME) { return renderEventModule({ contextId, diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field_helpers.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field_helpers.tsx index 1a1f8f22500cf..d41c0238ce592 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field_helpers.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field_helpers.tsx @@ -12,7 +12,6 @@ import type { SyntheticEvent } from 'react'; import React, { useCallback, useMemo, useContext } from 'react'; import styled from 'styled-components'; import { useExpandableFlyoutApi } from '@kbn/expandable-flyout'; -import { formatRiskScore } from '../../../../../entity_analytics/common'; import { DefaultDraggable } from '../../../../../common/components/draggables'; import { getEmptyTagValue } from '../../../../../common/components/empty_value'; import { getRuleDetailsUrl } from '../../../../../common/components/link_to/redirect_to_detection_engine'; @@ -383,16 +382,3 @@ export const renderUrl = ({ getEmptyTagValue() ); }; - -interface RenderRiskScoreProps { - value: number | string; -} - -export const RenderRiskScore: React.FC = ({ value }) => { - return ( - - {/* Usually is a string */} - {formatRiskScore(Number(value))} - - ); -}; From 2cdba5dc71d71ac9bcfd0529982149be907a25ff Mon Sep 17 00:00:00 2001 From: CAWilson94 Date: Tue, 5 Nov 2024 14:52:36 +0000 Subject: [PATCH 06/11] updated data-test-subj for cypress tests --- .../components/timeline/body/renderers/formatted_field.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx index 2660b577d956a..733eadc5a15ea 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx @@ -243,9 +243,7 @@ const FormattedFieldValueComponent: React.FC<{ ); } else if (fieldName === RISK_SCORE) { return value ? ( - - {formatRiskScore(Number(value))} - + {formatRiskScore(Number(value))} ) : null; } else if (fieldName === EVENT_MODULE_FIELD_NAME) { return renderEventModule({ From e53c31f79ab88284d78b0fb24a3d05f8bdfa23f7 Mon Sep 17 00:00:00 2001 From: CAWilson94 Date: Tue, 5 Nov 2024 15:20:01 +0000 Subject: [PATCH 07/11] jest test to test riskscore returns formatted value when value applied, or does not render when no value applied --- .../body/renderers/formatted_field.test.tsx | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.test.tsx index 868848acd12be..a5173e44f2524 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.test.tsx @@ -15,6 +15,7 @@ import { useMountAppended } from '../../../../../common/utils/use_mount_appended import { FormattedFieldValue } from './formatted_field'; import { HOST_NAME_FIELD_NAME } from './constants'; +import { formatRiskScore } from '../../../../../entity_analytics/common'; jest.mock('@elastic/eui', () => { const original = jest.requireActual('@elastic/eui'); @@ -285,4 +286,39 @@ describe('Events', () => { ); expect(wrapper.text()).toEqual(getEmptyValue()); }); + + test('it renders the formatted risk score when fieldName is RISK_SCORE and value is provided', () => { + const riskScoreValue = 85; + const wrapper = mount( + + + + ); + + expect( + wrapper.find(`[data-test-subj="formatted-field-kibana.alert.risk_score"]`).text() + ).toEqual(formatRiskScore(riskScoreValue)); + }); + + test('it does not render anything when fieldName is RISK_SCORE and value is not provided', () => { + const wrapper = mount( + + + + ); + + expect( + wrapper.find(`[data-test-subj="formatted-field-kibana.alert.risk_score"]`).exists() + ).toEqual(false); + }); }); From 9251942d46f714ccac92608b53d5a831f7686516 Mon Sep 17 00:00:00 2001 From: CAWilson94 Date: Wed, 6 Nov 2024 11:38:41 +0000 Subject: [PATCH 08/11] added risk score formatter to be consistent with other security screens 2dp --- .../flyout/document_details/right/components/risk_score.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/security_solution/public/flyout/document_details/right/components/risk_score.tsx b/x-pack/plugins/security_solution/public/flyout/document_details/right/components/risk_score.tsx index fba4343e97499..d7d55e96d30a9 100644 --- a/x-pack/plugins/security_solution/public/flyout/document_details/right/components/risk_score.tsx +++ b/x-pack/plugins/security_solution/public/flyout/document_details/right/components/risk_score.tsx @@ -8,6 +8,7 @@ import React, { memo } from 'react'; import { ALERT_RISK_SCORE } from '@kbn/rule-data-utils'; import { FormattedMessage } from '@kbn/i18n-react'; +import { formatRiskScore } from '../../../../entity_analytics/common'; import { AlertHeaderBlock } from './alert_header_block'; import { RISK_SCORE_TITLE_TEST_ID, RISK_SCORE_VALUE_TEST_ID } from './test_ids'; import { useDocumentDetailsContext } from '../../shared/context'; @@ -25,9 +26,9 @@ export const RiskScore = memo(() => { let alertRiskScore: string; if (typeof fieldsData === 'string') { - alertRiskScore = fieldsData; + alertRiskScore = formatRiskScore(Number(fieldsData)); } else if (Array.isArray(fieldsData) && fieldsData.length > 0) { - alertRiskScore = fieldsData[0]; + alertRiskScore = formatRiskScore(Number(fieldsData[0])); } else { return null; } From a9f10e5c856ebc61fcdabea7d02a0c9f91f21f90 Mon Sep 17 00:00:00 2001 From: CAWilson94 Date: Wed, 6 Nov 2024 16:47:02 +0000 Subject: [PATCH 09/11] remove unused import --- .../flyout/document_details/right/components/risk_score.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/security_solution/public/flyout/document_details/right/components/risk_score.tsx b/x-pack/plugins/security_solution/public/flyout/document_details/right/components/risk_score.tsx index d7d55e96d30a9..fba4343e97499 100644 --- a/x-pack/plugins/security_solution/public/flyout/document_details/right/components/risk_score.tsx +++ b/x-pack/plugins/security_solution/public/flyout/document_details/right/components/risk_score.tsx @@ -8,7 +8,6 @@ import React, { memo } from 'react'; import { ALERT_RISK_SCORE } from '@kbn/rule-data-utils'; import { FormattedMessage } from '@kbn/i18n-react'; -import { formatRiskScore } from '../../../../entity_analytics/common'; import { AlertHeaderBlock } from './alert_header_block'; import { RISK_SCORE_TITLE_TEST_ID, RISK_SCORE_VALUE_TEST_ID } from './test_ids'; import { useDocumentDetailsContext } from '../../shared/context'; @@ -26,9 +25,9 @@ export const RiskScore = memo(() => { let alertRiskScore: string; if (typeof fieldsData === 'string') { - alertRiskScore = formatRiskScore(Number(fieldsData)); + alertRiskScore = fieldsData; } else if (Array.isArray(fieldsData) && fieldsData.length > 0) { - alertRiskScore = formatRiskScore(Number(fieldsData[0])); + alertRiskScore = fieldsData[0]; } else { return null; } From 4cb404492f1086426b8c9b02bcf5fecbc2d3ae2d Mon Sep 17 00:00:00 2001 From: CAWilson94 Date: Wed, 6 Nov 2024 16:59:03 +0000 Subject: [PATCH 10/11] remove unused import --- .../timeline/body/renderers/constants.tsx | 1 - .../body/renderers/formatted_field.test.tsx | 36 ------------------- .../body/renderers/formatted_field.tsx | 6 ---- 3 files changed, 43 deletions(-) diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/constants.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/constants.tsx index a51763ba61137..030005b45ac62 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/constants.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/constants.tsx @@ -21,5 +21,4 @@ export const SIGNAL_STATUS_FIELD_NAME = 'kibana.alert.workflow_status'; export const AGENT_STATUS_FIELD_NAME = 'agent.status'; export const QUARANTINED_PATH_FIELD_NAME = 'quarantined.path'; export const REASON_FIELD_NAME = 'kibana.alert.reason'; -export const RISK_SCORE = 'kibana.alert.risk_score'; export const EVENT_SUMMARY_FIELD_NAME = 'eventSummary'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.test.tsx index a5173e44f2524..868848acd12be 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.test.tsx @@ -15,7 +15,6 @@ import { useMountAppended } from '../../../../../common/utils/use_mount_appended import { FormattedFieldValue } from './formatted_field'; import { HOST_NAME_FIELD_NAME } from './constants'; -import { formatRiskScore } from '../../../../../entity_analytics/common'; jest.mock('@elastic/eui', () => { const original = jest.requireActual('@elastic/eui'); @@ -286,39 +285,4 @@ describe('Events', () => { ); expect(wrapper.text()).toEqual(getEmptyValue()); }); - - test('it renders the formatted risk score when fieldName is RISK_SCORE and value is provided', () => { - const riskScoreValue = 85; - const wrapper = mount( - - - - ); - - expect( - wrapper.find(`[data-test-subj="formatted-field-kibana.alert.risk_score"]`).text() - ).toEqual(formatRiskScore(riskScoreValue)); - }); - - test('it does not render anything when fieldName is RISK_SCORE and value is not provided', () => { - const wrapper = mount( - - - - ); - - expect( - wrapper.find(`[data-test-subj="formatted-field-kibana.alert.risk_score"]`).exists() - ).toEqual(false); - }); }); diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx index 733eadc5a15ea..299bb736ec4f2 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/formatted_field.tsx @@ -13,7 +13,6 @@ import { isEmpty, isNumber } from 'lodash/fp'; import React from 'react'; import { css } from '@emotion/css'; import type { FieldSpec } from '@kbn/data-plugin/common'; -import { formatRiskScore } from '../../../../../entity_analytics/common'; import { getAgentTypeForAgentIdField } from '../../../../../common/lib/endpoint/utils/get_agent_type_for_agent_id_field'; import { ALERT_HOST_CRITICALITY, @@ -40,7 +39,6 @@ import { IP_FIELD_TYPE, MESSAGE_FIELD_NAME, REFERENCE_URL_FIELD_NAME, - RISK_SCORE, RULE_REFERENCE_FIELD_NAME, SIGNAL_RULE_NAME_FIELD_NAME, SIGNAL_STATUS_FIELD_NAME, @@ -241,10 +239,6 @@ const FormattedFieldValueComponent: React.FC<{ value={value} /> ); - } else if (fieldName === RISK_SCORE) { - return value ? ( - {formatRiskScore(Number(value))} - ) : null; } else if (fieldName === EVENT_MODULE_FIELD_NAME) { return renderEventModule({ contextId, From 4b4596a689d0ff1a24bbd8deb8ee2b8c881accef Mon Sep 17 00:00:00 2001 From: CAWilson94 Date: Thu, 7 Nov 2024 13:30:35 +0000 Subject: [PATCH 11/11] cypress test formatting added --- .../cypress/e2e/entity_analytics/hosts/host_risk_tab.cy.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/hosts/host_risk_tab.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/hosts/host_risk_tab.cy.ts index 2f1b4d4e9eb91..3123bd30cb450 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/hosts/host_risk_tab.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/hosts/host_risk_tab.cy.ts @@ -46,7 +46,7 @@ describe('risk tab', { tags: ['@ess'] }, () => { kqlSearch('host.name: "siem-kibana" {enter}'); cy.get(HOST_BY_RISK_TABLE_CELL).eq(4).should('have.text', 'siem-kibana'); cy.get(HOST_BY_RISK_TABLE_CELL).eq(5).should('have.text', 'Mar 10, 2021 @ 14:51:05.766'); - cy.get(HOST_BY_RISK_TABLE_CELL).eq(6).should('have.text', '21'); + cy.get(HOST_BY_RISK_TABLE_CELL).eq(6).should('have.text', '21.00'); cy.get(HOST_BY_RISK_TABLE_CELL).eq(7).should('have.text', 'Low'); }); @@ -93,7 +93,7 @@ describe('risk tab', { tags: ['@ess'] }, () => { kqlSearch('host.name: "siem-kibana" {enter}'); cy.get(HOST_BY_RISK_TABLE_CELL).eq(4).should('have.text', 'siem-kibana'); cy.get(HOST_BY_RISK_TABLE_CELL).eq(5).should('have.text', 'Mar 10, 2021 @ 14:51:05.766'); - cy.get(HOST_BY_RISK_TABLE_CELL).eq(6).should('have.text', '90'); + cy.get(HOST_BY_RISK_TABLE_CELL).eq(6).should('have.text', '90.00'); cy.get(HOST_BY_RISK_TABLE_CELL).eq(7).should('have.text', 'Critical'); });