@@ -7,6 +7,10 @@ import {
7
7
NODE_API ,
8
8
OPENSEARCH_DASHBOARDS_URL ,
9
9
} from '../../../utils/plugins/security-analytics-dashboards-plugin/constants' ;
10
+ import {
11
+ getLogTypeLabel ,
12
+ setupIntercept ,
13
+ } from '../../../utils/plugins/security-analytics-dashboards-plugin/helpers' ;
10
14
import sample_windows_index_settings from '../../../fixtures/plugins/security-analytics-dashboards-plugin/sample_windows_index_settings.json' ;
11
15
import sample_dns_index_settings from '../../../fixtures/plugins/security-analytics-dashboards-plugin/sample_dns_index_settings.json' ;
12
16
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';
18
22
const cypressIndexWindows = 'cypress-index-windows' ;
19
23
const detectorName = 'test detector' ;
20
24
const cypressLogTypeDns = 'dns' ;
25
+ const creationFailedMessage = 'Create detector failed.' ;
21
26
22
27
const cypressDNSRule = dns_name_rule_data . title ;
23
28
@@ -39,7 +44,7 @@ const dataSourceLabel = 'Select or input source indexes or index patterns';
39
44
40
45
const getDataSourceField = ( ) => cy . sa_getFieldByLabel ( dataSourceLabel ) ;
41
46
42
- const logTypeLabel = 'Select a log type you would like to detect ' ;
47
+ const logTypeLabel = 'Log type' ;
43
48
44
49
const getLogTypeField = ( ) => cy . sa_getFieldByLabel ( logTypeLabel ) ;
45
50
@@ -133,25 +138,39 @@ const validatePendingFieldMappingsPanel = (mappings) => {
133
138
} ) ;
134
139
} ;
135
140
136
- const fillDetailsForm = ( detectorName , dataSource ) => {
141
+ const fillDetailsForm = (
142
+ detectorName ,
143
+ dataSource ,
144
+ isCustomDataSource = false
145
+ ) => {
137
146
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
+
139
156
getDataSourceField ( ) . focus ( ) . blur ( ) ;
140
- getLogTypeField ( ) . sa_selectComboboxItem ( cypressLogTypeDns ) ;
157
+ getLogTypeField ( ) . sa_selectComboboxItem ( getLogTypeLabel ( cypressLogTypeDns ) ) ;
141
158
getLogTypeField ( ) . focus ( ) . blur ( ) ;
142
159
} ;
143
160
144
161
const createDetector = ( detectorName , dataSource , expectFailure ) => {
145
162
getCreateDetectorButton ( ) . click ( { force : true } ) ;
146
163
147
- fillDetailsForm ( detectorName , dataSource ) ;
164
+ fillDetailsForm ( detectorName , dataSource , expectFailure ) ;
148
165
149
166
cy . sa_getElementByText (
150
167
'.euiAccordion .euiTitle' ,
151
- 'Detection rules (14 selected )'
168
+ 'Selected detection rules (14)'
152
169
)
153
170
. click ( { force : true , timeout : 5000 } )
154
- . then ( ( ) => cy . contains ( '.euiTable .euiTableRow' , 'Dns' ) ) ;
171
+ . then ( ( ) =>
172
+ cy . contains ( '.euiTable .euiTableRow' , getLogTypeLabel ( cypressLogTypeDns ) )
173
+ ) ;
155
174
156
175
cy . sa_getElementByText ( '.euiAccordion .euiTitle' , 'Field mapping - optional' ) ;
157
176
cy . get ( '[aria-controls="mappedTitleFieldsAccordion"]' ) . then ( ( $btn ) => {
@@ -168,21 +187,14 @@ const createDetector = (detectorName, dataSource, expectFailure) => {
168
187
// Open the trigger details accordion
169
188
cy . get ( '[data-test-subj="trigger-details-btn"]' ) . click ( { force : true } ) ;
170
189
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' ) ;
174
190
cy . sa_getElementByTestSubject ( 'alert-tags-combo-box' )
175
191
. type ( `attack.defense_evasion{enter}` )
176
192
. find ( 'input' )
177
193
. focus ( )
178
194
. blur ( ) ;
179
195
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' ) ;
186
198
187
199
// create the detector
188
200
cy . sa_getElementByText ( 'button' , 'Create' ) . click ( { force : true } ) ;
@@ -197,11 +209,6 @@ const createDetector = (detectorName, dataSource, expectFailure) => {
197
209
cy . url ( )
198
210
. should ( 'contain' , detectorId )
199
211
. then ( ( ) => {
200
- cy . sa_getElementByText (
201
- '.euiCallOut' ,
202
- `Detector created successfully: ${ detectorName } `
203
- ) ;
204
-
205
212
// Confirm detector state
206
213
cy . sa_getElementByText ( '.euiTitle' , detectorName ) ;
207
214
cy . sa_getElementByText ( '.euiHealth' , 'Active' ) . then ( ( ) => {
@@ -217,7 +224,7 @@ const createDetector = (detectorName, dataSource, expectFailure) => {
217
224
cy . wait ( 5000 ) ; // waiting for the page to be reloaded after pushing detector id into route
218
225
cy . sa_getElementByText ( 'button.euiTab' , 'Alert triggers' )
219
226
. should ( 'be.visible' )
220
- . click ( ) ;
227
+ . click ( { force : true } ) ;
221
228
validateAlertPanel ( 'Trigger 1' ) ;
222
229
} ) ;
223
230
} ) ;
@@ -265,7 +272,7 @@ describe('Detectors', () => {
265
272
266
273
describe ( '...should validate form fields' , ( ) => {
267
274
beforeEach ( ( ) => {
268
- cy . intercept ( NODE_API . SEARCH_DETECTORS ) . as ( 'detectorsSearch' ) ;
275
+ setupIntercept ( cy , NODE_API . SEARCH_DETECTORS , 'detectorsSearch' ) ;
269
276
270
277
// Visit Detectors page before any test
271
278
cy . visit ( `${ OPENSEARCH_DASHBOARDS_URL } /detectors` ) ;
@@ -414,9 +421,7 @@ describe('Detectors', () => {
414
421
415
422
describe ( '...validate create detector flow' , ( ) => {
416
423
beforeEach ( ( ) => {
417
- cy . intercept ( NODE_API . SEARCH_DETECTORS )
418
- . as ( 'detectorsSearch' )
419
- . as ( 'detectorsSearch' ) ;
424
+ setupIntercept ( cy , NODE_API . SEARCH_DETECTORS , 'detectorsSearch' ) ;
420
425
421
426
// Visit Detectors page before any test
422
427
cy . visit ( `${ OPENSEARCH_DASHBOARDS_URL } /detectors` ) ;
@@ -425,16 +430,16 @@ describe('Detectors', () => {
425
430
426
431
it ( '...can fail creation' , ( ) => {
427
432
createDetector ( `${ detectorName } _fail` , '.kibana_1' , true ) ;
428
- cy . sa_getElementByText ( '.euiCallOut' , 'Create detector failed.' ) ;
433
+ cy . sa_getElementByText ( '.euiCallOut' , creationFailedMessage ) ;
429
434
} ) ;
430
435
431
436
it ( '...can be created' , ( ) => {
432
437
createDetector ( detectorName , cypressIndexDns , false ) ;
433
- cy . sa_getElementByText ( '.euiCallOut' , 'Detector created successfully ') ;
438
+ cy . contains ( creationFailedMessage ) . should ( 'not.exist ') ;
434
439
} ) ;
435
440
436
441
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 ') ;
438
443
openDetectorDetails ( detectorName ) ;
439
444
440
445
editDetectorDetails ( detectorName , 'Detector details' ) ;
@@ -494,10 +499,13 @@ describe('Detectors', () => {
494
499
} ) ;
495
500
496
501
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' ) ;
501
509
openDetectorDetails ( detectorName ) ;
502
510
503
511
editDetectorDetails ( detectorName , 'Detector details' ) ;
@@ -519,9 +527,7 @@ describe('Detectors', () => {
519
527
} ) ;
520
528
521
529
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' ) ;
525
531
526
532
openDetectorDetails ( detectorName ) ;
527
533
@@ -544,22 +550,16 @@ describe('Detectors', () => {
544
550
} ) ;
545
551
546
552
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' ) ;
553
554
openDetectorDetails ( detectorName ) ;
554
555
555
556
cy . wait ( '@detectorsSearch' ) ;
556
- cy . wait ( '@getCustomRules' ) ;
557
557
cy . wait ( '@getSigmaRules' ) ;
558
558
559
559
cy . sa_getButtonByText ( 'Actions' )
560
560
. click ( { force : true } )
561
561
. then ( ( ) => {
562
- cy . intercept ( `${ NODE_API . DETECTORS_BASE } /_search` ) . as ( 'detectors' ) ;
562
+ setupIntercept ( cy , `${ NODE_API . DETECTORS_BASE } /_search` , 'detectors' ) ;
563
563
cy . sa_getElementByText ( '.euiContextMenuItem' , 'Delete' ) . click ( {
564
564
force : true ,
565
565
} ) ;
0 commit comments