Skip to content

Commit

Permalink
[Cloud Security] Fix data view's flaky FTR
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenIdo authored Sep 30, 2024
1 parent 26f5e14 commit 1abd347
Showing 1 changed file with 168 additions and 113 deletions.
281 changes: 168 additions & 113 deletions x-pack/test/cloud_security_posture_functional/data_views/data_views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
import expect from '@kbn/expect';
import { DataViewAttributes } from '@kbn/data-views-plugin/common';
import { CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX } from '@kbn/cloud-security-posture-common';
import { CDR_VULNERABILITIES_DATA_VIEW_ID_PREFIX } from '@kbn/cloud-security-posture-plugin/common/constants';
import { KbnClientSavedObjects } from '@kbn/test/src/kbn_client/kbn_client_saved_objects';
import { FtrProviderContext } from '../ftr_provider_context';

const TEST_SPACE = 'space-1';

const DATA_VIEW_PREFIXES = [
CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX,
CDR_VULNERABILITIES_DATA_VIEW_ID_PREFIX,
];

const getDataViewSafe = async (
soClient: KbnClientSavedObjects,
dataViewId: string,
Expand All @@ -33,6 +39,7 @@ const getDataViewSafe = async (
export default ({ getService, getPageObjects }: FtrProviderContext) => {
const kibanaServer = getService('kibanaServer');
const spacesService = getService('spaces');
const retry = getService('retry');

const pageObjects = getPageObjects([
'common',
Expand All @@ -41,15 +48,17 @@ export default ({ getService, getPageObjects }: FtrProviderContext) => {
'header',
'spaceSelector',
'cspSecurity',
'security',
]);

// FLAKY: https://github.com/elastic/kibana/issues/189854
describe.skip('Data Views', async function () {
describe('Data Views', async function () {
this.tags(['cloud_security_posture_data_views', 'cloud_security_posture_spaces']);
let cspSecurity = pageObjects.cspSecurity;
let findings: typeof pageObjects.findings;

before(async () => {
await spacesService.delete(TEST_SPACE);

cspSecurity = pageObjects.cspSecurity;
findings = pageObjects.findings;
await cspSecurity.createRoles();
Expand All @@ -67,127 +76,173 @@ export default ({ getService, getPageObjects }: FtrProviderContext) => {
});

await spacesService.delete(TEST_SPACE);
await pageObjects.security.forceLogout();
});

it('Verify data view is created once user reach the findings page - default space', async () => {
const expectedDataViewId = `${CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX}-default`;
const idDataViewExists = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
'default'
);
expect(idDataViewExists).to.be(false);

await findings.navigateToLatestVulnerabilitiesPage();
await pageObjects.header.waitUntilLoadingHasFinished();

const idDataViewExistsPostFindingsNavigation = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
'default'
);
expect(idDataViewExistsPostFindingsNavigation).to.be(true);
DATA_VIEW_PREFIXES.forEach((dataViewPrefix) => {
it('Verify data view is created once user reach the findings page - default space', async () => {
const expectedDataViewId = `${dataViewPrefix}-default`;

if (await getDataViewSafe(kibanaServer.savedObjects, expectedDataViewId, 'default')) {
await kibanaServer.savedObjects.delete({
type: 'index-pattern',
id: expectedDataViewId,
space: 'default',
});

await retry.try(async () => {
expect(
await getDataViewSafe(kibanaServer.savedObjects, expectedDataViewId, 'default')
).to.be(false);
});
}

await findings.navigateToLatestVulnerabilitiesPage();
await pageObjects.header.waitUntilLoadingHasFinished();

const idDataViewExistsPostFindingsNavigation = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
'default'
);
expect(idDataViewExistsPostFindingsNavigation).to.be(true);
});
});

it('Verify data view is created once user reach the dashboard page - default space', async () => {
const expectedDataViewId = `${CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX}-default`;
const idDataViewExists = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
'default'
);
expect(idDataViewExists).to.be(false);

const cspDashboard = pageObjects.cloudPostureDashboard;
await cspDashboard.navigateToComplianceDashboardPage();
await pageObjects.header.waitUntilLoadingHasFinished();

const idDataViewExistsPostFindingsNavigation = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
'default'
);
expect(idDataViewExistsPostFindingsNavigation).to.be(true);
DATA_VIEW_PREFIXES.forEach((dataViewPrefix) => {
it('Verify data view is created once user reach the dashboard page - default space', async () => {
const expectedDataViewId = `${dataViewPrefix}-default`;

if (await getDataViewSafe(kibanaServer.savedObjects, expectedDataViewId, 'default')) {
await kibanaServer.savedObjects.delete({
type: 'index-pattern',
id: expectedDataViewId,
space: 'default',
});

await retry.try(async () => {
expect(
await getDataViewSafe(kibanaServer.savedObjects, expectedDataViewId, 'default')
).to.be(false);
});
}

const cspDashboard = pageObjects.cloudPostureDashboard;
await cspDashboard.navigateToComplianceDashboardPage();
await pageObjects.header.waitUntilLoadingHasFinished();

const idDataViewExistsPostFindingsNavigation = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
'default'
);
expect(idDataViewExistsPostFindingsNavigation).to.be(true);
});
});

it('Verify data view is created once user reach the findings page - non default space', async () => {
await pageObjects.common.navigateToApp('home');
await spacesService.create({ id: TEST_SPACE, name: 'space_one', disabledFeatures: [] });
await pageObjects.spaceSelector.openSpacesNav();
await pageObjects.spaceSelector.clickSpaceAvatar(TEST_SPACE);
await pageObjects.spaceSelector.expectHomePage(TEST_SPACE);

const expectedDataViewId = `${CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX}-${TEST_SPACE}`;
const idDataViewExists = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
TEST_SPACE
);

expect(idDataViewExists).to.be(false);

await findings.navigateToLatestFindingsPage(TEST_SPACE);
await pageObjects.header.waitUntilLoadingHasFinished();
const idDataViewExistsPostFindingsNavigation = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
TEST_SPACE
);

expect(idDataViewExistsPostFindingsNavigation).to.be(true);
DATA_VIEW_PREFIXES.forEach((dataViewPrefix) => {
it('Verify data view is created once user reach the findings page - non default space', async () => {
await pageObjects.common.navigateToApp('home');
await spacesService.create({ id: TEST_SPACE, name: 'space_one', disabledFeatures: [] });
await pageObjects.spaceSelector.openSpacesNav();
await pageObjects.spaceSelector.clickSpaceAvatar(TEST_SPACE);
await pageObjects.spaceSelector.expectHomePage(TEST_SPACE);

const expectedDataViewId = `${dataViewPrefix}-${TEST_SPACE}`;
if (await getDataViewSafe(kibanaServer.savedObjects, expectedDataViewId, TEST_SPACE)) {
await kibanaServer.savedObjects.delete({
type: 'index-pattern',
id: expectedDataViewId,
space: TEST_SPACE,
});

await retry.try(async () => {
expect(
await getDataViewSafe(kibanaServer.savedObjects, expectedDataViewId, TEST_SPACE)
).to.be(false);
});
}

await findings.navigateToLatestFindingsPage(TEST_SPACE);
await pageObjects.header.waitUntilLoadingHasFinished();
const idDataViewExistsPostFindingsNavigation = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
TEST_SPACE
);

expect(idDataViewExistsPostFindingsNavigation).to.be(true);
});
});

it('Verify data view is created once user reach the dashboard page - non default space', async () => {
// await pageObjects.header.waitUntilLoadingHasFinished();
await pageObjects.common.navigateToApp('home');
await spacesService.create({ id: TEST_SPACE, name: 'space_one', disabledFeatures: [] });
await pageObjects.spaceSelector.openSpacesNav();
await pageObjects.spaceSelector.clickSpaceAvatar(TEST_SPACE);
await pageObjects.spaceSelector.expectHomePage(TEST_SPACE);
const expectedDataViewId = `${CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX}-${TEST_SPACE}`;
const idDataViewExists = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
TEST_SPACE
);

expect(idDataViewExists).to.be(false);

const cspDashboard = pageObjects.cloudPostureDashboard;
await cspDashboard.navigateToComplianceDashboardPage(TEST_SPACE);
await pageObjects.header.waitUntilLoadingHasFinished();
const idDataViewExistsPostFindingsNavigation = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
TEST_SPACE
);

expect(idDataViewExistsPostFindingsNavigation).to.be(true);
DATA_VIEW_PREFIXES.forEach((dataViewPrefix) => {
it('Verify data view is created once user reach the dashboard page - non default space', async () => {
await pageObjects.common.navigateToApp('home');
await spacesService.create({ id: TEST_SPACE, name: 'space_one', disabledFeatures: [] });
await pageObjects.spaceSelector.openSpacesNav();
await pageObjects.spaceSelector.clickSpaceAvatar(TEST_SPACE);
await pageObjects.spaceSelector.expectHomePage(TEST_SPACE);
const expectedDataViewId = `${dataViewPrefix}-${TEST_SPACE}`;

if (await getDataViewSafe(kibanaServer.savedObjects, expectedDataViewId, TEST_SPACE)) {
await kibanaServer.savedObjects.delete({
type: 'index-pattern',
id: expectedDataViewId,
space: TEST_SPACE,
});

await retry.try(async () => {
expect(
await getDataViewSafe(kibanaServer.savedObjects, expectedDataViewId, TEST_SPACE)
).to.be(false);
});
}

const cspDashboard = pageObjects.cloudPostureDashboard;
await cspDashboard.navigateToComplianceDashboardPage(TEST_SPACE);
await pageObjects.header.waitUntilLoadingHasFinished();
const idDataViewExistsPostFindingsNavigation = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
TEST_SPACE
);

expect(idDataViewExistsPostFindingsNavigation).to.be(true);
});
});

it('Verify data view is created once user with read permissions reach the dashboard page', async () => {
await pageObjects.common.navigateToApp('home');
await cspSecurity.logout();
await cspSecurity.login('csp_read_user');
const expectedDataViewId = `${CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX}-default`;
const idDataViewExists = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
'default'
);

expect(idDataViewExists).to.be(false);

const cspDashboard = pageObjects.cloudPostureDashboard;
await cspDashboard.navigateToComplianceDashboardPage();
await pageObjects.header.waitUntilLoadingHasFinished();
const idDataViewExistsPostFindingsNavigation = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
'default'
);

expect(idDataViewExistsPostFindingsNavigation).to.be(true);
DATA_VIEW_PREFIXES.forEach((dataViewPrefix) => {
it('Verify data view is created once user with read permissions reach the dashboard page', async () => {
await pageObjects.common.navigateToApp('home');
await cspSecurity.logout();
await cspSecurity.login('csp_read_user');
const expectedDataViewId = `${CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX}-default`;

if (await getDataViewSafe(kibanaServer.savedObjects, expectedDataViewId, 'default')) {
await kibanaServer.savedObjects.delete({
type: 'index-pattern',
id: expectedDataViewId,
space: 'default',
});

await retry.try(async () => {
expect(
await getDataViewSafe(kibanaServer.savedObjects, expectedDataViewId, 'default')
).to.be(false);
});
}

const cspDashboard = pageObjects.cloudPostureDashboard;
await cspDashboard.navigateToComplianceDashboardPage();
await pageObjects.header.waitUntilLoadingHasFinished();
const idDataViewExistsPostFindingsNavigation = await getDataViewSafe(
kibanaServer.savedObjects,
expectedDataViewId,
'default'
);

expect(idDataViewExistsPostFindingsNavigation).to.be(true);
});
});
});
};

0 comments on commit 1abd347

Please sign in to comment.