@@ -9,7 +9,7 @@ const uniqueId = Cypress._.random(0, 1e6);
9
9
const SAMPLE_RULE = {
10
10
name : `Cypress test rule ${ uniqueId } ` ,
11
11
logType : 'windows' ,
12
- description : 'This is a rule used to test the rule creation workflow. Not for production use. ' ,
12
+ description : 'This is a rule used to test the rule creation workflow.' ,
13
13
detection :
14
14
'selection:\n Provider_Name: Service Control Manager\nEventID: 7045\nServiceName: ZzNetSvc\n{backspace}{backspace}condition: selection' ,
15
15
detectionLine : [
@@ -28,22 +28,23 @@ const SAMPLE_RULE = {
28
28
} ;
29
29
30
30
const YAML_RULE_LINES = [
31
+ `id:` ,
32
+ `logsource:` ,
33
+ `product: ${ SAMPLE_RULE . logType } ` ,
31
34
`title: ${ SAMPLE_RULE . name } ` ,
32
- `description:` ,
33
- `${ SAMPLE_RULE . description } ` ,
34
- `level: ${ SAMPLE_RULE . severity } ` ,
35
+ `description: ${ SAMPLE_RULE . description } ` ,
35
36
`tags:` ,
36
37
`- ${ SAMPLE_RULE . tags [ 0 ] } ` ,
37
38
`- ${ SAMPLE_RULE . tags [ 1 ] } ` ,
38
39
`- ${ SAMPLE_RULE . tags [ 2 ] } ` ,
39
- `references:` ,
40
- `- '${ SAMPLE_RULE . references } '` ,
41
40
`falsepositives:` ,
42
41
`- ${ SAMPLE_RULE . falsePositive } ` ,
43
- `author : ${ SAMPLE_RULE . author } ` ,
42
+ `level : ${ SAMPLE_RULE . severity } ` ,
44
43
`status: ${ SAMPLE_RULE . status } ` ,
45
- `logsource:` ,
46
- `product: ${ SAMPLE_RULE . logType } ` ,
44
+ `references:` ,
45
+ `- '${ SAMPLE_RULE . references } '` ,
46
+ `author: ${ SAMPLE_RULE . author } ` ,
47
+ `detection:` ,
47
48
...SAMPLE_RULE . detection . replaceAll ( ' ' , '' ) . replaceAll ( '{backspace}' , '' ) . split ( '\n' ) ,
48
49
] ;
49
50
@@ -222,11 +223,24 @@ describe('Rules', () => {
222
223
force : true ,
223
224
} ) ;
224
225
225
- YAML_RULE_LINES . forEach ( ( line ) =>
226
- cy
227
- . get ( '[data-test-subj="rule_flyout_yaml_rule"]' , TWENTY_SECONDS_TIMEOUT )
228
- . contains ( line , TWENTY_SECONDS_TIMEOUT )
229
- ) ;
226
+ cy . get ( '[data-test-subj="rule_flyout_yaml_rule"]' )
227
+ . get ( '[class="euiCodeBlock__line"]' )
228
+ . each ( ( lineElement , lineIndex ) => {
229
+ if ( lineIndex >= YAML_RULE_LINES . length ) {
230
+ return ;
231
+ }
232
+ let line = lineElement . text ( ) . replaceAll ( '\n' , '' ) . trim ( ) ;
233
+ let expectedLine = YAML_RULE_LINES [ lineIndex ] ;
234
+
235
+ // The document ID field is generated when the document is added to the index,
236
+ // so this test just checks that the line starts with the ID key.
237
+ if ( expectedLine . startsWith ( 'id:' ) ) {
238
+ expectedLine = 'id:' ;
239
+ expect ( line , `Sigma rule line ${ lineIndex } ` ) . to . contain ( expectedLine ) ;
240
+ } else {
241
+ expect ( line , `Sigma rule line ${ lineIndex } ` ) . to . equal ( expectedLine ) ;
242
+ }
243
+ } ) ;
230
244
231
245
// Close the flyout
232
246
cy . get ( '[data-test-subj="close-rule-details-flyout"]' , TWENTY_SECONDS_TIMEOUT ) . click ( {
0 commit comments