Skip to content

Commit

Permalink
Sync 8.15.0 changes (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
coutoPL authored Sep 18, 2024
1 parent b8ad596 commit 0b75e9a
Show file tree
Hide file tree
Showing 37 changed files with 666 additions and 418 deletions.
3 changes: 2 additions & 1 deletion e2e-tests/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export default defineConfig({
password: 'dev',
kibanaVersion: 'KIBANA_VERSION_NOT_SET_YET',
elasticsearchUrl: 'http://localhost:19200',
enterpriseActivationKey: 'PROVIDE_YOUR_ACTIVATION_KEY'
enterpriseActivationKey: 'PROVIDE_YOUR_ACTIVATION_KEY',
kibanaUserCredentials: "kibana:kibana"
},
video: true,
screenshotOnRunFailure: true,
Expand Down
6 changes: 4 additions & 2 deletions e2e-tests/cypress/e2e/Activation-keys.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Login } from '../support/page-objects/Login';
import { ActivationKeys } from '../support/page-objects/ActivationKeys';
import { userCredentials } from '../support/helpers';

// TODO:
describe.skip('Activation key', () => {
Expand All @@ -9,8 +10,9 @@ describe.skip('Activation key', () => {
});

afterEach(() => {
cy.post({
url: `"${Cypress.config().baseUrl}/api/ror/license?overwrite=true"`,
cy.kbnPost({
endpoint: "api/ror/license?overwrite=true",
credentials: userCredentials,
payload: { license: `${Cypress.env().enterpriseActivationKey}` }
});
});
Expand Down
85 changes: 39 additions & 46 deletions e2e-tests/cypress/e2e/Direct-kibana-request.cy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as semver from 'semver';
import { DataViews, DirectKibanaRequest, GetObject } from '../support/page-objects/DirectKibanaRequest';
import { getKibanaVersion } from '../support/helpers';
import { getKibanaVersion, userCredentials } from '../support/helpers';
import { kbnApiAdvancedClient } from '../support/helpers/KbnApiAdvancedClient';

describe('Direct kibana request', () => {
const user = 'user1:dev';

afterEach(() => {
const clearDirectKibanaRequestState = () => {
DirectKibanaRequest.deleteSavedObjects(user);
kbnApiAdvancedClient.deleteSavedObjects(user);
if (semver.gte(getKibanaVersion(), '8.0.0')) {
DirectKibanaRequest.deleteDataViews(user);
kbnApiAdvancedClient.deleteDataViews(user);
}
};

Expand All @@ -18,70 +18,63 @@ describe('Direct kibana request', () => {

it('should check direct kibana request', () => {
const verifySavedObjects = () => {
DirectKibanaRequest.deleteSavedObjects(user);
kbnApiAdvancedClient.deleteSavedObjects(user);

cy.log('Import saved objects for user1');
cy.import({
url: `${Cypress.config().baseUrl}/api/saved_objects/_import?overwrite=true`,
filename: 'cypress/fixtures/file.ndjson',
user
cy.kbnImport({
endpoint: "api/saved_objects/_import?overwrite=true",
credentials: user,
filename: 'cypress/fixtures/file.ndjson'
});

cy.log('Get imported saved objects for user1 Administrators group');
cy.getRequest({
url: DirectKibanaRequest.getObjectsUrl(),
user
}).then((result: GetObject) => {
kbnApiAdvancedClient.getSavedObjects(user).then(result => {
expect(result.saved_objects[0].id).equal('my-pattern');
expect(result.saved_objects[1].id).equal('my-dashboard');
});
})

cy.log('Get imported saved objects for admin Administrators group');
cy.getRequest({
url: DirectKibanaRequest.getObjectsUrl()
}).then((result: GetObject) => {
expect(result.saved_objects[0].id).equal('my-pattern');
expect(result.saved_objects[1].id).equal('my-dashboard');
expect(result.saved_objects).to.have.length(2);
});
kbnApiAdvancedClient
.getSavedObjects(userCredentials)
.then(result => {
expect(result.saved_objects[0].id).equal('my-pattern');
expect(result.saved_objects[1].id).equal('my-dashboard');
expect(result.saved_objects).to.have.length(2);
});

cy.log('Get imported saved objects for user1 infosec group');
cy.getRequest({
url: DirectKibanaRequest.getObjectsUrl(),
user,
header: 'x-ror-current-group: infosec_group'
}).then((result: GetObject) => {
const actual = result.saved_objects.some(
saved_object => saved_object.id === 'my-pattern' || saved_object.id === 'my-dashboard'
);
// eslint-disable-next-line no-unused-expressions
expect(actual).to.be.false;
});
kbnApiAdvancedClient.getSavedObjects(user, "infosec_group")
.then(result => {
const actual = result.saved_objects.some(
saved_object => saved_object.id === 'my-pattern' || saved_object.id === 'my-dashboard'
);
// eslint-disable-next-line no-unused-expressions
expect(actual).to.be.false;
});
};

const verifyDataViews = () => {
DirectKibanaRequest.deleteDataViews(user);
kbnApiAdvancedClient.deleteDataViews(user);
cy.log('Create data_views for user1 Administrators group');
cy.post({
url: `${Cypress.config().baseUrl}/api/data_views/data_view`,
payload: {
kbnApiAdvancedClient.createDataView(
{
data_view: {
id: 'logstash',
title: 'logstash-*',
name: 'My Logstash Data View'
}
}
});
},
user
);

cy.log('get all data_views for user1 infosec group');
cy.getRequest({
url: `${Cypress.config().baseUrl}/api/data_views`,
header: 'x-ror-current-group: infosec_group'
}).then((result: DataViews) => {
const actual = result.data_view.some(saved_object => saved_object.id === 'logstash');
// eslint-disable-next-line no-unused-expressions
expect(actual).to.be.false;
});
kbnApiAdvancedClient
.getDataViews(userCredentials, "infosec_group")
.then(result => {
const actual = result.data_view.some(saved_object => saved_object.id === 'logstash');
// eslint-disable-next-line no-unused-expressions
expect(actual).to.be.false;
});
};

verifySavedObjects();
Expand Down
43 changes: 43 additions & 0 deletions e2e-tests/cypress/e2e/Kibana-content-overwrite.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as semver from 'semver';
import { Login } from '../support/page-objects/Login';
import { StackManagement } from '../support/page-objects/StackManagement';
import { KibanaNavigation } from '../support/page-objects/KibanaNavigation';
import { getKibanaVersion } from '../support/helpers';

describe('Kibana-content-overwrite', () => {
beforeEach(() => {
Login.initialization();
});

it('should overwrite Kibana alerting content', () => {
const isAlertingOverwritePageVisible = () => {
if (semver.gte(getKibanaVersion(), '8.6.0')) {
cy.contains(
'Kibana alerting does not work with ReadonlyREST, but we are working on an even better alerting and reporting solution.'
).should('be.visible');
} else {
cy.contains(
'Kibana alerting does not work with ReadonlyREST, but we are working on an even better alerting and reporting solution.'
).should('not.exist');
}
};

if (semver.gte(getKibanaVersion(), '8.6.0')) {
if (semver.gte(getKibanaVersion(), '8.14.0')) {
StackManagement.openAlertsPage();
isAlertingOverwritePageVisible();
KibanaNavigation.openHomepage();
}
StackManagement.openRulesPage();
isAlertingOverwritePageVisible();

KibanaNavigation.openHomepage();

StackManagement.openConnectorsPage();
isAlertingOverwritePageVisible();
} else {
StackManagement.openRulesAndConnectorsPage();
isAlertingOverwritePageVisible();
}
});
});
7 changes: 3 additions & 4 deletions e2e-tests/cypress/e2e/Sanity-check-ro-kibana-access.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { RoAndRoStrictKibanaAccessAssertions } from '../support/page-objects/RoA
import roSettings from '../fixtures/roSettings.json';
import { Settings } from '../support/page-objects/Settings';
import defaultSettings from '../fixtures/defaultSettings.json';
import { kbnApiClient, KbnApiClient } from '../support/helpers/KbnApiClient';
import { userCredentials } from '../support/helpers';

describe('sanity check ro kibana access', () => {
beforeEach(() => {
Expand All @@ -11,10 +13,7 @@ describe('sanity check ro kibana access', () => {

afterEach(() => {
Settings.setSettingsData(defaultSettings);
cy.deleteRequest({
url: `${Cypress.config().baseUrl}/api/sample_data/ecommerce`,
header: 'x-ror-current-group: template_group'
});
kbnApiClient.deleteSampleData("ecommerce", userCredentials, "template_group");
});

it('should verify that everything works', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { RoAndRoStrictKibanaAccessAssertions } from '../support/page-objects/RoA
import roStrictSettings from '../fixtures/roStrictSettings.json';
import { Settings } from '../support/page-objects/Settings';
import defaultSettings from '../fixtures/defaultSettings.json';
import { kbnApiClient, KbnApiClient } from '../support/helpers/KbnApiClient';
import { userCredentials } from '../support/helpers';

describe('sanity check ro_strict kibana access', () => {
beforeEach(() => {
Expand All @@ -11,10 +13,7 @@ describe('sanity check ro_strict kibana access', () => {

afterEach(() => {
Settings.setSettingsData(defaultSettings);
cy.deleteRequest({
url: `${Cypress.config().baseUrl}/api/sample_data/ecommerce`,
header: 'x-ror-current-group: template_group'
});
kbnApiClient.deleteSampleData("ecommerce", userCredentials, "template_group");
});

it('should verify that everything works', () => {
Expand Down
72 changes: 13 additions & 59 deletions e2e-tests/cypress/e2e/Sanity-check.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,28 @@ import { Reporting } from '../support/page-objects/Reporting';
import { KibanaNavigation } from '../support/page-objects/KibanaNavigation';
import { getKibanaVersion } from '../support/helpers';
import { Loader } from '../support/page-objects/Loader';
import { DirectKibanaRequest, GetIndices, GetObject, GetReport } from '../support/page-objects/DirectKibanaRequest';
import { esApiAdvancedClient } from '../support/helpers/EsApiAdvancedClient';
import { kbnApiAdvancedClient } from '../support/helpers/KbnApiAdvancedClient';
import { SampleData } from '../support/helpers/SampleData';

describe('sanity check', () => {
beforeEach(() => {
SampleData.createSampleData("sample_index", 1)
Login.initialization();
});

afterEach(() => {
const clearSanityCheckState = () => {
cy.getRequest({ url: DirectKibanaRequest.getObjectsUrl() }).then((result: GetObject) => {
result.saved_objects.map(savedObject =>
cy.deleteRequest({ url: DirectKibanaRequest.deleteObjectUrl(savedObject.type, savedObject.id) })
);
});

cy.getRequest({ url: DirectKibanaRequest.getObjectsUrl(), header: 'x-ror-current-group: infosec_group' }).then(
(result: GetObject) => {
result.saved_objects.map(savedObject =>
cy.deleteRequest({
url: DirectKibanaRequest.deleteObjectUrl(savedObject.type, savedObject.id),
header: 'x-ror-current-group: infosec_group'
})
);
}
);

cy.getRequest({ url: DirectKibanaRequest.getIndices, user: 'kibana:kibana' }).then((result: GetIndices[]) => {
const reportingIndex = result.find(index => index.index.startsWith('.reporting'));

cy.getRequest({ url: DirectKibanaRequest.getReportUrl(reportingIndex.index) }).then((result: GetReport) => {
result.hits.hits.map(report =>
cy.deleteRequest({
url: DirectKibanaRequest.deleteReportUrl(reportingIndex.index, report._id),
user: 'kibana:kibana'
})
);
});
});

cy.getRequest({
url: DirectKibanaRequest.getIndices,
user: 'kibana:kibana',
header: 'x-ror-current-group: infosec_group'
}).then((result: GetIndices[]) => {
const reportingIndex = result.find(index => index.index.startsWith('.reporting'));

cy.getRequest({
url: DirectKibanaRequest.getReportUrl(reportingIndex.index),
header: 'x-ror-current-group: infosec_group'
}).then((result: GetReport) => {
result.hits.hits.map(report =>
cy.deleteRequest({
url: DirectKibanaRequest.deleteReportUrl(reportingIndex.index, report._id),
header: 'x-ror-current-group: infosec_group',
user: 'kibana:kibana'
})
);
});
});
};

clearSanityCheckState();
esApiAdvancedClient.deleteIndex("sample_index");
kbnApiAdvancedClient.deleteSavedObjects("admin:dev");
kbnApiAdvancedClient.deleteSavedObjects("admin:dev", "infosec_group")
esApiAdvancedClient.pruneAllReportingIndices();
});

it('should verify that everything works', () => {
cy.log('Initialize Administrator tenancy');

Discover.openDataViewPage();
Discover.createIndexPattern('r');
Discover.createIndexPattern('s');

cy.log('Create a CSV report');
Discover.saveReport('admin_search');
Expand All @@ -86,16 +40,16 @@ describe('sanity check', () => {
if (semver.gte(getKibanaVersion(), '8.8.0')) {
Reporting.noReportsCreatedCheck('rorMenu');
RorMenu.openDataViewsPage();
Discover.createIndexPattern('re');
Discover.createIndexPattern('sa');
} else if (semver.gte(getKibanaVersion(), '8.1.0')) {
Reporting.noReportsCreatedCheck('rorMenu');
RorMenu.openDataViewsPage();
Discover.openDataViewPage();
Discover.createIndexPattern('re');
Discover.createIndexPattern('sa');
} else {
Reporting.noReportsCreatedCheck('rorMenu');
Discover.openDataViewPage();
Discover.createIndexPattern('re');
Discover.createIndexPattern('sa');

cy.log('Create CSV report for the second tenancy');
Discover.saveReport('infosec_search');
Expand Down
12 changes: 2 additions & 10 deletions e2e-tests/cypress/e2e/Saved-objects.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as semver from 'semver';
import { Login } from '../support/page-objects/Login';
import { StackManagement } from '../support/page-objects/StackManagement';
import { DirectKibanaRequest, GetObject } from '../support/page-objects/DirectKibanaRequest';
import { getKibanaVersion } from '../support/helpers';
import { kbnApiAdvancedClient } from '../support/helpers/KbnApiAdvancedClient';

describe('Saved objects', () => {
beforeEach(() => {
Expand All @@ -11,15 +11,7 @@ describe('Saved objects', () => {
});

afterEach(() => {
const clearSavedObjects = () => {
cy.getRequest({ url: DirectKibanaRequest.getObjectsUrl() }).then((result: GetObject) => {
result.saved_objects.map(savedObject =>
cy.deleteRequest({ url: DirectKibanaRequest.deleteObjectUrl(savedObject.type, savedObject.id) })
);
});
};

clearSavedObjects();
kbnApiAdvancedClient.deleteSavedObjects("admin:dev");
});

it('should display saved objects list', () => {
Expand Down
Loading

0 comments on commit 0b75e9a

Please sign in to comment.