3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
- import { PLUGIN_NAME } from '../support/constants' ;
6
+ import { OPENSEARCH_DASHBOARDS_URL } from '../support/constants' ;
7
7
import sample_field_mappings from '../fixtures/sample_field_mappings.json' ;
8
8
import sample_index_settings from '../fixtures/sample_index_settings.json' ;
9
9
10
10
describe ( 'Detectors' , ( ) => {
11
11
const indexName = 'cypress-test-windows' ;
12
+ const detectorName = 'test detector' ;
12
13
13
14
before ( ( ) => {
14
- cy . deleteAllIndices ( ) ;
15
+ cy . cleanUpTests ( ) ;
15
16
16
17
// Create test index
17
18
cy . createIndex ( indexName , sample_index_settings ) ;
18
19
19
- cy . contains ( 'test detector' ) . should ( 'not.exist' ) ;
20
+ cy . contains ( detectorName ) . should ( 'not.exist' ) ;
20
21
} ) ;
21
22
22
23
beforeEach ( ( ) => {
23
24
// Visit Detectors page
24
- cy . visit ( `${ Cypress . env ( 'opensearch_dashboards' ) } /app/${ PLUGIN_NAME } #/detectors` ) ;
25
-
26
- //wait for page to load
27
- cy . wait ( 7000 ) ;
25
+ cy . visit ( `${ OPENSEARCH_DASHBOARDS_URL } /detectors` ) ;
28
26
29
27
// Check that correct page is showing
30
- cy . url ( ) . should (
31
- 'eq' ,
32
- 'http://localhost:5601/app/opensearch_security_analytics_dashboards#/detectors'
33
- ) ;
28
+ cy . waitForPageLoad ( 'detectors' , {
29
+ contains : 'Threat detectors' ,
30
+ } ) ;
34
31
} ) ;
35
32
36
33
it ( '...can be created' , ( ) => {
37
34
// Locate Create detector button click to start
38
35
cy . contains ( 'Create detector' ) . click ( { force : true } ) ;
39
36
40
37
// Check to ensure process started
41
- cy . contains ( 'Define detector' ) ;
42
- cy . url ( ) . should (
43
- 'eq' ,
44
- 'http://localhost:5601/app/opensearch_security_analytics_dashboards#/create-detector'
45
- ) ;
38
+ cy . waitForPageLoad ( 'create-detector' , {
39
+ contains : 'Define detector' ,
40
+ } ) ;
46
41
47
42
// Enter a name for the detector in the appropriate input
48
43
cy . get ( `input[placeholder="Enter a name for the detector."]` ) . type ( 'test detector{enter}' ) ;
49
44
50
- // Select our pre-seeded data source (cypress-test-windows)
51
- cy . get ( `[data-test-subj="define-detector-select-data-source"]` ) . type (
52
- 'cypress-test-windows{enter}'
53
- ) ;
45
+ // Select our pre-seeded data source (check indexName)
46
+ cy . get ( `[data-test-subj="define-detector-select-data-source"]` ) . type ( `${ indexName } {enter}` ) ;
54
47
55
48
// Select threat detector type (Windows logs)
56
49
cy . get ( `input[id="windows"]` ) . click ( { force : true } ) ;
@@ -59,7 +52,7 @@ describe('Detectors', () => {
59
52
cy . get ( '[data-test-subj="detection-rules-btn"]' ) . click ( { timeout : 5000 } ) ;
60
53
61
54
// find search, type USB
62
- cy . get ( `[placeholder=" Search..."]` ) . type ( ' USB Device Plugged' ) . trigger ( 'search ') ;
55
+ cy . triggerSearchField ( ' Search...' , ' USB Device Plugged') ;
63
56
64
57
// Disable all rules
65
58
cy . contains ( 'tr' , 'USB Device Plugged' , { timeout : 20000 } ) ;
@@ -121,21 +114,23 @@ describe('Detectors', () => {
121
114
122
115
// Confirm entries user has made
123
116
cy . contains ( 'Detector details' ) ;
124
- cy . contains ( 'test detector' ) ;
117
+ cy . contains ( detectorName ) ;
125
118
cy . contains ( 'windows' ) ;
126
119
cy . contains ( indexName ) ;
127
120
cy . contains ( 'Alert on test_trigger' ) ;
128
121
129
122
// Create the detector
130
123
cy . get ( 'button' ) . contains ( 'Create' ) . click ( { force : true } ) ;
131
-
132
- cy . wait ( 10000 ) ;
124
+ cy . waitForPageLoad ( 'detector-details' , {
125
+ contains : detectorName ,
126
+ } ) ;
133
127
134
128
// Confirm detector active
135
- cy . contains ( 'There are no existing detectors.' , { timeout : 20000 } ) . should ( 'not.exist' ) ;
136
- cy . contains ( 'test detector' ) ;
129
+ cy . contains ( detectorName ) ;
137
130
cy . contains ( 'Active' ) ;
131
+ cy . contains ( 'View Alerts' ) ;
138
132
cy . contains ( 'View Findings' ) ;
133
+ cy . contains ( 'Actions' ) ;
139
134
cy . contains ( 'Detector configuration' ) ;
140
135
cy . contains ( 'Field mappings' ) ;
141
136
cy . contains ( 'Alert triggers' ) ;
@@ -146,21 +141,19 @@ describe('Detectors', () => {
146
141
147
142
it ( '...basic details can be edited' , ( ) => {
148
143
// Click on detector name
149
- cy . contains ( 'test detector' ) . click ( { force : true } ) ;
150
-
151
- // Confirm on detector details page
152
- cy . contains ( 'test detector' ) ;
144
+ cy . contains ( detectorName ) . click ( { force : true } ) ;
145
+ cy . waitForPageLoad ( 'detector-details' , {
146
+ contains : detectorName ,
147
+ } ) ;
153
148
154
149
// Click "Edit" button in detector details
155
150
cy . get ( `[data-test-subj="edit-detector-basic-details"]` ) . click ( { force : true } ) ;
156
151
157
152
// Confirm arrival at "Edit detector details" page
158
- cy . url ( ) . should (
159
- 'include' ,
160
- 'http://localhost:5601/app/opensearch_security_analytics_dashboards#/edit-detector-details'
161
- ) ;
153
+ cy . waitForPageLoad ( 'edit-detector-details' , {
154
+ contains : 'Edit detector details' ,
155
+ } ) ;
162
156
163
- cy . wait ( 5000 ) ;
164
157
// Change detector name
165
158
cy . get ( `[data-test-subj="define-detector-detector-name"]` ) . type ( '_edited' ) ;
166
159
@@ -173,18 +166,16 @@ describe('Detectors', () => {
173
166
) ;
174
167
175
168
// Change detector scheduling
176
- cy . get ( `[data-test-subj="detector-schedule-number-select"]` ) . type ( '0 ' ) ;
169
+ cy . get ( `[data-test-subj="detector-schedule-number-select"]` ) . type ( '{selectall}10 ' ) ;
177
170
cy . get ( `[data-test-subj="detector-schedule-unit-select"]` ) . select ( 'Hours' ) ;
178
171
179
- cy . wait ( 7000 ) ;
180
172
// Save changes to detector details
181
173
cy . get ( `[data-test-subj="save-basic-details-edits"]` ) . click ( { force : true } ) ;
182
174
183
175
// Confirm taken to detector details page
184
- cy . url ( { timeout : 20000 } ) . should (
185
- 'include' ,
186
- 'http://localhost:5601/app/opensearch_security_analytics_dashboards#/detector-details'
187
- ) ;
176
+ cy . waitForPageLoad ( 'detector-details' , {
177
+ contains : detectorName ,
178
+ } ) ;
188
179
189
180
// Verify edits are applied
190
181
cy . contains ( 'test detector_edited' ) ;
@@ -195,13 +186,15 @@ describe('Detectors', () => {
195
186
196
187
it ( '...rules can be edited' , ( ) => {
197
188
// Ensure start on main detectors page
198
- cy . url ( ) . should (
199
- 'eq' ,
200
- 'http://localhost:5601/app/opensearch_security_analytics_dashboards#/detectors'
201
- ) ;
189
+ cy . waitForPageLoad ( 'detectors' , {
190
+ contains : 'Threat detectors' ,
191
+ } ) ;
202
192
203
193
// Click on detector name
204
- cy . contains ( 'test detector' ) . click ( { force : true } ) ;
194
+ cy . contains ( detectorName ) . click ( { force : true } ) ;
195
+ cy . waitForPageLoad ( 'detector-details' , {
196
+ contains : detectorName ,
197
+ } ) ;
205
198
206
199
// Confirm number of rules before edit
207
200
cy . contains ( 'Active rules (1)' ) ;
@@ -216,7 +209,7 @@ describe('Detectors', () => {
216
209
) ;
217
210
218
211
// Search for specific rule
219
- cy . get ( `[placeholder=" Search..."]` ) . type ( ' USB Device') . trigger ( 'search' , { timeout : 5000 } ) ;
212
+ cy . triggerSearchField ( ' Search...' , ' USB Device') ;
220
213
221
214
// Toggle single search result to unchecked
222
215
cy . contains ( 'tr' , 'USB Device Plugged' ) . within ( ( ) => {
@@ -235,13 +228,12 @@ describe('Detectors', () => {
235
228
cy . get ( `[data-test-subj="edit-detector-rules"]` ) . click ( { force : true } ) ;
236
229
237
230
// Confirm arrival on "Edit detector rules" page
238
- cy . url ( ) . should (
239
- 'include' ,
240
- 'http://localhost:5601/app/opensearch_security_analytics_dashboards#/edit-detector-rules'
241
- ) ;
231
+ cy . waitForPageLoad ( 'edit-detector-rules' , {
232
+ contains : 'Edit detector rules' ,
233
+ } ) ;
242
234
243
235
// Search for specific rule
244
- cy . get ( `[placeholder=" Search..."]` ) . focus ( ) . type ( 'USB' ) . trigger ( 'search' , { timeout : 5000 } ) ;
236
+ cy . triggerSearchField ( ' Search...' , 'USB' ) ;
245
237
246
238
// Toggle single search result to checked
247
239
cy . contains ( 'tr' , 'USB Device Plugged' ) . within ( ( ) => {
@@ -251,6 +243,9 @@ describe('Detectors', () => {
251
243
252
244
// Save changes
253
245
cy . get ( `[data-test-subj="save-detector-rules-edits"]` ) . click ( { force : true } ) ;
246
+ cy . waitForPageLoad ( 'detector-details' , {
247
+ contains : detectorName ,
248
+ } ) ;
254
249
255
250
// Confirm 1 rule has been added to detector
256
251
cy . contains ( 'Active rules (1)' ) ;
@@ -261,7 +256,9 @@ describe('Detectors', () => {
261
256
cy . contains ( 'test detector_edited' ) . click ( { force : true } ) ;
262
257
263
258
// Confirm page
264
- cy . contains ( 'Detector details' ) ;
259
+ cy . waitForPageLoad ( 'detector-details' , {
260
+ contains : 'Detector details' ,
261
+ } ) ;
265
262
266
263
// Click "Actions" button, the click "Delete"
267
264
cy . contains ( 'Actions' ) . click ( { force : true } ) ;
@@ -270,4 +267,6 @@ describe('Detectors', () => {
270
267
// Confirm detector is deleted
271
268
cy . contains ( 'There are no existing detectors' ) ;
272
269
} ) ;
270
+
271
+ after ( ( ) => cy . cleanUpTests ( ) ) ;
273
272
} ) ;
0 commit comments