@@ -48,11 +48,93 @@ const YAML_RULE_LINES = [
48
48
...SAMPLE_RULE . detection . replaceAll ( ' ' , '' ) . replaceAll ( '{backspace}' , '' ) . split ( '\n' ) ,
49
49
] ;
50
50
51
+ const checkRulesFlyout = ( ) => {
52
+ // Search for the rule
53
+ cy . get ( `input[placeholder="Search rules"]` ) . ospSearch ( SAMPLE_RULE . name ) ;
54
+
55
+ // Click the rule link to open the details flyout
56
+ cy . get ( `[data-test-subj="rule_link_${ SAMPLE_RULE . name } "]` ) . click ( { force : true } ) ;
57
+
58
+ // Confirm the flyout contains the expected values
59
+ cy . get ( `[data-test-subj="rule_flyout_${ SAMPLE_RULE . name } "]` )
60
+ . click ( { force : true } )
61
+ . within ( ( ) => {
62
+ // Validate name
63
+ cy . get ( '[data-test-subj="rule_flyout_rule_name"]' ) . contains ( SAMPLE_RULE . name ) ;
64
+
65
+ // Validate log type
66
+ cy . get ( '[data-test-subj="rule_flyout_rule_log_type"]' ) . contains ( SAMPLE_RULE . logType ) ;
67
+
68
+ // Validate description
69
+ cy . get ( '[data-test-subj="rule_flyout_rule_description"]' ) . contains ( SAMPLE_RULE . description ) ;
70
+
71
+ // Validate author
72
+ cy . get ( '[data-test-subj="rule_flyout_rule_author"]' ) . contains ( SAMPLE_RULE . author ) ;
73
+
74
+ // Validate source is "custom"
75
+ cy . get ( '[data-test-subj="rule_flyout_rule_source"]' ) . contains ( 'Custom' ) ;
76
+
77
+ // Validate severity
78
+ cy . get ( '[data-test-subj="rule_flyout_rule_severity"]' ) . contains ( SAMPLE_RULE . severity ) ;
79
+
80
+ // Validate tags
81
+ SAMPLE_RULE . tags . forEach ( ( tag ) =>
82
+ cy . get ( '[data-test-subj="rule_flyout_rule_tags"]' ) . contains ( tag )
83
+ ) ;
84
+
85
+ // Validate references
86
+ cy . get ( '[data-test-subj="rule_flyout_rule_references"]' ) . contains ( SAMPLE_RULE . references ) ;
87
+
88
+ // Validate false positives
89
+ cy . get ( '[data-test-subj="rule_flyout_rule_false_positives"]' ) . contains (
90
+ SAMPLE_RULE . falsePositive
91
+ ) ;
92
+
93
+ // Validate status
94
+ cy . get ( '[data-test-subj="rule_flyout_rule_status"]' ) . contains ( SAMPLE_RULE . status ) ;
95
+
96
+ // Validate detection
97
+ SAMPLE_RULE . detectionLine . forEach ( ( line ) =>
98
+ cy . get ( '[data-test-subj="rule_flyout_rule_detection"]' ) . contains ( line )
99
+ ) ;
100
+
101
+ cy . get ( '[data-test-subj="change-editor-type"] label:nth-child(2)' ) . click ( {
102
+ force : true ,
103
+ } ) ;
104
+
105
+ cy . get ( '[data-test-subj="rule_flyout_yaml_rule"]' )
106
+ . get ( '[class="euiCodeBlock__line"]' )
107
+ . each ( ( lineElement , lineIndex ) => {
108
+ if ( lineIndex >= YAML_RULE_LINES . length ) {
109
+ return ;
110
+ }
111
+ let line = lineElement . text ( ) . replaceAll ( '\n' , '' ) . trim ( ) ;
112
+ let expectedLine = YAML_RULE_LINES [ lineIndex ] ;
113
+
114
+ // The document ID field is generated when the document is added to the index,
115
+ // so this test just checks that the line starts with the ID key.
116
+ if ( expectedLine . startsWith ( 'id:' ) ) {
117
+ expectedLine = 'id:' ;
118
+ expect ( line , `Sigma rule line ${ lineIndex } ` ) . to . contain ( expectedLine ) ;
119
+ } else {
120
+ expect ( line , `Sigma rule line ${ lineIndex } ` ) . to . equal ( expectedLine ) ;
121
+ }
122
+ } ) ;
123
+
124
+ // Close the flyout
125
+ cy . get ( '[data-test-subj="close-rule-details-flyout"]' ) . click ( {
126
+ force : true ,
127
+ } ) ;
128
+ } ) ;
129
+ } ;
130
+
51
131
describe ( 'Rules' , ( ) => {
52
132
before ( ( ) => cy . cleanUpTests ( ) ) ;
53
133
beforeEach ( ( ) => {
134
+ cy . intercept ( '/rules/_search' ) . as ( 'rulesSearch' ) ;
54
135
// Visit Rules page
55
136
cy . visit ( `${ OPENSEARCH_DASHBOARDS_URL } /rules` ) ;
137
+ cy . wait ( '@rulesSearch' ) . should ( 'have.property' , 'state' , 'Complete' ) ;
56
138
57
139
// Check that correct page is showing
58
140
cy . waitForPageLoad ( 'rules' , {
@@ -114,89 +196,73 @@ describe('Rules', () => {
114
196
force : true ,
115
197
} ) ;
116
198
199
+ cy . wait ( '@getRules' ) ;
200
+
117
201
cy . waitForPageLoad ( 'rules' , {
118
202
contains : 'Rules' ,
119
203
} ) ;
120
204
121
- cy . wait ( '@getRules' ) ;
205
+ checkRulesFlyout ( ) ;
206
+ } ) ;
122
207
123
- // Search for the rule
124
- cy . get ( `input[placeholder="Search rules"]` ) . ospSearch ( SAMPLE_RULE . name ) ;
208
+ it ( '...can be edited' , ( ) => {
209
+ cy . waitForPageLoad ( 'rules' , {
210
+ contains : 'Rules' ,
211
+ } ) ;
125
212
126
- // Click the rule link to open the details flyout
213
+ cy . get ( `input[placeholder="Search rules"]` ) . ospSearch ( SAMPLE_RULE . name ) ;
127
214
cy . get ( `[data-test-subj="rule_link_${ SAMPLE_RULE . name } "]` ) . click ( { force : true } ) ;
128
215
129
- // Confirm the flyout contains the expected values
130
216
cy . get ( `[data-test-subj="rule_flyout_${ SAMPLE_RULE . name } "]` )
217
+ . find ( 'button' )
218
+ . contains ( 'Action' )
131
219
. click ( { force : true } )
132
- . within ( ( ) => {
133
- // Validate name
134
- cy . get ( '[data-test-subj="rule_flyout_rule_name"]' ) . contains ( SAMPLE_RULE . name ) ;
135
-
136
- // Validate log type
137
- cy . get ( '[data-test-subj="rule_flyout_rule_log_type"]' ) . contains ( SAMPLE_RULE . logType ) ;
138
-
139
- // Validate description
140
- cy . get ( '[data-test-subj="rule_flyout_rule_description"]' ) . contains ( SAMPLE_RULE . description ) ;
141
-
142
- // Validate author
143
- cy . get ( '[data-test-subj="rule_flyout_rule_author"]' ) . contains ( SAMPLE_RULE . author ) ;
220
+ . then ( ( ) => {
221
+ // Confirm arrival at detectors page
222
+ cy . get ( '.euiPopover__panel' ) . find ( 'button' ) . contains ( 'Edit' ) . click ( ) ;
223
+ } ) ;
144
224
145
- // Validate source is "custom"
146
- cy . get ( '[data-test-subj="rule_flyout_rule_source"]' ) . contains ( 'Custom' ) ;
225
+ const ruleNameSelector = '[data-test-subj="rule_name_field"]' ;
226
+ cy . get ( ruleNameSelector ) . clear ( ) ;
147
227
148
- // Validate severity
149
- cy . get ( '[data-test-subj="rule_flyout_rule_severity"]' ) . contains ( SAMPLE_RULE . severity ) ;
228
+ SAMPLE_RULE . name += ' edited' ;
229
+ cy . get ( ruleNameSelector ) . type ( SAMPLE_RULE . name ) ;
230
+ cy . get ( ruleNameSelector ) . should ( 'have.value' , SAMPLE_RULE . name ) ;
150
231
151
- // Validate tags
152
- SAMPLE_RULE . tags . forEach ( ( tag ) =>
153
- cy . get ( '[data-test-subj="rule_flyout_rule_tags"]' ) . contains ( tag )
154
- ) ;
232
+ // Enter the log type
233
+ const logSelector = '[data-test-subj="rule_type_dropdown"]' ;
234
+ cy . get ( logSelector ) . within ( ( ) => cy . get ( '.euiFormControlLayoutClearButton' ) . click ( ) ) ;
235
+ SAMPLE_RULE . logType = 'dns' ;
236
+ YAML_RULE_LINES [ 2 ] = `product: ${ SAMPLE_RULE . logType } ` ;
237
+ YAML_RULE_LINES [ 3 ] = `title: ${ SAMPLE_RULE . name } ` ;
238
+ cy . get ( logSelector ) . type ( SAMPLE_RULE . logType ) . type ( '{enter}' ) ;
239
+ cy . get ( logSelector ) . contains ( SAMPLE_RULE . logType , {
240
+ matchCase : false ,
241
+ } ) ;
155
242
156
- // Validate references
157
- cy . get ( '[data-test-subj="rule_flyout_rule_references"]' ) . contains ( SAMPLE_RULE . references ) ;
243
+ const ruleDescriptionSelector = '[data-test-subj="rule_description_field"]' ;
244
+ SAMPLE_RULE . description += ' edited' ;
245
+ YAML_RULE_LINES [ 4 ] = `description: ${ SAMPLE_RULE . description } ` ;
246
+ cy . get ( ruleDescriptionSelector ) . clear ( ) ;
247
+ cy . get ( ruleDescriptionSelector ) . type ( SAMPLE_RULE . description ) ;
248
+ cy . get ( ruleDescriptionSelector ) . should ( 'have.value' , SAMPLE_RULE . description ) ;
158
249
159
- // Validate false positives
160
- cy . get ( '[data-test-subj="rule_flyout_rule_false_positives"]' ) . contains (
161
- SAMPLE_RULE . falsePositive
162
- ) ;
250
+ cy . intercept ( {
251
+ url : '/rules' ,
252
+ } ) . as ( 'getRules' ) ;
163
253
164
- // Validate status
165
- cy . get ( '[data-test-subj="rule_flyout_rule_status"]' ) . contains ( SAMPLE_RULE . status ) ;
254
+ // Click "create" button
255
+ cy . get ( '[data-test-subj="submit_rule_form_button"]' ) . click ( {
256
+ force : true ,
257
+ } ) ;
166
258
167
- // Validate detection
168
- SAMPLE_RULE . detectionLine . forEach ( ( line ) =>
169
- cy . get ( '[data-test-subj="rule_flyout_rule_detection"]' ) . contains ( line )
170
- ) ;
259
+ cy . waitForPageLoad ( 'rules' , {
260
+ contains : 'Rules' ,
261
+ } ) ;
171
262
172
- cy . get ( '[data-test-subj="change-editor-type"] label:nth-child(2)' ) . click ( {
173
- force : true ,
174
- } ) ;
263
+ cy . wait ( '@getRules' ) ;
175
264
176
- cy . get ( '[data-test-subj="rule_flyout_yaml_rule"]' )
177
- . get ( '[class="euiCodeBlock__line"]' )
178
- . each ( ( lineElement , lineIndex ) => {
179
- if ( lineIndex >= YAML_RULE_LINES . length ) {
180
- return ;
181
- }
182
- let line = lineElement . text ( ) . replaceAll ( '\n' , '' ) . trim ( ) ;
183
- let expectedLine = YAML_RULE_LINES [ lineIndex ] ;
184
-
185
- // The document ID field is generated when the document is added to the index,
186
- // so this test just checks that the line starts with the ID key.
187
- if ( expectedLine . startsWith ( 'id:' ) ) {
188
- expectedLine = 'id:' ;
189
- expect ( line , `Sigma rule line ${ lineIndex } ` ) . to . contain ( expectedLine ) ;
190
- } else {
191
- expect ( line , `Sigma rule line ${ lineIndex } ` ) . to . equal ( expectedLine ) ;
192
- }
193
- } ) ;
194
-
195
- // Close the flyout
196
- cy . get ( '[data-test-subj="close-rule-details-flyout"]' ) . click ( {
197
- force : true ,
198
- } ) ;
199
- } ) ;
265
+ checkRulesFlyout ( ) ;
200
266
} ) ;
201
267
202
268
it ( '...can be deleted' , ( ) => {
@@ -209,20 +275,17 @@ describe('Rules', () => {
209
275
// Click the rule link to open the details flyout
210
276
cy . get ( `[data-test-subj="rule_link_${ SAMPLE_RULE . name } "]` ) . click ( { force : true } ) ;
211
277
212
- cy . get ( '.euiButton' )
278
+ cy . get ( `[data-test-subj="rule_flyout_${ SAMPLE_RULE . name } "]` )
279
+ . find ( 'button' )
213
280
. contains ( 'Action' )
214
281
. click ( { force : true } )
215
282
. then ( ( ) => {
216
283
// Confirm arrival at detectors page
217
- cy . get (
218
- '.euiFlexGroup > :nth-child(3) > .euiButtonEmpty > .euiButtonContent > .euiButtonEmpty__text'
219
- )
220
- . click ( {
221
- force : true ,
222
- } )
223
- . then ( ( ) => {
224
- cy . get ( '.euiButton' ) . contains ( 'Delete' ) . click ( ) ;
225
- } ) ;
284
+ cy . get ( '.euiPopover__panel' )
285
+ . find ( 'button' )
286
+ . contains ( 'Delete' )
287
+ . click ( )
288
+ . then ( ( ) => cy . get ( '.euiModalFooter > .euiButton' ) . contains ( 'Delete' ) . click ( ) ) ;
226
289
227
290
cy . wait ( '@deleteRule' ) ;
228
291
0 commit comments