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

[Security Solution] Cypress back to live #86093

Merged
merged 15 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from 11 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@
"cpy": "^8.1.1",
"cronstrue": "^1.51.0",
"css-loader": "^3.4.2",
"cypress": "^6.0.1",
"cypress": "^6.1.0",
"cypress-cucumber-preprocessor": "^2.5.2",
"cypress-multi-reporters": "^1.4.0",
"d3": "3.5.17",
Expand Down
17 changes: 8 additions & 9 deletions vars/tasks.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,14 @@ def functionalXpack(Map params = [:]) {
task(kibanaPipeline.functionalTestProcess('xpack-savedObjectsFieldMetrics', './test/scripts/jenkins_xpack_saved_objects_field_metrics.sh'))
}

// FLAKY: https://github.com/elastic/kibana/issues/86080
// whenChanged([
// 'x-pack/plugins/security_solution/',
// 'x-pack/test/security_solution_cypress/',
// 'x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/',
// 'x-pack/plugins/triggers_actions_ui/public/application/context/actions_connectors_context.tsx',
// ]) {
// task(kibanaPipeline.functionalTestProcess('xpack-securitySolutionCypress', './test/scripts/jenkins_security_solution_cypress.sh'))
// }
whenChanged([
'x-pack/plugins/security_solution/',
'x-pack/test/security_solution_cypress/',
'x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/',
'x-pack/plugins/triggers_actions_ui/public/application/context/actions_connectors_context.tsx',
]) {
task(kibanaPipeline.functionalTestProcess('xpack-securitySolutionCypress', './test/scripts/jenkins_security_solution_cypress.sh'))
}
}
}

Expand Down
38 changes: 21 additions & 17 deletions x-pack/plugins/security_solution/cypress/integration/alerts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
goToInProgressAlerts,
} from '../tasks/alerts';
import { removeSignalsIndex } from '../tasks/api_calls/rules';
import { cleanKibana } from '../tasks/common';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
import { loginAndWaitForPage } from '../tasks/login';

Expand All @@ -34,16 +35,13 @@ import { DETECTIONS_URL } from '../urls/navigation';
describe('Alerts', () => {
context('Closing alerts', () => {
beforeEach(() => {
cleanKibana();
removeSignalsIndex();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit of a tangent, but I just had a couple thoughts:

  • Keeping test setup/teardown symmetrical is a PITA
    • reorienting this to do teardown, then setup all within setup would reduce this complexity
      • This would address/sidestep the issue of test failures, which can currently cause teardown not to execute
      • We could lessen developer burden by defining this as a general function(s)
// in test file
describe('my test', () => {
  detectionEngineHooks();
  
  it('does a thing', () => {});
});

// in helper file
const detectionEngineHooks = () => {
  beforeEach(() => {
    cleanKibana(); // deletes `.kibana*`, loads `empty_kibana`
    cleanSignals(); // deletes `.siem-signals*`, hits detections endpoint to create index
    cleanLoad('alerts'); // see below
  });
};

const cleanLoad = (archive) => {
    unload(archive); // might need to try/catch this?
    load(archive);
}

esArchiverLoad('alerts');
loginAndWaitForPage(DETECTIONS_URL);
});

afterEach(() => {
esArchiverUnload('alerts');
removeSignalsIndex();
});

it.skip('Closes and opens alerts', () => {
it('Closes and opens alerts', () => {
waitForAlertsPanelToBeLoaded();
waitForAlertsToBeLoaded();

Expand Down Expand Up @@ -117,13 +115,15 @@ describe('Alerts', () => {
`Showing ${expectedNumberOfOpenedAlerts.toString()} alerts`
);

cy.get(
'[data-test-subj="events-viewer-panel"] [data-test-subj="server-side-event-count"]'
).should('have.text', expectedNumberOfOpenedAlerts.toString());
cy.get('[data-test-subj="server-side-event-count"]').should(
'have.text',
expectedNumberOfOpenedAlerts.toString()
);
esArchiverUnload('alerts');
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these should go back into the afterEach. I had mentioned offline that, due to cypress skipping the suite if the test fails, we should move any test-specific teardown (e.g. deleteRule) into the test itself to avoid unnecessary skips, but I don't think that these unloads fall in that category.

});
});

it.skip('Closes one alert when more than one opened alerts are selected', () => {
it('Closes one alert when more than one opened alerts are selected', () => {
waitForAlertsToBeLoaded();

cy.get(ALERTS_COUNT)
Expand Down Expand Up @@ -157,22 +157,20 @@ describe('Alerts', () => {
`Showing ${numberOfAlertsToBeClosed.toString()} alert`
);
cy.get(ALERTS).should('have.length', numberOfAlertsToBeClosed);
esArchiverUnload('alerts');
});
});
});

context('Opening alerts', () => {
beforeEach(() => {
cleanKibana();
removeSignalsIndex();
esArchiverLoad('closed_alerts');
loginAndWaitForPage(DETECTIONS_URL);
});

afterEach(() => {
esArchiverUnload('closed_alerts');
removeSignalsIndex();
});

it.skip('Open one alert when more than one closed alerts are selected', () => {
it('Open one alert when more than one closed alerts are selected', () => {
waitForAlerts();
goToClosedAlerts();
waitForAlertsToBeLoaded();
Expand Down Expand Up @@ -209,12 +207,16 @@ describe('Alerts', () => {
`Showing ${numberOfAlertsToBeOpened.toString()} alert`
);
cy.get(ALERTS).should('have.length', numberOfAlertsToBeOpened);

esArchiverUnload('closed_alerts');
});
});
});

context('Marking alerts as in-progress', () => {
beforeEach(() => {
cleanKibana();
removeSignalsIndex();
esArchiverLoad('alerts');
loginAndWaitForPage(DETECTIONS_URL);
});
Expand All @@ -224,7 +226,7 @@ describe('Alerts', () => {
removeSignalsIndex();
});

it.skip('Mark one alert in progress when more than one open alerts are selected', () => {
it('Mark one alert in progress when more than one open alerts are selected', () => {
waitForAlerts();
waitForAlertsToBeLoaded();

Expand Down Expand Up @@ -259,6 +261,8 @@ describe('Alerts', () => {
`Showing ${numberOfAlertsToBeMarkedInProgress.toString()} alert`
);
cy.get(ALERTS).should('have.length', numberOfAlertsToBeMarkedInProgress);

esArchiverUnload('closed_alerts');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
login,
loginAndWaitForPageWithoutDateRange,
waitForPageWithoutDateRange,
deleteRoleAndUser,
} from '../tasks/login';
import { waitForAlertsIndexToBeCreated } from '../tasks/alerts';
import { goToRuleDetails } from '../tasks/alerts_detection_rules';
import { createCustomRule, deleteCustomRule, removeSignalsIndex } from '../tasks/api_calls/rules';
import { getCallOut, waitForCallOutToBeShown, dismissCallOut } from '../tasks/common/callouts';
import { cleanKibana } from '../tasks/common';

const loadPageAsReadOnlyUser = (url: string) => {
waitForPageWithoutDateRange(url, ROLES.reader);
Expand All @@ -41,19 +41,15 @@ describe('Detections > Callouts indicating read-only access to resources', () =>
before(() => {
// First, we have to open the app on behalf of a priviledged user in order to initialize it.
// Otherwise the app will be disabled and show a "welcome"-like page.
cleanKibana();
removeSignalsIndex();
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL, ROLES.platform_engineer);
waitForAlertsIndexToBeCreated();

// After that we can login as a read-only user.
login(ROLES.reader);
});

after(() => {
deleteRoleAndUser(ROLES.reader);
deleteRoleAndUser(ROLES.platform_engineer);
removeSignalsIndex();
});

context('On Detections home page', () => {
beforeEach(() => {
loadPageAsReadOnlyUser(DETECTIONS_URL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
goToOpenedAlerts,
waitForAlertsIndexToBeCreated,
} from '../tasks/alerts';
import { createCustomRule, deleteCustomRule, removeSignalsIndex } from '../tasks/api_calls/rules';
import { createCustomRule, removeSignalsIndex } from '../tasks/api_calls/rules';
import { goToRuleDetails } from '../tasks/alerts_detection_rules';
import { waitForAlertsToPopulate } from '../tasks/create_new_rule';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
Expand All @@ -33,10 +33,13 @@ import {
import { refreshPage } from '../tasks/security_header';

import { DETECTIONS_URL } from '../urls/navigation';
import { cleanKibana } from '../tasks/common';

describe.skip('Exceptions', () => {
const NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS = '1';
beforeEach(() => {
cleanKibana();
removeSignalsIndex();
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL);
waitForAlertsIndexToBeCreated();
createCustomRule(newRule);
Expand All @@ -55,12 +58,6 @@ describe.skip('Exceptions', () => {
cy.get(NUMBER_OF_ALERTS).should('have.text', NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS);
});

afterEach(() => {
esArchiverUnload('auditbeat_for_exceptions');
esArchiverUnload('auditbeat_for_exceptions2');
deleteCustomRule();
removeSignalsIndex();
});
context('From rule', () => {
it('Creates an exception and deletes it', () => {
goToExceptionsTab();
Expand Down Expand Up @@ -96,6 +93,9 @@ describe.skip('Exceptions', () => {

cy.get(ALERTS_COUNT).should('exist');
cy.get(NUMBER_OF_ALERTS).should('have.text', NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS);

esArchiverUnload('auditbeat_for_exceptions');
esArchiverUnload('auditbeat_for_exceptions2');
});
});

Expand Down Expand Up @@ -130,6 +130,9 @@ describe.skip('Exceptions', () => {

cy.get(ALERTS_COUNT).should('exist');
cy.get(NUMBER_OF_ALERTS).should('have.text', NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS);

esArchiverUnload('auditbeat_for_exceptions');
esArchiverUnload('auditbeat_for_exceptions2');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';
import { DEFAULT_RULE_REFRESH_INTERVAL_VALUE } from '../../common/constants';

import { DETECTIONS_URL } from '../urls/navigation';
import { removeSignalsIndex } from '../tasks/api_calls/rules';
import { cleanKibana } from '../tasks/common';

describe('Alerts detection rules', () => {
before(() => {
cleanKibana();
removeSignalsIndex();
esArchiverLoad('prebuilt_rules_loaded');
});

after(() => {
esArchiverUnload('prebuilt_rules_loaded');
cy.clock().invoke('restore');
});

it('Sorts by activated rules', () => {
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL);
waitForAlertsPanelToBeLoaded();
Expand Down Expand Up @@ -81,6 +80,8 @@ describe('Alerts detection rules', () => {
cy.get(RULE_SWITCH).eq(SECOND_RULE).should('have.attr', 'role', 'switch');
});
});

esArchiverUnload('prebuilt_rules_loaded');
});

// FIXME: UI hangs on loading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ import {
import {
changeToThreeHundredRowsPerPage,
deleteFirstRule,
deleteRule,
deleteSelectedRules,
editFirstRule,
filterByCustomRules,
Expand All @@ -86,7 +85,8 @@ import {
waitForRulesToBeLoaded,
} from '../tasks/alerts_detection_rules';
import { removeSignalsIndex } from '../tasks/api_calls/rules';
import { createTimeline, deleteTimeline } from '../tasks/api_calls/timelines';
import { createTimeline } from '../tasks/api_calls/timelines';
import { cleanKibana } from '../tasks/common';
import {
createAndActivateRule,
fillAboutRule,
Expand Down Expand Up @@ -115,17 +115,13 @@ describe('Custom detection rules creation', () => {
const rule = { ...newRule };

before(() => {
cleanKibana();
removeSignalsIndex();
createTimeline(newRule.timeline).then((response) => {
rule.timeline.id = response.body.data.persistTimeline.timeline.savedObjectId;
});
});

after(() => {
deleteRule();
deleteTimeline(rule.timeline.id!);
removeSignalsIndex();
});

it('Creates and activates a new rule', () => {
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL);
waitForAlertsPanelToBeLoaded();
Expand Down Expand Up @@ -219,18 +215,15 @@ describe('Custom detection rules creation', () => {

describe.skip('Custom detection rules deletion and edition', () => {
beforeEach(() => {
cleanKibana();
removeSignalsIndex();
esArchiverLoad('custom_rules');
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL);
waitForAlertsPanelToBeLoaded();
waitForAlertsIndexToBeCreated();
goToManageAlertsDetectionRules();
});

afterEach(() => {
removeSignalsIndex();
esArchiverUnload('custom_rules');
});

context('Deletion', () => {
it('Deletes one rule', () => {
cy.get(RULES_TABLE)
Expand Down Expand Up @@ -259,6 +252,8 @@ describe.skip('Custom detection rules deletion and edition', () => {
`Custom rules (${expectedNumberOfRulesAfterDeletion})`
);
});

esArchiverUnload('custom_rules');
});

it('Deletes more than one rule', () => {
Expand Down Expand Up @@ -289,6 +284,8 @@ describe.skip('Custom detection rules deletion and edition', () => {
`Custom rules (${expectedNumberOfRulesAfterDeletion})`
);
});

esArchiverUnload('custom_rules');
});
});

Expand Down Expand Up @@ -362,5 +359,7 @@ describe.skip('Custom detection rules deletion and edition', () => {
});
}
});

esArchiverUnload('custom_rules');
});
});
Loading