Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cloud Security] POC - basic ui tests for Create Environment workflow #183801

Merged
merged 17 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ disabled:
- x-pack/test/upgrade/config.ts
- test/functional/config.edge.js
- x-pack/test/functional/config.edge.js
- x-pack/test/cloud_security_posture_functional/config.cloud.ts
kfirpeled marked this conversation as resolved.
Show resolved Hide resolved

# Cypress configs, for now these are still run manually
- x-pack/test/fleet_cypress/cli_config.ts
Expand Down
Original file line number Diff line number Diff line change
@@ -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 { 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']);

describe('Cloud Posture Dashboard Page', function () {
this.tags(['cloud_security_posture_ui_sanity']);
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.navigateToComplianceDashboardPage();
await retry.waitFor(
'Cloud posture integration dashboard to be displayed',
async () => !!dashboard.getIntegrationDashboardContainer()
);
});

describe('Cloud Dashboard', () => {
it('displays accurate summary compliance score', async () => {
await pageObjects.header.waitUntilLoadingHasFinished();
const scoreElement = await dashboard.getCloudComplianceScore();
expect((await scoreElement.getVisibleText()) === '41%').to.be(true);
});

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', async () => {
const resourcesEvaluated = await dashboard.getCloudResourcesEvaluated();
const visibleText = await resourcesEvaluated.getVisibleText();
const resourcesEvaluatedCount = parseInt(visibleText.replace(/,/g, ''), 10);
expect(resourcesEvaluatedCount).greaterThan(3000);
});
});

describe('Kubernetes Dashboard', () => {
it('displays accurate summary compliance score', async () => {
await pageObjects.header.waitUntilLoadingHasFinished();
const scoreElement = await dashboard.getKubernetesComplianceScore();
expect((await scoreElement.getVisibleText()) === '83%').to.be(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More like the previous question, will the agents be installed pointing to a controlled environment that the score doesn't (or at least shouldn't) change over time? otherwise, we could perform an assertion that are more flexible:

expect(score).greaterThan(80);

The main reason is having to avoid having to update the tests in Kibana whenever these values change if the findings of the environments scanned are mutable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

});

it('displays correct number of resources evaluated', async () => {
const resourcesEvaluated = await dashboard.getKubernetesResourcesEvaluated();
expect((await resourcesEvaluated.getVisibleText()) === '199').to.be(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's ensured these numbers won't change over time? otherwise, I would recommend changing to something like the previous test leaving some room for fluctuation:

 expect(resourcesEvaluatedCount).greaterThan(150);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@opauloh, since we are deploying the same resources, the number should not change. However, the timing of findings retrieval can affect this. Therefore, I have taken your suggestion and updated the test to allow some room for fluctuation

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

// eslint-disable-next-line import/no-default-export
export default function ({ loadTestFile }: FtrProviderContext) {
describe('Cloud Security Posture', function () {
loadTestFile(require.resolve('./basic_ui_sanity'));
});
}
25 changes: 25 additions & 0 deletions x-pack/test/cloud_security_posture_functional/config.cloud.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { resolve } from 'path';
import type { FtrConfigProviderContext } from '@kbn/test';
import { pageObjects } from './page_objects';

export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const xpackFunctionalConfig = await readConfigFile(
require.resolve('../functional/config.base.js')
);
// FTR configuration for cloud testing
return {
...xpackFunctionalConfig.getAll(),
pageObjects,
testFiles: [resolve(__dirname, './cloud_tests')],
junit: {
reportName: 'X-Pack Cloud Security Posture Sanity Tests',
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,26 @@ export function CspDashboardPageProvider({ getService, getPageObjects }: FtrProv
return await testSubjects.find('dashboard-summary-section');
},

getAllCloudComplianceScores: async () => {
await dashboard.getCloudDashboard();
return await testSubjects.findAll('dashboard-summary-section-compliance-score');
},

getCloudComplianceScore: async () => {
await dashboard.getCloudSummarySection();
return await testSubjects.find('dashboard-summary-section-compliance-score');
},

getCloudResourcesEvaluatedCard: async () => {
await dashboard.getCloudDashboard();
return await testSubjects.find('dashboard-counter-card-resources-evaluated');
},

getCloudResourcesEvaluated: async () => {
const resourcesEvaluatedCard = await dashboard.getCloudResourcesEvaluatedCard();
return await resourcesEvaluatedCard.findByXpath('//div/p/span');
},

// Kubernetes Dashboard

getKubernetesDashboard: async () => {
Expand All @@ -121,6 +136,16 @@ export function CspDashboardPageProvider({ getService, getPageObjects }: FtrProv

return await testSubjects.find('dashboard-summary-section-compliance-score');
},

getKubernetesResourcesEvaluatedCard: async () => {
await dashboard.getKubernetesDashboard();
return await testSubjects.find('dashboard-counter-card-resources-evaluated');
},

getKubernetesResourcesEvaluated: async () => {
const resourcesEvaluatedCard = await dashboard.getKubernetesResourcesEvaluatedCard();
return await resourcesEvaluatedCard.findByXpath('//div/p/span');
},
};

const navigateToComplianceDashboardPage = async () => {
Expand Down