Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Adds support to run Cypress test in an ODFE cluster with security enabled #235

Merged
merged 15 commits into from
Jan 15, 2021
Merged
3 changes: 2 additions & 1 deletion cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"defaultCommandTimeout": 10000,
"env": {
"elasticsearch": "localhost:9200",
"kibana": "localhost:5601"
"kibana": "localhost:5601",
"security_enabled": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"inputs": [
{
"search": {
"indices": [".*"],
"indices": ["alerting*"],
"query": {
"query": {
"term": { "monitor.type": "monitor" }
"match_all": {}
}
}
}
Expand All @@ -25,7 +25,7 @@
"severity": "3",
"condition": {
"script": {
"source": "ctx.results[0].hits.total.value > 1",
"source": "ctx.results[0].hits.total.value < 1",
"lang": "painless"
}
},
Expand Down
146 changes: 84 additions & 62 deletions cypress/integration/alert_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@

import { PLUGIN_NAME } from '../support/constants';
import sampleMonitorWithAlwaysTrueTrigger from '../fixtures/sample_monitor_with_always_true_trigger';
import sampleMonitorWorkflow from '../fixtures/sample_monitor_workflow_7.1.json';
import sampleMonitorWorkflow from '../fixtures/sample_monitor_workflow';

const SAMPLE_MONITOR_TO_BE_DELETED = 'sample_monitor_with_always_true_trigger';
const SAMPLE_MONITOR_WORKFLOW = 'sample_monitor_workflow';
const TESTING_INDEX = 'alerting_test';

describe('Alerts', () => {
beforeEach(() => {
Expand All @@ -34,7 +33,11 @@ describe('Alerts', () => {

describe("can be in 'Active' state", () => {
before(() => {
cy.deleteAllIndices();
cy.deleteAllMonitors();
// Generate a unique number in every test by getting a unix timestamp in milliseconds
Cypress.config('unique_number', `${Date.now()}`);
// Modify the monitor name to be unique
sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`;
cy.createMonitor(sampleMonitorWithAlwaysTrueTrigger);
});

Expand All @@ -45,6 +48,11 @@ describe('Alerts', () => {
// Reload the page
cy.reload();

// Type in monitor name in search box to filter out the alert
cy.get(`input[type="search"]`)
.focus()
.type(`${Cypress.config('unique_number')}`);

// Confirm we can see one and only alert in Active state
cy.get('tbody > tr').should(($tr) => {
expect($tr, '1 row').to.have.length(1);
Expand All @@ -55,16 +63,25 @@ describe('Alerts', () => {

describe("can be in 'Acknowledged' state", () => {
before(() => {
cy.deleteAllIndices();
cy.deleteAllMonitors();
Cypress.config('unique_number', `${Date.now()}`);
// Modify the monitor name to be unique
sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`;
cy.createAndExecuteMonitor(sampleMonitorWithAlwaysTrueTrigger);
});

it('by clicking the button in Dashboard', () => {
// Type in monitor name in search box to filter out the alert
cy.get(`input[type="search"]`)
.focus()
.type(`${Cypress.config('unique_number')}`);

//Confirm there is an active alert
cy.contains('Active');

// Select checkbox for the existing alert
cy.get('input[data-test-subj^="checkboxSelectRow-"]').click({ force: true });
// There may be multiple alerts in the cluster, first() is used to get the active alert
cy.get('input[data-test-subj^="checkboxSelectRow-"]').first().click({ force: true });

// Click Acknowledge button
cy.get('button').contains('Acknowledge').click({ force: true });
Expand All @@ -76,108 +93,113 @@ describe('Alerts', () => {

describe("can be in 'Completed' state", () => {
before(() => {
cy.deleteAllIndices();
cy.createMonitor(sampleMonitorWithAlwaysTrueTrigger);
cy.deleteAllMonitors();
// Delete the target indices defined in 'sample_monitor_workflow.json'
cy.deleteIndexByName('alerting*');
Cypress.config('unique_number', `${Date.now()}`);
// Modify the monitor name to be unique
sampleMonitorWorkflow.name += `-${Cypress.config('unique_number')}`;
cy.createAndExecuteMonitor(sampleMonitorWorkflow);
});

it('when the trigger condition is not met after met once', () => {
//Confirm there is an active alert
cy.contains('Active');

// Select checkbox for the existing alert
cy.get('input[data-test-subj^="checkboxSelectRow-"]').click({ force: true });

// Click Monitors button to route to Monitors tab
cy.get('button').contains('Monitors').click({ force: true });
// Type in monitor name in search box to filter out the alert
cy.get(`input[type="search"]`)
.focus()
.type(`${Cypress.config('unique_number')}`);

// Type in monitor name in search box
cy.get(`input[type="search"]`).focus().type(SAMPLE_MONITOR_TO_BE_DELETED);

// Confirm we filtered down to our one and only monitor
cy.get('tbody > tr').should(($tr) => {
expect($tr, '1 row').to.have.length(1);
expect($tr, 'item').to.contain(SAMPLE_MONITOR_TO_BE_DELETED);
});

// Select checkbox for the existing monitor
cy.get('input[data-test-subj^="checkboxSelectRow-"]').first().click({ force: true });

// Click Actions button to open the actions menu
cy.contains('Actions').click({ force: true });

// Click the Delete button
cy.contains('Delete').click({ force: true });
// Confirm there is an active alert
cy.contains('Active');

// Clear the text in the search box
cy.get(`input[type="search"]`).focus().clear();
// The trigger condition is: there is no document in the indices 'alerting*'
// The following commands create a document in the index to complete the alert
// Create an index
cy.createIndexByName(TESTING_INDEX);

// Confirm we can see only one monitor in the list
cy.get('tbody > tr').should(($tr) => {
expect($tr, '1 row').to.have.length(1);
expect($tr, 'item').to.contain(SAMPLE_MONITOR_WORKFLOW);
});
// Insert a document
cy.insertDocumentToIndex('test', 1, {});

// Wait for 1 minute
cy.wait(60000);

// Click Dashboard button to route to Dashboard tab
cy.get('button').contains('Dashboard').click({ force: true });
// Reload the page
cy.reload();

// Type in monitor name in search box to filter out the alert
cy.get(`input[type="search"]`)
.focus()
.type(`${Cypress.config('unique_number')}`);

// Confirm we can see the alert is in 'Completed' state
cy.contains('Completed');
});

after(() => {
// Delete the testing index
cy.deleteIndexByName(TESTING_INDEX);
});
});

describe("can be in 'Error' state", () => {
before(() => {
cy.deleteAllIndices();
cy.deleteAllMonitors();
// modify the JSON object to make an error alert when executing the monitor
sampleMonitorWithAlwaysTrueTrigger.triggers[0].actions = [
{ name: '', destination_id: '', message_template: { source: '' } },
];
Cypress.config('unique_number', `${Date.now()}`);
// Modify the monitor name to be unique
sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`;
cy.createAndExecuteMonitor(sampleMonitorWithAlwaysTrueTrigger);
});

it('by using a wrong destination', () => {
// Type in monitor name in search box to filter out the alert
cy.get(`input[type="search"]`)
.focus()
.type(`${Cypress.config('unique_number')}`);

// Confirm we can see the alert is in 'Error' state
cy.contains('Error');
});
});

describe("can be in 'Deleted' state", () => {
before(() => {
cy.deleteAllIndices();
cy.deleteAllMonitors();
Cypress.config('unique_number', `${Date.now()}`);
// Modify the monitor name to be unique
sampleMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`;
cy.createAndExecuteMonitor(sampleMonitorWithAlwaysTrueTrigger);
});

it('by deleting the monitor', () => {
// Type in monitor name in search box to filter out the alert
cy.get(`input[type="search"]`)
.focus()
.type(`${Cypress.config('unique_number')}`);

//Confirm there is an active alert
cy.contains('Active');

// Click Monitors button to route to Monitors tab
cy.get('button').contains('Monitors').click({ force: true });

// Confirm we can see a monitor in the list
cy.contains(SAMPLE_MONITOR_TO_BE_DELETED);

// Select checkbox for the existing monitor
cy.get('input[data-test-subj^="checkboxSelectRow-"]').click({ force: true });

// Click Actions button to open the actions menu
cy.contains('Actions').click({ force: true });

// Click the Delete button
cy.contains('Delete').click({ force: true });
// Delete all existing monitors
cy.deleteAllMonitors();

// Confirm we can see an empty monitor list
cy.contains('There are no existing monitors');
// Reload the page
cy.reload();

// Click Dashboard button to route to Dashboard tab
cy.get('button').contains('Dashboard').click({ force: true });
// Type in monitor name in search box to filter out the alert
cy.get(`input[type="search"]`)
.focus()
.type(`${Cypress.config('unique_number')}`);

// Confirm we can see the alert is in 'Deleted' state
cy.contains('Deleted');
});
});

after(() => {
// Delete all existing monitors
cy.deleteAllMonitors();
});
});
21 changes: 15 additions & 6 deletions cypress/integration/destination_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import { PLUGIN_NAME } from '../support/constants';
import sampleDestination from '../fixtures/sample_destination_custom_webhook.json';
import sampleDestination from '../fixtures/sample_destination_custom_webhook';
import sampleDestinationChime from '../fixtures/sample_destination_chime';

const SAMPLE_DESTINATION = 'sample_destination';
Expand All @@ -36,7 +36,7 @@ describe('Destinations', () => {

describe('can be created', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteAllDestinations();
});

it('with a custom webhook', () => {
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('Destinations', () => {

describe('can be updated', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteAllDestinations();
cy.createDestination(sampleDestination);
});

Expand All @@ -77,7 +77,11 @@ describe('Destinations', () => {
cy.get('button').contains('Edit').click({ force: true });

// Wait for input to load and then type in the destination name
cy.get('input[name="name"]').focus().clear().type(UPDATED_DESTINATION, { force: true });
// should() is used to wait for input loading before clearing
cy.get('input[name="name"]')
.should('have.value', SAMPLE_DESTINATION)
.clear()
.type(UPDATED_DESTINATION, { force: true });

// Click the create button
cy.get('button').contains('Update').click({ force: true });
Expand All @@ -89,7 +93,7 @@ describe('Destinations', () => {

describe('can be deleted', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteAllDestinations();
cy.createDestination(sampleDestination);
});

Expand All @@ -110,7 +114,7 @@ describe('Destinations', () => {

describe('can be searched', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteAllDestinations();
// Create 21 destinations so that a monitor will not appear in the first page
for (let i = 0; i < 20; i++) {
cy.createDestination(sampleDestination);
Expand All @@ -135,4 +139,9 @@ describe('Destinations', () => {
});
});
});

after(() => {
// Delete all existing destinations
cy.deleteAllDestinations();
});
});
Loading