From 9f1cc37c7f44480bb972292d01a65d006bf1b56b Mon Sep 17 00:00:00 2001 From: animehart Date: Tue, 20 Aug 2024 01:00:30 -0700 Subject: [PATCH] pr comments --- .github/CODEOWNERS | 1 + .../kbn-cloud-security-posture/index.ts | 2 +- .../src/utils/utils.ts | 5 ++-- .../kbn-cloud-security-posture/type.ts | 2 -- .../entity_details/host_right/content.tsx | 10 ++++--- .../host_details_insight_accordion.cy.ts | 27 ++++++++++--------- .../screens/hosts/flyout_host_panel.ts | 6 ----- .../cypress/tasks/api_calls/rules.ts | 13 --------- 8 files changed, 25 insertions(+), 41 deletions(-) rename x-pack/test/security_solution_cypress/cypress/e2e/{investigations/alerts/expandable_flyout => cloud_security_posture/misconfiguration}/host_details_insight_accordion.cy.ts (52%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 691ffde591204d..7884277ae7d104 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1428,6 +1428,7 @@ x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts @elastic/kib /x-pack/test/security_solution_cypress/cypress/screens/common @elastic/security-detections-response @elastic/security-threat-hunting /x-pack/test/security_solution_cypress/cypress/support @elastic/security-detections-response @elastic/security-threat-hunting /x-pack/test/security_solution_cypress/cypress/urls @elastic/security-threat-hunting-investigations @elastic/security-detection-engine +/x-pack/test/security_solution_cypress/cypress/e2e/cloud_security_posture @elastic/kibana-cloud-security-posture /x-pack/plugins/security_solution/common/ecs @elastic/security-threat-hunting-investigations /x-pack/plugins/security_solution/common/test @elastic/security-detections-response @elastic/security-threat-hunting diff --git a/x-pack/packages/kbn-cloud-security-posture/index.ts b/x-pack/packages/kbn-cloud-security-posture/index.ts index b49d6e83bd79e5..e038f3f7c3d261 100644 --- a/x-pack/packages/kbn-cloud-security-posture/index.ts +++ b/x-pack/packages/kbn-cloud-security-posture/index.ts @@ -12,5 +12,5 @@ export { useCspSetupStatusApi } from './src/hooks/use_csp_setup_status_api'; export { getAggregationCount, getFindingsCountAggQuery, - isAllIndicesEmpty, + isIndexWithDocsAvailable, } from './src/utils/utils'; diff --git a/x-pack/packages/kbn-cloud-security-posture/src/utils/utils.ts b/x-pack/packages/kbn-cloud-security-posture/src/utils/utils.ts index 37aaa33b38c50d..528209d9bd9618 100644 --- a/x-pack/packages/kbn-cloud-security-posture/src/utils/utils.ts +++ b/x-pack/packages/kbn-cloud-security-posture/src/utils/utils.ts @@ -49,7 +49,6 @@ export const getMisconfigurationAggregationCount = ( }; }; -export const isAllIndicesEmpty = (indices: Array) => { - const notEmptyIndices = indices.find((indice) => indice?.status !== 'empty'); - return notEmptyIndices ? false : true; +export const isIndexWithDocsAvailable = (indices: Array) => { + return indices.some((indice) => indice?.status !== 'empty'); }; diff --git a/x-pack/packages/kbn-cloud-security-posture/type.ts b/x-pack/packages/kbn-cloud-security-posture/type.ts index 917c2621579ae8..5a5f507effe96b 100644 --- a/x-pack/packages/kbn-cloud-security-posture/type.ts +++ b/x-pack/packages/kbn-cloud-security-posture/type.ts @@ -29,7 +29,6 @@ export interface FindingsBaseEsQuery { } export interface CspClientPluginStartDeps { - // required data: DataPublicPluginStart; dataViews: DataViewsServicePublic; dataViewFieldEditor: IndexPatternFieldEditorStart; @@ -44,6 +43,5 @@ export interface CspClientPluginStartDeps { share: SharePluginStart; storage: Storage; - // optional usageCollection?: UsageCollectionStart; } diff --git a/x-pack/plugins/security_solution/public/flyout/entity_details/host_right/content.tsx b/x-pack/plugins/security_solution/public/flyout/entity_details/host_right/content.tsx index ccefa85ff1fd04..8af3c7c78f6f6a 100644 --- a/x-pack/plugins/security_solution/public/flyout/entity_details/host_right/content.tsx +++ b/x-pack/plugins/security_solution/public/flyout/entity_details/host_right/content.tsx @@ -5,9 +5,9 @@ * 2.0. */ -import React from 'react'; +import React, { useMemo } from 'react'; import { EuiHorizontalRule } from '@elastic/eui'; -import { useCspSetupStatusApi, isAllIndicesEmpty } from '@kbn/cloud-security-posture'; +import { useCspSetupStatusApi, isIndexWithDocsAvailable } from '@kbn/cloud-security-posture'; import { AssetCriticalityAccordion } from '../../../entity_analytics/components/asset_criticality/asset_criticality_selector'; import { FlyoutRiskSummary } from '../../../entity_analytics/components/risk_summary_flyout/risk_summary'; import type { RiskScoreState } from '../../../entity_analytics/api/hooks/use_risk_score'; @@ -49,7 +49,9 @@ export const HostPanelContent = ({ const getSetupStatus = useCspSetupStatusApi({ refetchInterval: 10000, }); - const cspAllIndicesEmpty = isAllIndicesEmpty(getSetupStatus.data?.indicesDetails || []); + const notEmptyIndices = useMemo(() => { + return isIndexWithDocsAvailable(getSetupStatus.data?.indicesDetails || []); + }, [getSetupStatus.data?.indicesDetails]); return ( {riskScoreState.isModuleEnabled && riskScoreState.data?.length !== 0 && ( @@ -77,7 +79,7 @@ export const HostPanelContent = ({ queryId={HOST_PANEL_OBSERVED_HOST_QUERY_ID} /> - {!cspAllIndicesEmpty && } + {notEmptyIndices && } ); }; diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/investigations/alerts/expandable_flyout/host_details_insight_accordion.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/cloud_security_posture/misconfiguration/host_details_insight_accordion.cy.ts similarity index 52% rename from x-pack/test/security_solution_cypress/cypress/e2e/investigations/alerts/expandable_flyout/host_details_insight_accordion.cy.ts rename to x-pack/test/security_solution_cypress/cypress/e2e/cloud_security_posture/misconfiguration/host_details_insight_accordion.cy.ts index a7901860a6509f..d18eeea37c5cdd 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/investigations/alerts/expandable_flyout/host_details_insight_accordion.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/cloud_security_posture/misconfiguration/host_details_insight_accordion.cy.ts @@ -4,19 +4,22 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ +import { getDataTestSubjectSelector } from '../../../helpers/common'; +import { expandFirstAlertHostFlyout } from '../../../tasks/asset_criticality/common'; +import { deleteAlertsAndRules } from '../../../tasks/api_calls/common'; +import { login } from '../../../tasks/login'; +import { visit } from '../../../tasks/navigation'; +import { createRule } from '../../../tasks/api_calls/rules'; +import { getNewRule } from '../../../objects/rule'; +import { ALERTS_URL } from '../../../urls/navigation'; +import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule'; -import { - HOST_INSIGHT_MISCONFIGURATION, - HOST_INSIGHT_MISCONFIGURATION_TITLE, -} from '../../../../screens/hosts/flyout_host_panel'; -import { expandFirstAlertHostFlyout } from '../../../../tasks/asset_criticality/common'; -import { deleteAlertsAndRules } from '../../../../tasks/api_calls/common'; -import { login } from '../../../../tasks/login'; -import { visit } from '../../../../tasks/navigation'; -import { createRule } from '../../../../tasks/api_calls/rules'; -import { getNewRule } from '../../../../objects/rule'; -import { ALERTS_URL } from '../../../../urls/navigation'; -import { waitForAlertsToPopulate } from '../../../../tasks/create_new_rule'; +const HOST_INSIGHT_MISCONFIGURATION = getDataTestSubjectSelector( + 'securitySolutionFlyoutInsightsMisconfigurationsLeftSection' +); +const HOST_INSIGHT_MISCONFIGURATION_TITLE = getDataTestSubjectSelector( + 'securitySolutionFlyoutInsightsMisconfigurationsTitleText' +); describe('Alert Host details expandable flyout', { tags: ['@ess', '@serverless'] }, () => { beforeEach(() => { diff --git a/x-pack/test/security_solution_cypress/cypress/screens/hosts/flyout_host_panel.ts b/x-pack/test/security_solution_cypress/cypress/screens/hosts/flyout_host_panel.ts index 27adb5ec72dc8c..e3173bd17d5831 100644 --- a/x-pack/test/security_solution_cypress/cypress/screens/hosts/flyout_host_panel.ts +++ b/x-pack/test/security_solution_cypress/cypress/screens/hosts/flyout_host_panel.ts @@ -10,9 +10,3 @@ import { getDataTestSubjectSelector } from '../../helpers/common'; export const HOST_PANEL_HEADER = getDataTestSubjectSelector('host-panel-header'); export const HOST_PREVIEW_PANEL_FOOTER = getDataTestSubjectSelector('host-preview-footer'); export const OPEN_HOST_FLYOUT_LINK = getDataTestSubjectSelector('open-host-flyout'); -export const HOST_INSIGHT_MISCONFIGURATION = getDataTestSubjectSelector( - 'securitySolutionFlyoutInsightsMisconfigurationsLeftSection' -); -export const HOST_INSIGHT_MISCONFIGURATION_TITLE = getDataTestSubjectSelector( - 'securitySolutionFlyoutInsightsMisconfigurationsTitleText' -); diff --git a/x-pack/test/security_solution_cypress/cypress/tasks/api_calls/rules.ts b/x-pack/test/security_solution_cypress/cypress/tasks/api_calls/rules.ts index be63a66f9a5317..008fc92bd02248 100644 --- a/x-pack/test/security_solution_cypress/cypress/tasks/api_calls/rules.ts +++ b/x-pack/test/security_solution_cypress/cypress/tasks/api_calls/rules.ts @@ -138,16 +138,3 @@ export const enableRules = ({ names, ids }: EnableRulesParameters): Cypress.Chai failOnStatusCode: false, }); }; - -export const createFindings = ( - rule: RuleCreateProps -): Cypress.Chainable> => { - return cy.currentSpace().then((spaceId) => - rootRequest({ - method: 'POST', - url: spaceId ? getSpaceUrl(spaceId, DETECTION_ENGINE_RULES_URL) : DETECTION_ENGINE_RULES_URL, - body: rule, - failOnStatusCode: false, - }) - ); -};