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

ROR_INTR_001 #3

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
6 changes: 4 additions & 2 deletions 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: 'NOT_SET_YET',
elasticsearchUrl: 'http://localhost:19200',
enterpriseActivationKey: 'PROVIDE_YOUR_ACTIVATION_KEY'
enterpriseActivationKey: 'PROVIDE_YOUR_ACTIVATION_KEY',
readFileTimeout: 60000,
},
video: true,
screenshotOnRunFailure: true,
Expand All @@ -31,6 +32,7 @@ export default defineConfig({
},
baseUrl: 'http://localhost:5601',
videosFolder: '../results/videos',
screenshotsFolder: '../results/screenshots'
screenshotsFolder: '../results/screenshots',
downloadsFolder: './cypress/downloads/',
coutoPL marked this conversation as resolved.
Show resolved Hide resolved
}
});
108 changes: 108 additions & 0 deletions e2e-tests/cypress/e2e/Report-generation.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { Login } from "../support/page-objects/Login";
import { DataViews } from "../support/page-objects/management/DataViews";
import { Discover } from "../support/page-objects/Discover";
import { Reports } from "../support/page-objects/management/Reports";

describe('Report Generation', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I ran the test - it's way too SLOOOOW.
Do we need so much data?

const indexName: string = 'invoices';
const searchName: string = `${ indexName } search`;


before(() => {
// Attempt to bulk index sample data
cy.put({
user: 'kibana:kibana',
url: `${ Cypress.env().elasticsearchUrl }/${ indexName }/_bulk`,
payload: [
{create: {}},
{id: 1, number: "INV001", date: "2024-08-01", amount: "123.45", currency: "USD"},
{create: {}},
{id: 2, number: "INV002", date: "2024-08-02", amount: "67.89", currency: "EUR"},
{create: {}},
{id: 3, number: "INV003", date: "2024-08-03", amount: "456.78", currency: "GBP"},
{create: {}},
{id: 4, number: "INV004", date: "2024-08-04", amount: "90.12", currency: "JPY"},
{create: {}},
{id: 5, number: "INV005", date: "2024-08-05", amount: "345.67", currency: "CAD"},
{create: {}},
{id: 6, number: "INV006", date: "2024-08-06", amount: "89.01", currency: "AUD"},
{create: {}},
{id: 7, number: "INV007", date: "2024-08-07", amount: "234.56", currency: "CHF"},
{create: {}},
{id: 8, number: "INV008", date: "2024-08-08", amount: "78.90", currency: "SEK"},
{create: {}},
{id: 9, number: "INV009", date: "2024-08-09", amount: "135.79", currency: "NZD"},
{create: {}},
{id: 10, number: "INV010", date: "2024-08-10", amount: "246.80", currency: "DKK"},
{create: {}},
{id: 11, number: "INV011", date: "2024-08-11", amount: "357.91", currency: "NOK"},
{create: {}},
{id: 12, number: "INV012", date: "2024-08-12", amount: "468.02", currency: "ZAR"},
{create: {}},
{id: 13, number: "INV013", date: "2024-08-13", amount: "579.13", currency: "BRL"},
{create: {}},
{id: 14, number: "INV014", date: "2024-08-14", amount: "680.24", currency: "INR"},
{create: {}},
{id: 15, number: "INV015", date: "2024-08-15", amount: "791.35", currency: "RUB"}
]
});
});

beforeEach(() => {
Login.setLogin('user2:dev');
Login.initialization();

DataViews.deleteSavedObjectsIfExist([indexName, searchName]);
Reports.deleteAllReports(searchName)


Login.signOut();
})

it('should generate and verify reports for user2, and user3 should not see them', () => {
Login.setLogin('user2:dev');
Login.initialization();

DataViews.createDataView(indexName);

Discover.navigateTo();

Discover.selectDataView(indexName);
Discover.saveSearch(searchName);
for (let i = 0; i < 10; i++) {
Discover.generateCsvReport(50000);
}

// Go to Reports and check if all reports are not empty
Reports.navigateTo();
Reports.checkAllReports(searchName);

Login.signOut();

Login.setLogin('user3:dev');
Login.initialization();

Reports.navigateTo();
Reports.verifyNoReports();

Login.signOut();
});

afterEach(() => {
Login.setLogin('user2:dev');
Login.initialization();

DataViews.deleteSavedObjectsIfExist([indexName, searchName]);
Reports.deleteAllReports(searchName)


Login.signOut();
})

after(() => {
cy.delete({
user: 'kibana:kibana',
url: `${ Cypress.env().elasticsearchUrl }/${ indexName }`,
})
});
});
4 changes: 2 additions & 2 deletions e2e-tests/cypress/e2e/Sanity-check.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('sanity check', () => {
Discover.createIndexPattern('r');

cy.log('Create a CSV report');
Discover.saveReport('admin_search');
Discover.saveSearch('admin_search');
Discover.exportToCsv();
Reporting.verifySavedReport('admin_search', 'kibanaNavigation', 1);

Expand All @@ -98,7 +98,7 @@ describe('sanity check', () => {
Discover.createIndexPattern('re');

cy.log('Create CSV report for the second tenancy');
Discover.saveReport('infosec_search');
Discover.saveSearch('infosec_search');
Discover.exportToCsv();
Reporting.verifySavedReport('infosec_search', 'rorMenu', 1);
}
Expand Down
81 changes: 63 additions & 18 deletions e2e-tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,93 @@
import '@testing-library/cypress/add-commands';
import { isJsonString } from './helpers';

Cypress.Commands.add('post', ({ url, user = `${Cypress.env().login}:${Cypress.env().password}`, payload }, ...args) => {
const escapedAndStringifyPayload = JSON.stringify(JSON.stringify(payload));

return cy
.exec(
`curl -v -k -H "Content-Type: application/json" -H "kbn-xsrf: true" -d ${escapedAndStringifyPayload} -X POST ${url} --user ${user}`
)
.then(result => {
console.log(url, result);
return isJsonString(result.stdout) ? JSON.parse(result.stdout) : result.stdout;
});
});
Cypress.Commands.add(
'post',
({url, user = `${ Cypress.env().login }:${ Cypress.env().password }`, payload}, ...args) => {
const escapedAndStringifyPayload = JSON.stringify(JSON.stringify(payload));

return cy
.exec(
`curl -v -k -H "Content-Type: application/json" -H "kbn-xsrf: true" -d ${ escapedAndStringifyPayload } -X POST ${ url } --user ${ user }`
)
.then(result => {
console.log(url, result);
return isJsonString(result.stdout) ? JSON.parse(result.stdout) : result.stdout;
});
});

Cypress.Commands.add(
'put',
({url, user = `${ Cypress.env().login }:${ Cypress.env().password }`, payload}, ...args) => {
const formattedPayload = payload.map(item => JSON.stringify(item)).join('\n') + '\n';

console.log(`curl -H "Content-Type: application/json" -d '${ formattedPayload }' -XPUT "${ url }" -u ${ user }`);

return cy
.exec(
`curl -H "Content-Type: application/json" -d '${ formattedPayload }' -XPUT "${ url }" -u ${ user }`
)
.then(result => {
console.log(url, result);
return isJsonString(result.stdout) ? JSON.parse(result.stdout) : result.stdout;
});
});

Cypress.Commands.add(
'import',
({ url, filename, user = `${Cypress.env().login}:${Cypress.env().password}` }, ...args) =>
cy.exec(`curl -v -k -H "kbn-xsrf: true" --form file=@${filename} -X POST "${url}" --user ${user}`).then(result => {
({url, filename, user = `${ Cypress.env().login }:${ Cypress.env().password }`}, ...args) =>
cy.exec(`curl -v -k -H "kbn-xsrf: true" --form file=@${ filename } -X POST "${ url }" --user ${ user }`).then(result => {
console.log(url, result);
return isJsonString(result.stdout) ? JSON.parse(result.stdout) : result.stdout;
})
);

Cypress.Commands.add(
'getRequest',
({ url, user = `${Cypress.env().login}:${Cypress.env().password}`, header }, ...args) =>
cy.exec(`curl -v -k "${url}" --user ${user} ${header ? `-H "${header}"` : ''}`).then(result => {
({url, user = `${ Cypress.env().login }:${ Cypress.env().password }`, header}, ...args) =>
cy.exec(`curl -v -k "${ url }" --user ${ user } ${ header ? `-H "${ header }"` : '' }`).then(result => {
console.log(url, result);
return isJsonString(result.stdout) ? JSON.parse(result.stdout) : result.stdout;
})
);

Cypress.Commands.add(
'deleteRequest',
({ url, header, user = `${Cypress.env().login}:${Cypress.env().password}` }, ...args) =>
({url, header, user = `${ Cypress.env().login }:${ Cypress.env().password }`}, ...args) =>
cy
.exec(`curl -H "kbn-xsrf: true" -v -k -X DELETE "${url}" --user ${user} ${header ? `-H "${header}"` : ''}`)
.exec(`curl -H "kbn-xsrf: true" -v -k -X DELETE "${ url }" --user ${ user } ${ header ? `-H "${ header }"` : '' }`)
.then(result => {
console.log(url, result);
return isJsonString(result.stdout) ? JSON.parse(result.stdout) : result.stdout;
})
);

Cypress.Commands.add(
'delete',
({url, user = `${ Cypress.env().login }:${ Cypress.env().password }`}, ...args) =>
cy
.exec(`curl -H "Content-Type: application/json" -X DELETE "${ url }" -u ${ user }`)
.then(result => {
console.log(url, result);
return isJsonString(result.stdout) ? JSON.parse(result.stdout) : result.stdout;
})
);

Cypress.Commands.add(
'verifyDownload',
(fileName, options = {}) => { // Provide a default empty object for options
const downloadsFolder = Cypress.config('downloadsFolder');
const downloadTimeout = options.timeout || Cypress.env().readFileTimeout;

// Poll for the downloaded file
cy.log(`Waiting for download: ${ fileName }`);
return cy.readFile(`${ downloadsFolder }/${ fileName }`, {timeout: downloadTimeout})
.then(fileContent => {
cy.log(`Downloaded file: ${ fileName }`);
return Cypress.Promise.resolve(`${ downloadsFolder }/${ fileName }`);
});
});

Cypress.on('uncaught:exception', (err, runnable) => {
/**
* Don't fail test when these specific errors from kibana platform
Expand Down
3 changes: 3 additions & 0 deletions e2e-tests/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ declare global {
namespace Cypress {
export interface Chainable<Subject> {
post({ url, user, payload }: { url: string; user?: string; payload: unknown }): Chainable<Subject>;
put({ url, user, payload }: { url: string; user?: string; payload: unknown }): Chainable<Subject>;
import({ url, user, filename }: { url: string; user?: string; filename: string }): Chainable<Subject>;
getRequest({ url, user, header }: { url: string; user?: string; header?: string }): Chainable<Subject>;
deleteRequest({ url, user, header }: { url: string; user?: string; header?: string }): Chainable<Subject>;
delete({ url, user}: { url: string; user?: string}): Chainable<Subject>;
verifyDownload( fileName: string, options?: any): Chainable<Subject>;
}
}
}
14 changes: 7 additions & 7 deletions e2e-tests/cypress/support/page-objects/DevTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export class DevTools {
cy.log('Open Dev tools');
KibanaNavigation.openKibanaNavigation();
cy.contains('Dev Tools').click();
cy.findByRole('button', { name: /Dismiss/ });
cy.findByRole('button', {name: /Dismiss/});
cy.findByRole('dialog')
.findByRole('button', { name: /Dismiss/ })
.findByRole('button', {name: /Dismiss/})
.click();
}

Expand All @@ -18,15 +18,15 @@ export class DevTools {
if (semver.lte(getKibanaVersion(), '7.9.0')) {
// Select editor, delete, write
cy.get('#ConAppEditor').click();
cy.get('#ConAppInputTextarea').clear({ force: true });
cy.get('#ConAppInputTextarea').clear({force: true});
cy.get('#ConAppInputTextarea').type(text);

// Click play
cy.get('.ace_scroller:nth-child(4) > .ace_content').click({ force: true });
cy.get('.conApp__editorActionButton path').click({ force: true });
cy.get('.ace_scroller:nth-child(4) > .ace_content').click({force: true});
cy.get('.conApp__editorActionButton path').click({force: true});
} else {
cy.get('[data-test-subj=console-textarea]').clear({ force: true });
cy.get('[data-test-subj=console-textarea]').type(text, { force: true });
cy.get('[data-test-subj=console-textarea]').clear({force: true});
cy.get('[data-test-subj=console-textarea]').type(text, {force: true, parseSpecialCharSequences: false});
cy.get('[data-test-subj=sendRequestButton]').click();
}
}
Expand Down
Loading