@@ -27,6 +27,20 @@ describe('Security Solution - Health Diagnostic Queries - utils', () => {
2727 } ) ;
2828 } ) ;
2929
30+ test ( 'should keep fields marked with KEEP action in flat doc' , async ( ) => {
31+ const data = [ { 'kibana.alert.rule.name' : 'Endpoint Security (Elastic Defend)' } ] ;
32+ const rules = {
33+ 'user.name' : Action . KEEP ,
34+ 'kibana.alert.rule.name' : Action . KEEP ,
35+ } ;
36+
37+ const result = await applyFilterlist ( data , rules , mockSalt ) ;
38+
39+ expect ( result ) . toEqual ( [
40+ { kibana : { alert : { rule : { name : 'Endpoint Security (Elastic Defend)' } } } } ,
41+ ] ) ;
42+ } ) ;
43+
3044 test ( 'should keep fields marked with KEEP action' , async ( ) => {
3145 const data = [ { user :
{ name :
'john' , email :
'[email protected] ' } } ] ; 3246 const rules = {
@@ -98,31 +112,6 @@ describe('Security Solution - Health Diagnostic Queries - utils', () => {
98112 expect ( ( result [ 0 ] as any ) . meta . host . ip ) . not . toBe ( '192.168.1.1' ) ;
99113 } ) ;
100114
101- test ( 'should handle arrays of documents' , async ( ) => {
102- const data = [
103- [
104- { user : 'alice' , token : 'abc123' } ,
105- { user : 'bob' , token : 'xyz789' } ,
106- ] ,
107- ] ;
108- const rules = {
109- user : Action . KEEP ,
110- token : Action . MASK ,
111- } ;
112-
113- const result = await applyFilterlist ( data , rules , mockSalt ) ;
114-
115- expect ( result ) . toHaveLength ( 1 ) ;
116- expect ( Array . isArray ( result [ 0 ] ) ) . toBe ( true ) ;
117- // eslint-disable-next-line @typescript-eslint/no-explicit-any
118- const docs = result [ 0 ] as any [ ] ;
119- expect ( docs ) . toHaveLength ( 2 ) ;
120- expect ( docs [ 0 ] . user ) . toBe ( 'alice' ) ;
121- expect ( docs [ 1 ] . user ) . toBe ( 'bob' ) ;
122- expect ( docs [ 0 ] . token ) . not . toBe ( 'abc123' ) ;
123- expect ( docs [ 1 ] . token ) . not . toBe ( 'xyz789' ) ;
124- } ) ;
125-
126115 test ( 'should handle arrays of complex documents' , async ( ) => {
127116 const data = [
128117 {
@@ -301,30 +290,6 @@ describe('Security Solution - Health Diagnostic Queries - utils', () => {
301290 ] ) ;
302291 } ) ;
303292
304- test ( 'should handle mixed document types' , async ( ) => {
305- const data = [
306- { type : 'user' , name : 'john' , password : 'secret' } ,
307- [ { type : 'admin' , name : 'admin' , token : 'admin123' } ] ,
308- ] ;
309- const rules = {
310- name : Action . KEEP ,
311- password : Action . MASK ,
312- token : Action . MASK ,
313- } ;
314-
315- const result = await applyFilterlist ( data , rules , mockSalt ) ;
316-
317- expect ( result ) . toHaveLength ( 2 ) ;
318- expect ( result [ 0 ] ) . toMatchObject ( { name : 'john' } ) ;
319- // eslint-disable-next-line @typescript-eslint/no-explicit-any
320- expect ( ( result [ 0 ] as any ) . password ) . not . toBe ( 'secret' ) ;
321- expect ( Array . isArray ( result [ 1 ] ) ) . toBe ( true ) ;
322- // eslint-disable-next-line @typescript-eslint/no-explicit-any
323- const adminDocs = result [ 1 ] as any [ ] ;
324- expect ( adminDocs [ 0 ] . name ) . toBe ( 'admin' ) ;
325- expect ( adminDocs [ 0 ] . token ) . not . toBe ( 'admin123' ) ;
326- } ) ;
327-
328293 test ( 'should handle numeric and boolean values' , async ( ) => {
329294 const data = [
330295 {
0 commit comments