Skip to content

Commit 2b7b556

Browse files
amsiglangithub-actions[bot]
authored andcommitted
[2.12] Update security analytics tests (#1085)
* updated tests Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com> * updated tests Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com> * updated tests Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com> * updated intercepts Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com> * fixed lint errors Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com> * updated tests Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com> * fixed incorrect intercept setup Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com> * updated rules test Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com> --------- Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com> (cherry picked from commit 14400ed)
1 parent 34a2630 commit 2b7b556

File tree

6 files changed

+127
-141
lines changed

6 files changed

+127
-141
lines changed

cypress/integration/plugins/security-analytics-dashboards-plugin/1_detectors.spec.js

+44-44
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import {
77
NODE_API,
88
OPENSEARCH_DASHBOARDS_URL,
99
} from '../../../utils/plugins/security-analytics-dashboards-plugin/constants';
10+
import {
11+
getLogTypeLabel,
12+
setupIntercept,
13+
} from '../../../utils/plugins/security-analytics-dashboards-plugin/helpers';
1014
import sample_windows_index_settings from '../../../fixtures/plugins/security-analytics-dashboards-plugin/sample_windows_index_settings.json';
1115
import sample_dns_index_settings from '../../../fixtures/plugins/security-analytics-dashboards-plugin/sample_dns_index_settings.json';
1216
import dns_name_rule_data from '../../../fixtures/plugins/security-analytics-dashboards-plugin/integration_tests/rule/create_dns_rule_with_name_selection.json';
@@ -18,6 +22,7 @@ const cypressIndexDns = 'cypress-index-dns';
1822
const cypressIndexWindows = 'cypress-index-windows';
1923
const detectorName = 'test detector';
2024
const cypressLogTypeDns = 'dns';
25+
const creationFailedMessage = 'Create detector failed.';
2126

2227
const cypressDNSRule = dns_name_rule_data.title;
2328

@@ -39,7 +44,7 @@ const dataSourceLabel = 'Select or input source indexes or index patterns';
3944

4045
const getDataSourceField = () => cy.sa_getFieldByLabel(dataSourceLabel);
4146

42-
const logTypeLabel = 'Select a log type you would like to detect';
47+
const logTypeLabel = 'Log type';
4348

4449
const getLogTypeField = () => cy.sa_getFieldByLabel(logTypeLabel);
4550

@@ -133,25 +138,39 @@ const validatePendingFieldMappingsPanel = (mappings) => {
133138
});
134139
};
135140

136-
const fillDetailsForm = (detectorName, dataSource) => {
141+
const fillDetailsForm = (
142+
detectorName,
143+
dataSource,
144+
isCustomDataSource = false
145+
) => {
137146
getNameField().type(detectorName);
138-
getDataSourceField().sa_selectComboboxItem(dataSource);
147+
148+
if (isCustomDataSource) {
149+
getDataSourceField()
150+
.focus()
151+
.type(dataSource + '{enter}');
152+
} else {
153+
getDataSourceField().sa_selectComboboxItem(dataSource);
154+
}
155+
139156
getDataSourceField().focus().blur();
140-
getLogTypeField().sa_selectComboboxItem(cypressLogTypeDns);
157+
getLogTypeField().sa_selectComboboxItem(getLogTypeLabel(cypressLogTypeDns));
141158
getLogTypeField().focus().blur();
142159
};
143160

144161
const createDetector = (detectorName, dataSource, expectFailure) => {
145162
getCreateDetectorButton().click({ force: true });
146163

147-
fillDetailsForm(detectorName, dataSource);
164+
fillDetailsForm(detectorName, dataSource, expectFailure);
148165

149166
cy.sa_getElementByText(
150167
'.euiAccordion .euiTitle',
151-
'Detection rules (14 selected)'
168+
'Selected detection rules (14)'
152169
)
153170
.click({ force: true, timeout: 5000 })
154-
.then(() => cy.contains('.euiTable .euiTableRow', 'Dns'));
171+
.then(() =>
172+
cy.contains('.euiTable .euiTableRow', getLogTypeLabel(cypressLogTypeDns))
173+
);
155174

156175
cy.sa_getElementByText('.euiAccordion .euiTitle', 'Field mapping - optional');
157176
cy.get('[aria-controls="mappedTitleFieldsAccordion"]').then(($btn) => {
@@ -168,21 +187,14 @@ const createDetector = (detectorName, dataSource, expectFailure) => {
168187
// Open the trigger details accordion
169188
cy.get('[data-test-subj="trigger-details-btn"]').click({ force: true });
170189
cy.sa_getElementByText('.euiTitle.euiTitle--medium', 'Set up alert triggers');
171-
cy.sa_getInputByPlaceholder(
172-
'Enter a name to describe the alert condition'
173-
).type('test_trigger');
174190
cy.sa_getElementByTestSubject('alert-tags-combo-box')
175191
.type(`attack.defense_evasion{enter}`)
176192
.find('input')
177193
.focus()
178194
.blur();
179195

180-
cy.sa_getFieldByLabel('Specify alert severity').sa_selectComboboxItem(
181-
'1 (Highest)'
182-
);
183-
184-
cy.intercept('POST', NODE_API.MAPPINGS_BASE).as('createMappingsRequest');
185-
cy.intercept('POST', NODE_API.DETECTORS_BASE).as('createDetectorRequest');
196+
setupIntercept(cy, NODE_API.MAPPINGS_BASE, 'createMappingsRequest');
197+
setupIntercept(cy, NODE_API.DETECTORS_BASE, 'createDetectorRequest');
186198

187199
// create the detector
188200
cy.sa_getElementByText('button', 'Create').click({ force: true });
@@ -197,11 +209,6 @@ const createDetector = (detectorName, dataSource, expectFailure) => {
197209
cy.url()
198210
.should('contain', detectorId)
199211
.then(() => {
200-
cy.sa_getElementByText(
201-
'.euiCallOut',
202-
`Detector created successfully: ${detectorName}`
203-
);
204-
205212
// Confirm detector state
206213
cy.sa_getElementByText('.euiTitle', detectorName);
207214
cy.sa_getElementByText('.euiHealth', 'Active').then(() => {
@@ -217,7 +224,7 @@ const createDetector = (detectorName, dataSource, expectFailure) => {
217224
cy.wait(5000); // waiting for the page to be reloaded after pushing detector id into route
218225
cy.sa_getElementByText('button.euiTab', 'Alert triggers')
219226
.should('be.visible')
220-
.click();
227+
.click({ force: true });
221228
validateAlertPanel('Trigger 1');
222229
});
223230
});
@@ -265,7 +272,7 @@ describe('Detectors', () => {
265272

266273
describe('...should validate form fields', () => {
267274
beforeEach(() => {
268-
cy.intercept(NODE_API.SEARCH_DETECTORS).as('detectorsSearch');
275+
setupIntercept(cy, NODE_API.SEARCH_DETECTORS, 'detectorsSearch');
269276

270277
// Visit Detectors page before any test
271278
cy.visit(`${OPENSEARCH_DASHBOARDS_URL}/detectors`);
@@ -414,9 +421,7 @@ describe('Detectors', () => {
414421

415422
describe('...validate create detector flow', () => {
416423
beforeEach(() => {
417-
cy.intercept(NODE_API.SEARCH_DETECTORS)
418-
.as('detectorsSearch')
419-
.as('detectorsSearch');
424+
setupIntercept(cy, NODE_API.SEARCH_DETECTORS, 'detectorsSearch');
420425

421426
// Visit Detectors page before any test
422427
cy.visit(`${OPENSEARCH_DASHBOARDS_URL}/detectors`);
@@ -425,16 +430,16 @@ describe('Detectors', () => {
425430

426431
it('...can fail creation', () => {
427432
createDetector(`${detectorName}_fail`, '.kibana_1', true);
428-
cy.sa_getElementByText('.euiCallOut', 'Create detector failed.');
433+
cy.sa_getElementByText('.euiCallOut', creationFailedMessage);
429434
});
430435

431436
it('...can be created', () => {
432437
createDetector(detectorName, cypressIndexDns, false);
433-
cy.sa_getElementByText('.euiCallOut', 'Detector created successfully');
438+
cy.contains(creationFailedMessage).should('not.exist');
434439
});
435440

436441
it('...basic details can be edited', () => {
437-
cy.intercept('GET', NODE_API.INDICES_BASE).as('getIndices');
442+
setupIntercept(cy, NODE_API.INDICES_BASE, 'getIndices', 'GET');
438443
openDetectorDetails(detectorName);
439444

440445
editDetectorDetails(detectorName, 'Detector details');
@@ -494,10 +499,13 @@ describe('Detectors', () => {
494499
});
495500

496501
xit('...should update field mappings if data source is changed', () => {
497-
cy.intercept(
498-
`${NODE_API.MAPPINGS_VIEW}?indexName=cypress-index-dns&ruleTopic=dns`
499-
).as('getMappingsView');
500-
cy.intercept('GET', NODE_API.INDICES_BASE).as('getIndices');
502+
setupIntercept(
503+
cy,
504+
`${NODE_API.MAPPINGS_VIEW}?indexName=cypress-index-dns&ruleTopic=dns`,
505+
'getMappingsView',
506+
'GET'
507+
);
508+
setupIntercept(cy, NODE_API.INDICES_BASE, 'getIndices', 'GET');
501509
openDetectorDetails(detectorName);
502510

503511
editDetectorDetails(detectorName, 'Detector details');
@@ -519,9 +527,7 @@ describe('Detectors', () => {
519527
});
520528

521529
xit('...should show field mappings if rule selection is changed', () => {
522-
cy.intercept(
523-
`${NODE_API.MAPPINGS_VIEW}?indexName=cypress-index-windows&ruleTopic=dns`
524-
).as('getMappingsView');
530+
setupIntercept(cy, `${NODE_API.MAPPINGS_VIEW}`, 'getMappingsView', 'GET');
525531

526532
openDetectorDetails(detectorName);
527533

@@ -544,22 +550,16 @@ describe('Detectors', () => {
544550
});
545551

546552
it('...can be deleted', () => {
547-
cy.intercept(`${NODE_API.RULES_BASE}/_search?prePackaged=true`).as(
548-
'getSigmaRules'
549-
);
550-
cy.intercept(`${NODE_API.RULES_BASE}/_search?prePackaged=false`).as(
551-
'getCustomRules'
552-
);
553+
setupIntercept(cy, `${NODE_API.RULES_BASE}/_search`, 'getSigmaRules');
553554
openDetectorDetails(detectorName);
554555

555556
cy.wait('@detectorsSearch');
556-
cy.wait('@getCustomRules');
557557
cy.wait('@getSigmaRules');
558558

559559
cy.sa_getButtonByText('Actions')
560560
.click({ force: true })
561561
.then(() => {
562-
cy.intercept(`${NODE_API.DETECTORS_BASE}/_search`).as('detectors');
562+
setupIntercept(cy, `${NODE_API.DETECTORS_BASE}/_search`, 'detectors');
563563
cy.sa_getElementByText('.euiContextMenuItem', 'Delete').click({
564564
force: true,
565565
});

0 commit comments

Comments
 (0)