Skip to content

Commit

Permalink
[Cloud Security] Add sanity UI tests for ESS deployments (#187328)
Browse files Browse the repository at this point in the history
## Summary

This PR adds sanity UI tests for all main components related to CSPM and
KSPM integrations (i.e., Dashboards, Benchmarks, and Findings pages).

The following is covered:
 - Dashboard - Overall functionality and appearance check
    - Accounts - Verification of correct account count
- Account panels - Ensuring functionality and appearance of account
panels (AWS, GCP, Azure).
      - Verification of non-null values
      - Aggregation data panel
    - Navigation links - Confirmation of proper navigation links
- Findings
   - Query + Grouping by
   - Data grid manipulations (pagination, sort)
- Rules
   - Benchmark (Count > 0 for evaluation and compliance)
  • Loading branch information
gurevichdmitry committed Jul 9, 2024
1 parent 5df3971 commit 43fca86
Show file tree
Hide file tree
Showing 7 changed files with 436 additions and 83 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 { FtrProviderContext } from '../ftr_provider_context';

// eslint-disable-next-line import/no-default-export
export default ({ getPageObjects, getService }: FtrProviderContext) => {
const pageObjects = getPageObjects(['common', 'benchmark']);

describe('Benchmark Page - Sanity Tests', function () {
this.tags(['cloud_security_posture_ui_sanity']);
let benchmark: typeof pageObjects.benchmark;

before(async () => {
benchmark = pageObjects.benchmark;
await benchmark.navigateToBenchnmarkPage();
await benchmark.waitForPluginInitialized();
});

it('Benchmark table exists', async () => {
expect(await benchmark.benchmarkPage.doesBenchmarkTableExists());
});

it('Benchmarks count is more than 0', async () => {
const benchmarksRows = await benchmark.benchmarkPage.getBenchmarkTableRows();
expect(benchmarksRows.length).to.be.greaterThan(0);
});

it('For each benchmark, evaluation and complience are not empty', async () => {
const benchmarksRows = await benchmark.benchmarkPage.getBenchmarkTableRows();
for (const row of benchmarksRows) {
const benchmarkName = await benchmark.benchmarkPage.getCisNameCellData(row);
const evaluated = await benchmark.benchmarkPage.getEvaluatedCellData(row);
const compliance = await benchmark.benchmarkPage.getComplianceCellData(row);
expect(await evaluated).to.not.contain(
'Add',
`The ${benchmarkName} does not have evaluated data`
);
expect(await compliance).to.not.contain(
'No',
`The ${benchmarkName} does not have compliance data`
);
}
});
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* 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 { FtrProviderContext } from '../ftr_provider_context';

// eslint-disable-next-line import/no-default-export
export default ({ getPageObjects, getService }: FtrProviderContext) => {
const retry = getService('retry');
const pageObjects = getPageObjects(['common', 'cloudPostureDashboard', 'header', 'findings']);

describe('Cloud Posture Dashboard Page - Sanity Tests', function () {
this.tags(['cloud_security_posture_ui_sanity']);
let cspDashboard: typeof pageObjects.cloudPostureDashboard;
let dashboard: typeof pageObjects.cloudPostureDashboard.dashboard;
let findings: typeof pageObjects.findings;
let TAB_TYPES: typeof pageObjects.cloudPostureDashboard.TAB_TYPES;

before(async () => {
cspDashboard = pageObjects.cloudPostureDashboard;
dashboard = pageObjects.cloudPostureDashboard.dashboard;
findings = pageObjects.findings;
TAB_TYPES = pageObjects.cloudPostureDashboard.TAB_TYPES;
await cspDashboard.waitForPluginInitialized();
await cspDashboard.navigateToComplianceDashboardPage();
await retry.waitFor(
'Cloud posture integration dashboard to be displayed',
async () => !!dashboard.getIntegrationDashboardContainer()
);
});

describe('Cloud Dashboard', () => {
it('displays compliance score greater than 40', async () => {
await pageObjects.header.waitUntilLoadingHasFinished();
const scoreElement = await dashboard.getCloudComplianceScore();
const score = parseInt((await scoreElement.getVisibleText()).replace('%', ''), 10);
expect(score).to.be.greaterThan(40);
});

it('displays all compliance scores', async () => {
const scoresElements = await dashboard.getAllCloudComplianceScores();
const scores: string[] = [];
for (const scoreElement of scoresElements) {
scores.push(await scoreElement.getVisibleText());
}
// 3 scores for each cloud provider + 1 summary score
expect(scores.length).to.be(4);
});

it('displays a number of resources evaluated greater than 1500', async () => {
const resourcesEvaluated = await dashboard.getCloudResourcesEvaluated();
const visibleText = await resourcesEvaluated.getVisibleText();
const resourcesEvaluatedCount = parseInt(visibleText.replace(/,/g, ''), 10);
expect(resourcesEvaluatedCount).greaterThan(1500);
});

it('Compliance By CIS sections have non empty values', async () => {
const complianceScoresChartPanel = await dashboard.getAllComplianceScoresByCisSection(
TAB_TYPES.CLOUD
);
expect(complianceScoresChartPanel.length).to.be.greaterThan(0);
for (const score of complianceScoresChartPanel) {
const scoreValue = await score.getVisibleText();
// Check if the score is a percentage
expect(scoreValue).to.match(/^\d+%$/);
}
});

it('Navigation to Findings page', async () => {
const findingsLinkCount = await dashboard.getFindingsLinksCount(TAB_TYPES.CLOUD);
for (let i = 0; i < findingsLinkCount; i++) {
const link = await dashboard.getFindingsLinkAtIndex(TAB_TYPES.CLOUD, i);
// for (const link of findingsLink) {
await link.click();
await pageObjects.header.waitUntilLoadingHasFinished();
const groupSelector = await findings.groupSelector();
await groupSelector.openDropDown();
await groupSelector.setValue('None');
expect(
await findings.createDataTableObject('latest_findings_table').getRowsCount()
).to.be.greaterThan(0);
await cspDashboard.navigateToComplianceDashboardPage();
await pageObjects.header.waitUntilLoadingHasFinished();
}
});
});

describe('Kubernetes Dashboard', () => {
it('displays compliance score greater than 80', async () => {
await pageObjects.header.waitUntilLoadingHasFinished();
const scoreElement = await dashboard.getKubernetesComplianceScore();
const score = parseInt((await scoreElement.getVisibleText()).replace('%', ''), 10);
expect(score).to.be.greaterThan(80);
});

it('displays a number of resources evaluated greater than 150', async () => {
const resourcesEvaluated = await dashboard.getKubernetesResourcesEvaluated();
const resourcesEvaluatedCount = parseInt(
(await resourcesEvaluated.getVisibleText()).replace(/,/g, ''),
10
);
expect(resourcesEvaluatedCount).greaterThan(150);
});

it('Compliance By CIS sections have non empty values', async () => {
const complianceScoresChartPanel = await dashboard.getAllComplianceScoresByCisSection(
'Kubernetes'
);
expect(complianceScoresChartPanel.length).to.be.greaterThan(0);
for (const score of complianceScoresChartPanel) {
const scoreValue = await score.getVisibleText();
// Check if the score is a percentage
expect(scoreValue).to.match(/^\d+%$/);
}
});

it('Navigation to Findings page', async () => {
const findingsLinkCount = await dashboard.getFindingsLinksCount(TAB_TYPES.KUBERNETES);
for (let i = 0; i < findingsLinkCount; i++) {
const link = await dashboard.getFindingsLinkAtIndex(TAB_TYPES.KUBERNETES, i);
await link.click();
await pageObjects.header.waitUntilLoadingHasFinished();
const groupSelector = await findings.groupSelector();
await groupSelector.openDropDown();
await groupSelector.setValue('None');
expect(
await findings.createDataTableObject('latest_findings_table').getRowsCount()
).to.be.greaterThan(0);
await cspDashboard.navigateToComplianceDashboardPage();
await pageObjects.header.waitUntilLoadingHasFinished();
await dashboard.getKubernetesDashboard();
}
});
});
});
};
Loading

0 comments on commit 43fca86

Please sign in to comment.