@@ -8,28 +8,25 @@ import expect from '@kbn/expect';
88import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common' ;
99import { CDR_LATEST_NATIVE_VULNERABILITIES_INDEX_PATTERN } from '@kbn/cloud-security-posture-common' ;
1010import type { CspSetupStatus } from '@kbn/cloud-security-posture-common' ;
11- import {
12- FINDINGS_INDEX_DEFAULT_NS ,
13- LATEST_FINDINGS_INDEX_DEFAULT_NS ,
14- VULNERABILITIES_INDEX_DEFAULT_NS ,
15- } from '@kbn/cloud-security-posture-plugin/common/constants' ;
11+ import { LATEST_FINDINGS_INDEX_DEFAULT_NS } from '@kbn/cloud-security-posture-plugin/common/constants' ;
1612import { FtrProviderContext } from '../../../ftr_provider_context' ;
17- import { deleteIndex , addIndex , createPackagePolicy } from '../helper' ;
13+ import { EsIndexDataProvider } from '../../../../cloud_security_posture_api/utils' ;
14+ import { createPackagePolicy } from '../helper' ;
1815import { findingsMockData , vulnerabilityMockData } from '../mock_data' ;
1916
20- const INDEX_ARRAY = [
21- FINDINGS_INDEX_DEFAULT_NS ,
22- LATEST_FINDINGS_INDEX_DEFAULT_NS ,
23- CDR_LATEST_NATIVE_VULNERABILITIES_INDEX_PATTERN ,
24- VULNERABILITIES_INDEX_DEFAULT_NS ,
25- ] ;
26-
2717export default function ( providerContext : FtrProviderContext ) {
2818 const { getService } = providerContext ;
2919 const supertest = getService ( 'supertest' ) ;
3020 const es = getService ( 'es' ) ;
3121 const esArchiver = getService ( 'esArchiver' ) ;
3222 const kibanaServer = getService ( 'kibanaServer' ) ;
23+ const latestFindingsIndex = new EsIndexDataProvider ( es , LATEST_FINDINGS_INDEX_DEFAULT_NS ) ;
24+ const latestVulnerabilitiesIndex = new EsIndexDataProvider (
25+ es ,
26+ CDR_LATEST_NATIVE_VULNERABILITIES_INDEX_PATTERN
27+ ) ;
28+ const mock3PIndex = 'security_solution-mock-3p-integration.misconfiguration_latest' ;
29+ const _3pIndex = new EsIndexDataProvider ( es , mock3PIndex ) ;
3330
3431 describe ( 'GET /internal/cloud_security_posture/status' , ( ) => {
3532 let agentPolicyId : string ;
@@ -50,19 +47,21 @@ export default function (providerContext: FtrProviderContext) {
5047
5148 agentPolicyId = agentPolicyResponse . item . id ;
5249
53- await deleteIndex ( es , INDEX_ARRAY ) ;
54- await addIndex ( es , findingsMockData , LATEST_FINDINGS_INDEX_DEFAULT_NS ) ;
55- await addIndex ( es , vulnerabilityMockData , CDR_LATEST_NATIVE_VULNERABILITIES_INDEX_PATTERN ) ;
50+ await latestFindingsIndex . deleteAll ( ) ;
51+ await latestVulnerabilitiesIndex . deleteAll ( ) ;
52+ await _3pIndex . deleteAll ( ) ;
5653 } ) ;
5754
5855 afterEach ( async ( ) => {
59- await deleteIndex ( es , INDEX_ARRAY ) ;
56+ await latestFindingsIndex . deleteAll ( ) ;
57+ await latestVulnerabilitiesIndex . deleteAll ( ) ;
58+ await _3pIndex . destroyIndex ( ) ;
6059 await kibanaServer . savedObjects . cleanStandardList ( ) ;
6160 await esArchiver . unload ( 'x-pack/test/functional/es_archives/fleet/empty_fleet_server' ) ;
6261 } ) ;
6362
6463 it ( `Return hasMisconfigurationsFindings true when there are latest findings but no installed integrations` , async ( ) => {
65- await addIndex ( es , findingsMockData , LATEST_FINDINGS_INDEX_DEFAULT_NS ) ;
64+ await latestFindingsIndex . addBulk ( findingsMockData ) ;
6665
6766 const { body : res } : { body : CspSetupStatus } = await supertest
6867 . get ( `/internal/cloud_security_posture/status` )
@@ -77,9 +76,7 @@ export default function (providerContext: FtrProviderContext) {
7776 } ) ;
7877
7978 it ( `Return hasMisconfigurationsFindings true when there are only findings in third party index` , async ( ) => {
80- await deleteIndex ( es , INDEX_ARRAY ) ;
81- const mock3PIndex = 'security_solution-mock-3p-integration.misconfiguration_latest' ;
82- await addIndex ( es , findingsMockData , mock3PIndex ) ;
79+ await _3pIndex . addBulk ( findingsMockData ) ;
8380
8481 const { body : res } : { body : CspSetupStatus } = await supertest
8582 . get ( `/internal/cloud_security_posture/status` )
@@ -91,13 +88,9 @@ export default function (providerContext: FtrProviderContext) {
9188 true ,
9289 `expected hasMisconfigurationsFindings to be true but got ${ res . hasMisconfigurationsFindings } instead`
9390 ) ;
94-
95- await deleteIndex ( es , [ mock3PIndex ] ) ;
9691 } ) ;
9792
9893 it ( `Return hasMisconfigurationsFindings false when there are no findings` , async ( ) => {
99- await deleteIndex ( es , INDEX_ARRAY ) ;
100-
10194 const { body : res } : { body : CspSetupStatus } = await supertest
10295 . get ( `/internal/cloud_security_posture/status` )
10396 . set ( ELASTIC_HTTP_VERSION_HEADER , '1' )
@@ -120,6 +113,8 @@ export default function (providerContext: FtrProviderContext) {
120113 'kspm'
121114 ) ;
122115
116+ await latestFindingsIndex . addBulk ( findingsMockData ) ;
117+
123118 const { body : res } : { body : CspSetupStatus } = await supertest
124119 . get ( `/internal/cloud_security_posture/status` )
125120 . set ( ELASTIC_HTTP_VERSION_HEADER , '1' )
@@ -142,6 +137,8 @@ export default function (providerContext: FtrProviderContext) {
142137 'cspm'
143138 ) ;
144139
140+ await latestFindingsIndex . addBulk ( findingsMockData ) ;
141+
145142 const { body : res } : { body : CspSetupStatus } = await supertest
146143 . get ( `/internal/cloud_security_posture/status` )
147144 . set ( ELASTIC_HTTP_VERSION_HEADER , '1' )
@@ -164,6 +161,8 @@ export default function (providerContext: FtrProviderContext) {
164161 'vuln_mgmt'
165162 ) ;
166163
164+ await latestVulnerabilitiesIndex . addBulk ( vulnerabilityMockData ) ;
165+
167166 const { body : res } : { body : CspSetupStatus } = await supertest
168167 . get ( `/internal/cloud_security_posture/status` )
169168 . set ( ELASTIC_HTTP_VERSION_HEADER , '1' )
0 commit comments