diff --git a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_charts/cloud_posture_score_chart.tsx b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_charts/compliance_score_chart.tsx
similarity index 91%
rename from x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_charts/cloud_posture_score_chart.tsx
rename to x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_charts/compliance_score_chart.tsx
index c1b86258a46c9..c15e0ce87570f 100644
--- a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_charts/cloud_posture_score_chart.tsx
+++ b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_charts/compliance_score_chart.tsx
@@ -29,13 +29,14 @@ import {
import { FormattedDate, FormattedTime } from '@kbn/i18n-react';
import moment from 'moment';
import { i18n } from '@kbn/i18n';
+import { DASHBOARD_COMPLIANCE_SCORE_CHART } from '../test_subjects';
import { statusColors } from '../../../common/constants';
import { RULE_FAILED, RULE_PASSED } from '../../../../common/constants';
import { CompactFormattedNumber } from '../../../components/compact_formatted_number';
import type { Evaluation, PostureTrend, Stats } from '../../../../common/types';
import { useKibana } from '../../../common/hooks/use_kibana';
-interface CloudPostureScoreChartProps {
+interface ComplianceScoreChartProps {
compact?: boolean;
trend: PostureTrend[];
data: Stats;
@@ -48,7 +49,7 @@ const getPostureScorePercentage = (postureScore: number): string => `${Math.roun
const PercentageInfo = ({
compact,
postureScore,
-}: CloudPostureScoreChartProps['data'] & { compact?: CloudPostureScoreChartProps['compact'] }) => {
+}: ComplianceScoreChartProps['data'] & { compact?: ComplianceScoreChartProps['compact'] }) => {
const { euiTheme } = useEuiTheme();
const percentage = getPostureScorePercentage(postureScore);
@@ -59,6 +60,7 @@ const PercentageInfo = ({
paddingLeft: compact ? euiTheme.size.s : euiTheme.size.xs,
marginBottom: compact ? euiTheme.size.s : 'none',
}}
+ data-test-subj={DASHBOARD_COMPLIANCE_SCORE_CHART.COMPLIANCE_SCORE}
>
{percentage}
@@ -140,12 +142,12 @@ const CounterLink = ({
);
};
-export const CloudPostureScoreChart = ({
+export const ComplianceScoreChart = ({
data,
trend,
onEvalCounterClick,
compact,
-}: CloudPostureScoreChartProps) => {
+}: ComplianceScoreChartProps) => {
const { euiTheme } = useEuiTheme();
return (
@@ -173,7 +175,7 @@ export const CloudPostureScoreChart = ({
color={statusColors.passed}
onClick={() => onEvalCounterClick(RULE_PASSED)}
tooltipContent={i18n.translate(
- 'xpack.csp.cloudPostureScoreChart.counterLink.passedFindingsTooltip',
+ 'xpack.csp.complianceScoreChart.counterLink.passedFindingsTooltip',
{ defaultMessage: 'Passed findings' }
)}
/>
@@ -184,7 +186,7 @@ export const CloudPostureScoreChart = ({
color={statusColors.failed}
onClick={() => onEvalCounterClick(RULE_FAILED)}
tooltipContent={i18n.translate(
- 'xpack.csp.cloudPostureScoreChart.counterLink.failedFindingsTooltip',
+ 'xpack.csp.complianceScoreChart.counterLink.failedFindingsTooltip',
{ defaultMessage: 'Failed findings' }
)}
/>
diff --git a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_dashboard.tsx b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_dashboard.tsx
index 6c75891fc62af..2dca58dfa32b4 100644
--- a/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_dashboard.tsx
+++ b/x-pack/plugins/cloud_security_posture/public/pages/compliance_dashboard/compliance_dashboard.tsx
@@ -332,6 +332,7 @@ export const ComplianceDashboard = () => {
return (
-
@@ -151,7 +152,7 @@ export const SummarySection = ({
- =>
+ retry.try(async () => {
+ log.debug('Check CSP plugin is initialized');
+ const response = await supertest
+ .get('/internal/cloud_security_posture/status?check=init')
+ .expect(200);
+ expect(response.body).to.eql({ isPluginInitialized: true });
+ log.debug('CSP plugin is initialized');
+ });
+
+ const index = {
+ remove: () => es.indices.delete({ index: LATEST_FINDINGS_INDEX, ignore_unavailable: true }),
+ add: async (findingsMock: T[]) => {
+ // await waitForPluginInitialized();
+ await Promise.all(
+ findingsMock.map((finding) =>
+ es.index({
+ index: LATEST_FINDINGS_INDEX,
+ body: finding,
+ })
+ )
+ );
+ },
+ };
+
+ const dashboard = {
+ getDashboardPageHeader: () => testSubjects.find('cloud-posture-dashboard-page-header'),
+
+ getDashboardTabs: async () => {
+ const dashboardPageHeader = await dashboard.getDashboardPageHeader();
+ return await dashboardPageHeader.findByClassName('euiTabs');
+ },
+
+ getCloudTab: async () => {
+ const tabs = await dashboard.getDashboardTabs();
+ return await tabs.findByXpath(`//span[text()="Cloud"]`);
+ },
+
+ getKubernetesTab: async () => {
+ const tabs = await dashboard.getDashboardTabs();
+ return await tabs.findByXpath(`//span[text()="Kubernetes"]`);
+ },
+
+ clickTab: async (tab: 'Cloud' | 'Kubernetes') => {
+ if (tab === 'Cloud') {
+ const cloudTab = await dashboard.getCloudTab();
+ await cloudTab.click();
+ }
+ if (tab === 'Kubernetes') {
+ const k8sTab = await dashboard.getKubernetesTab();
+ await k8sTab.click();
+ }
+ },
+
+ getIntegrationDashboardContainer: () => testSubjects.find('dashboard-container'),
+
+ // Cloud Dashboard
+
+ getCloudDashboard: async () => {
+ await dashboard.clickTab('Cloud');
+ return await testSubjects.find('cloud-dashboard-container');
+ },
+
+ getCloudSummarySection: async () => {
+ await dashboard.getCloudDashboard();
+ return await testSubjects.find('dashboard-summary-section');
+ },
+
+ getCloudComplianceScore: async () => {
+ await dashboard.getCloudSummarySection();
+ return await testSubjects.find('dashboard-summary-section-compliance-score');
+ },
+
+ // Kubernetes Dashboard
+
+ getKubernetesDashboard: async () => {
+ await dashboard.clickTab('Kubernetes');
+ return await testSubjects.find('kubernetes-dashboard-container');
+ },
+
+ getKubernetesSummarySection: async () => {
+ await dashboard.getKubernetesDashboard();
+ return await testSubjects.find('dashboard-summary-section');
+ },
+
+ getKubernetesComplianceScore: async () => {
+ await dashboard.getKubernetesSummarySection();
+ return await testSubjects.find('dashboard-summary-section-compliance-score');
+ },
+
+ getKubernetesComplianceScore2: async () => {
+ // await dashboard.getKubernetesSummarySection();
+ return await testSubjects.find('dashboard-summary-section-compliance-score');
+ },
+ };
+
+ const navigateToComplianceDashboardPage = async () => {
+ await PageObjects.common.navigateToUrl(
+ 'securitySolution', // Defined in Security Solution plugin
+ 'cloud_security_posture/dashboard',
+ { shouldUseHashForSubUrl: false }
+ );
+ };
+
+ return {
+ waitForPluginInitialized,
+ navigateToComplianceDashboardPage,
+ dashboard,
+ index,
+ };
+}
diff --git a/x-pack/test/cloud_security_posture_functional/page_objects/index.ts b/x-pack/test/cloud_security_posture_functional/page_objects/index.ts
index e5738873edc51..26aacd8cca997 100644
--- a/x-pack/test/cloud_security_posture_functional/page_objects/index.ts
+++ b/x-pack/test/cloud_security_posture_functional/page_objects/index.ts
@@ -7,8 +7,10 @@
import { pageObjects as xpackFunctionalPageObjects } from '../../functional/page_objects';
import { FindingsPageProvider } from './findings_page';
+import { CspDashboardPageProvider } from './csp_dashboard_page';
export const pageObjects = {
...xpackFunctionalPageObjects,
findings: FindingsPageProvider,
+ cloudPostureDashboard: CspDashboardPageProvider,
};
diff --git a/x-pack/test/cloud_security_posture_functional/pages/compliance_dashboard.ts b/x-pack/test/cloud_security_posture_functional/pages/compliance_dashboard.ts
new file mode 100644
index 0000000000000..a4cb0ab0e4458
--- /dev/null
+++ b/x-pack/test/cloud_security_posture_functional/pages/compliance_dashboard.ts
@@ -0,0 +1,69 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0; you may not use this file except in compliance with the Elastic License
+ * 2.0.
+ */
+
+import expect from '@kbn/expect';
+import Chance from 'chance';
+import type { FtrProviderContext } from '../ftr_provider_context';
+
+// eslint-disable-next-line import/no-default-export
+export default function ({ getPageObjects, getService }: FtrProviderContext) {
+ const retry = getService('retry');
+ const pageObjects = getPageObjects(['common', 'cloudPostureDashboard']);
+ const chance = new Chance();
+
+ const data = [
+ {
+ '@timestamp': new Date().toISOString(),
+ resource: { id: chance.guid(), name: `kubelet`, sub_type: 'lower case sub type' },
+ result: { evaluation: 'failed' },
+ rule: {
+ name: 'Upper case rule name',
+ section: 'Upper case section',
+ benchmark: {
+ id: 'cis_k8s',
+ posture_type: 'kspm',
+ },
+ },
+ cluster_id: 'Upper case cluster id',
+ },
+ ];
+
+ describe('Cloud Posture Dashboard Page', () => {
+ let cspDashboard: typeof pageObjects.cloudPostureDashboard;
+ let dashboard: typeof pageObjects.cloudPostureDashboard.dashboard;
+
+ before(async () => {
+ cspDashboard = pageObjects.cloudPostureDashboard;
+ dashboard = pageObjects.cloudPostureDashboard.dashboard;
+ await cspDashboard.waitForPluginInitialized();
+
+ await cspDashboard.index.add(data);
+ await cspDashboard.navigateToComplianceDashboardPage();
+ await retry.waitFor(
+ 'Cloud posture integration dashboard to be displayed',
+ async () => !!dashboard.getIntegrationDashboardContainer()
+ );
+ });
+
+ after(async () => {
+ await cspDashboard.index.remove();
+ });
+
+ describe('Kubernetes Dashboard', () => {
+ it('display the dashboard header', async () => {
+ const dashboardHeader = await dashboard.getDashboardPageHeader();
+ expect((await dashboardHeader.getVisibleText()) === 'Cloud Security Posture').to.be(true);
+ });
+
+ it('displays accurate summary compliance score', async () => {
+ const scoreElement = await dashboard.getKubernetesComplianceScore();
+
+ expect((await scoreElement.getVisibleText()) === '0%').to.be(true);
+ });
+ });
+ });
+}
diff --git a/x-pack/test/cloud_security_posture_functional/pages/index.ts b/x-pack/test/cloud_security_posture_functional/pages/index.ts
index 80e96b8b17ce9..7566afda0501a 100644
--- a/x-pack/test/cloud_security_posture_functional/pages/index.ts
+++ b/x-pack/test/cloud_security_posture_functional/pages/index.ts
@@ -11,5 +11,6 @@ import { FtrProviderContext } from '../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('Cloud Security Posture', function () {
loadTestFile(require.resolve('./findings'));
+ loadTestFile(require.resolve('./compliance_dashboard'));
});
}