[SIEM] Adds Cypress 'Exports custom rule' test (#64099)
* changes default browser download folder * adds 'exportRuleAction' data-test-subj attribute * implements 'Exports a custom rule' test * changes headless browser to chrome * updates path * updates 'EXPECTED_RULE_FILE_PATH' * gives time to the file to be downloaded * adds downloads folder * updates download directory * updates paths * captures API call to check the content of the file * removes browser launch hook since is not needed anymore Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
4f66dfd661
commit
eae92e34c3
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import {
|
||||
goToManageSignalDetectionRules,
|
||||
waitForSignalsIndexToBeCreated,
|
||||
waitForSignalsPanelToBeLoaded,
|
||||
} from '../tasks/detections';
|
||||
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
|
||||
import { loginAndWaitForPageWithoutDateRange } from '../tasks/login';
|
||||
import { exportFirstRule } from '../tasks/signal_detection_rules';
|
||||
|
||||
import { DETECTIONS } from '../urls/navigation';
|
||||
|
||||
const EXPECTED_EXPORTED_RULE_FILE_PATH = 'cypress/test_files/expected_rules_export.ndjson';
|
||||
|
||||
describe('Export rules', () => {
|
||||
before(() => {
|
||||
esArchiverLoad('custom_rules');
|
||||
cy.server();
|
||||
cy.route(
|
||||
'POST',
|
||||
'**api/detection_engine/rules/_export?exclude_export_details=false&file_name=rules_export.ndjson*'
|
||||
).as('export');
|
||||
});
|
||||
|
||||
after(() => {
|
||||
esArchiverUnload('custom_rules');
|
||||
});
|
||||
|
||||
it('Exports a custom rule', () => {
|
||||
loginAndWaitForPageWithoutDateRange(DETECTIONS);
|
||||
waitForSignalsPanelToBeLoaded();
|
||||
waitForSignalsIndexToBeCreated();
|
||||
goToManageSignalDetectionRules();
|
||||
exportFirstRule();
|
||||
cy.wait('@export').then(xhr => {
|
||||
cy.readFile(EXPECTED_EXPORTED_RULE_FILE_PATH).then($expectedExportedJson => {
|
||||
cy.wrap(xhr.responseBody).should('eql', $expectedExportedJson);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
const wp = require('@cypress/webpack-preprocessor');
|
||||
|
||||
module.exports = on => {
|
||||
const options = {
|
||||
webpackOptions: {
|
||||
|
|
|
@ -18,6 +18,8 @@ export const DELETE_RULE_BULK_BTN = '[data-test-subj="deleteRuleBulk"]';
|
|||
|
||||
export const ELASTIC_RULES_BTN = '[data-test-subj="show-elastic-rules-filter-button"]';
|
||||
|
||||
export const EXPORT_ACTION_BTN = '[data-test-subj="exportRuleAction"]';
|
||||
|
||||
export const FIFTH_RULE = 4;
|
||||
|
||||
export const FIRST_RULE = 0;
|
||||
|
|
|
@ -32,5 +32,10 @@ Cypress.on('uncaught:exception', err => {
|
|||
}
|
||||
});
|
||||
|
||||
Cypress.on('window:before:load', win => {
|
||||
win.fetch = null;
|
||||
win.Blob = null;
|
||||
});
|
||||
|
||||
// Alternatively you can use CommonJS syntax:
|
||||
// require('./commands')
|
||||
|
|
|
@ -23,6 +23,7 @@ import {
|
|||
RULES_TABLE,
|
||||
SORT_RULES_BTN,
|
||||
THREE_HUNDRED_ROWS,
|
||||
EXPORT_ACTION_BTN,
|
||||
} from '../screens/signal_detection_rules';
|
||||
|
||||
export const activateRule = (rulePosition: number) => {
|
||||
|
@ -48,6 +49,14 @@ export const deleteSelectedRules = () => {
|
|||
cy.get(DELETE_RULE_BULK_BTN).click();
|
||||
};
|
||||
|
||||
export const exportFirstRule = () => {
|
||||
cy.get(COLLAPSED_ACTION_BTN)
|
||||
.first()
|
||||
.click({ force: true });
|
||||
cy.get(EXPORT_ACTION_BTN).click();
|
||||
cy.get(EXPORT_ACTION_BTN).should('not.exist');
|
||||
};
|
||||
|
||||
export const filterByCustomRules = () => {
|
||||
cy.get(CUSTOM_RULES_BTN).click({ force: true });
|
||||
cy.get(LOADING_SPINNER).should('exist');
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
{"actions":[],"created_at":"2020-03-26T10:09:07.569Z","updated_at":"2020-03-26T10:09:08.021Z","created_by":"elastic","description":"Rule 1","enabled":true,"false_positives":[],"filters":[],"from":"now-360s","id":"49db5bd1-bdd5-4821-be26-bb70a815dedb","immutable":false,"index":["apm-*-transaction*","auditbeat-*","endgame-*","filebeat-*","packetbeat-*","winlogbeat-*"],"interval":"5m","rule_id":"0cea4194-03f2-4072-b281-d31b72221d9d","language":"kuery","output_index":".siem-signals-default","max_signals":100,"risk_score":50,"name":"Rule 1","query":"host.name:*","references":[],"meta":{"from":"1m","throttle":"no_actions"},"severity":"low","updated_by":"elastic","tags":["rule1"],"to":"now","type":"query","threat":[],"throttle":"no_actions","version":1}
|
||||
{"exported_count":1,"missing_rules":[],"missing_rules_count":0}
|
|
@ -8,7 +8,7 @@
|
|||
"extract-mitre-attacks": "node scripts/extract_tactics_techniques_mitre.js && node ../../../scripts/eslint ./public/pages/detection_engine/mitre/mitre_tactics_techniques.ts --fix",
|
||||
"build-graphql-types": "node scripts/generate_types_from_graphql.js",
|
||||
"cypress:open": "cypress open --config-file ./cypress/cypress.json",
|
||||
"cypress:run": "cypress run --spec ./cypress/integration/**/*.spec.ts --config-file ./cypress/cypress.json --reporter ../../node_modules/cypress-multi-reporters --reporter-options configFile=./cypress/reporter_config.json; status=$?; ../../node_modules/.bin/mochawesome-merge --reportDir ../../../target/kibana-siem/cypress/results > ../../../target/kibana-siem/cypress/results/output.json; ../../../node_modules/.bin/marge ../../../target/kibana-siem/cypress/results/output.json --reportDir ../../../target/kibana-siem/cypress/results; mkdir -p ../../../target/junit && cp ../../../target/kibana-siem/cypress/results/*.xml ../../../target/junit/ && exit $status;",
|
||||
"cypress:run": "cypress run --browser chrome --headless --spec ./cypress/integration/**/*.spec.ts --config-file ./cypress/cypress.json --reporter ../../node_modules/cypress-multi-reporters --reporter-options configFile=./cypress/reporter_config.json; status=$?; ../../node_modules/.bin/mochawesome-merge --reportDir ../../../target/kibana-siem/cypress/results > ../../../target/kibana-siem/cypress/results/output.json; ../../../node_modules/.bin/marge ../../../target/kibana-siem/cypress/results/output.json --reportDir ../../../target/kibana-siem/cypress/results; mkdir -p ../../../target/junit && cp ../../../target/kibana-siem/cypress/results/*.xml ../../../target/junit/ && exit $status;",
|
||||
"cypress:run-as-ci": "node ../../../scripts/functional_tests --config ../../test/siem_cypress/config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -62,6 +62,7 @@ export const getActions = (
|
|||
},
|
||||
},
|
||||
{
|
||||
'data-test-subj': 'exportRuleAction',
|
||||
description: i18n.EXPORT_RULE,
|
||||
icon: 'exportAction',
|
||||
name: i18n.EXPORT_RULE,
|
||||
|
|
Loading…
Reference in a new issue