From f87edb9d6a3e1c51f386a73e06e86ce7fb21df50 Mon Sep 17 00:00:00 2001 From: Ricky Ang Date: Tue, 27 Jun 2023 19:37:20 -0700 Subject: [PATCH 1/5] refactor, using eql for more understandable error message --- .../get_csp_rule_template.ts | 29 +++-- .../status/status_index_timeout.ts | 15 ++- .../status/status_indexed.ts | 15 ++- .../status/status_indexing.ts | 15 ++- .../status_not_deployed_not_installed.ts | 75 ++++++++--- .../status/status_unprivileged.ts | 120 ++++++++++++++---- .../status/status_waiting_for_results.ts | 15 ++- 7 files changed, 223 insertions(+), 61 deletions(-) diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/get_csp_rule_template.ts b/x-pack/test/api_integration/apis/cloud_security_posture/get_csp_rule_template.ts index 1d91efdc7fe89..2c705031e896a 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/get_csp_rule_template.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/get_csp_rule_template.ts @@ -55,8 +55,9 @@ export default function ({ getService }: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(500); - expect(body.message).to.be( - 'Please provide either benchmarkId or packagePolicyId, but not both' + expect(body.message).to.eql( + 'Please provide either benchmarkId or packagePolicyId, but not both', + `expected 'Please provide either benchmarkId or packagePolicyId, but not both' but got ${body.message} instead` ); }); @@ -80,8 +81,9 @@ export default function ({ getService }: FtrProviderContext) { }) .expect(500); - expect(body.message).to.be( - 'Please provide either benchmarkId or packagePolicyId, but not both' + expect(body.message).to.eql( + 'Please provide either benchmarkId or packagePolicyId, but not both', + `expected 'Please provide either benchmarkId or packagePolicyId, but not both' but got ${body.message} instead` ); }); @@ -95,8 +97,8 @@ export default function ({ getService }: FtrProviderContext) { }) .expect(404); - expect(body.statusCode).to.be(404); - expect(body.error).to.be('Not Found'); + expect(body.statusCode).to.eql(404, `expected 404 but got ${body.statusCode} instead`); + expect(body.error).to.eql('Not Found', `expected 'Not Found' but got ${body.error} instead`); }); it(`Should return 200 status code and filter rules by benchmarkId`, async () => { @@ -124,7 +126,10 @@ export default function ({ getService }: FtrProviderContext) { (rule: CspRuleTemplate) => rule.metadata.benchmark.id === 'cis_k8s' ); - expect(allRulesHaveCorrectBenchmarkId).to.be(true); + expect(allRulesHaveCorrectBenchmarkId).to.eql( + true, + `expected true but got ${allRulesHaveCorrectBenchmarkId} instead` + ); }); it(`Should return 200 status code, and only requested fields in the response`, async () => { @@ -157,7 +162,7 @@ export default function ({ getService }: FtrProviderContext) { ); }); - expect(fieldsMatched).to.be(true); + expect(fieldsMatched).to.eql(true, `expected true but got ${fieldsMatched} instead`); }); it(`Should return 200 status code, items sorted by metadata.section field`, async () => { @@ -188,7 +193,8 @@ export default function ({ getService }: FtrProviderContext) { const isSorted = sections.every( (section, index) => index === 0 || section >= sections[index - 1] ); - expect(isSorted).to.be(true); + + expect(isSorted).to.eql(true, `expected true but got ${isSorted} instead`); }); it(`Should return 200 status code and paginate rules with a limit of PerPage`, async () => { @@ -213,7 +219,10 @@ export default function ({ getService }: FtrProviderContext) { }) .expect(200); - expect(body.items.length).to.be(perPage); + expect(body.items.length).to.eql( + perPage, + `expected ${perPage} but got ${body.items.length} instead` + ); }); }); } diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_index_timeout.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_index_timeout.ts index eae7154763bc0..86922921fc755 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_index_timeout.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_index_timeout.ts @@ -108,7 +108,10 @@ export default function (providerContext: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.kspm.status).to.be('index-timeout'); + expect(res.kspm.status).to.eql( + 'index-timeout', + `expected index-timeout but got ${res.kspm.status} instead` + ); }); it(`Should return index-timeout when installed cspm, has findings only on logs-cloud_security_posture.findings-default* and it has been more than 10 minutes since the installation`, async () => { @@ -134,7 +137,10 @@ export default function (providerContext: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.cspm.status).to.be('index-timeout'); + expect(res.cspm.status).to.eql( + 'index-timeout', + `expected index-timeout but got ${res.cspm.status} instead` + ); }); it(`Should return index-timeout when installed cnvm, has findings only on logs-cloud_security_posture.vulnerabilities-default* and it has been more than 4 hours minutes since the installation`, async () => { @@ -160,7 +166,10 @@ export default function (providerContext: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.vuln_mgmt.status).to.be('index-timeout'); + expect(res.vuln_mgmt.status).to.eql( + 'index-timeout', + `expected index-timeout but got ${res.vuln_mgmt.status} instead` + ); }); }); }); diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexed.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexed.ts index c8cd9927c72d4..45bebfbc0e7bd 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexed.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexed.ts @@ -74,7 +74,10 @@ export default function (providerContext: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.kspm.status).to.be('indexed'); + expect(res.kspm.status).to.eql( + 'indexed', + `expected indexed but got ${res.kspm.status} instead` + ); }); it(`Return cspm status indexed when logs-cloud_security_posture.findings_latest-default contains new cspm documents`, async () => { @@ -92,7 +95,10 @@ export default function (providerContext: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.cspm.status).to.be('indexed'); + expect(res.cspm.status).to.eql( + 'indexed', + `expected indexed but got ${res.cspm.status} instead` + ); }); it(`Return vuln status indexed when logs-cloud_security_posture.vulnerabilities_latest-default contains new documents`, async () => { @@ -110,7 +116,10 @@ export default function (providerContext: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.vuln_mgmt.status).to.be('indexed'); + expect(res.vuln_mgmt.status).to.eql( + 'indexed', + `expected indexed but got ${res.vuln_mgmt.status} instead` + ); }); }); }); diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexing.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexing.ts index d7c11c446544a..3ce2b16a1740f 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexing.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexing.ts @@ -73,7 +73,10 @@ export default function (providerContext: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.kspm.status).to.be('indexing'); + expect(res.kspm.status).to.eql( + 'indexing', + `expected indexing but got ${res.kspm.status} instead` + ); }); it(`Return cspm status indexing when logs-cloud_security_posture.findings_latest-default doesn't contain new cspm documents, but has newly connected agents `, async () => { @@ -91,7 +94,10 @@ export default function (providerContext: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.cspm.status).to.be('indexing'); + expect(res.cspm.status).to.eql( + 'indexing', + `expected indexing but got ${res.cspm.status} instead` + ); }); it(`Return vuln status indexing when logs-cloud_security_posture.vulnerabilities_latest-default doesn't contain vuln new documents, but has newly connected agents`, async () => { @@ -109,7 +115,10 @@ export default function (providerContext: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.vuln_mgmt.status).to.be('indexing'); + expect(res.vuln_mgmt.status).to.eql( + 'indexing', + `expected indexing but got ${res.vuln_mgmt.status} instead` + ); }); }); }); diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed.ts index 93b8c81ad44de..c43f5fb42a41f 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed.ts @@ -53,11 +53,26 @@ export default function (providerContext: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.kspm.status).to.be('not-deployed'); - expect(res.cspm.status).to.be('not-installed'); - expect(res.vuln_mgmt.status).to.be('not-installed'); - expect(res.kspm.healthyAgents).to.be(0); - expect(res.kspm.installedPackagePolicies).to.be(1); + expect(res.kspm.status).to.eql( + 'not-deployed', + `expected not-deployed but got ${res.kspm.status} instead` + ); + expect(res.cspm.status).to.eql( + 'not-installed', + `expected not-installed but got ${res.cspm.status} instead` + ); + expect(res.vuln_mgmt.status).to.eql( + 'not-installed', + `expected not-installed but got ${res.vuln_mgmt.status} instead` + ); + expect(res.kspm.healthyAgents).to.eql( + 0, + `expected 0 but got ${res.kspm.healthyAgents} instead` + ); + expect(res.kspm.installedPackagePolicies).to.eql( + 1, + `expected 1 but got ${res.kspm.installedPackagePolicies} instead` + ); }); it(`Should return not-deployed when installed cspm, no findings on either indices and no healthy agents`, async () => { @@ -75,11 +90,26 @@ export default function (providerContext: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.cspm.status).to.be('not-deployed'); - expect(res.kspm.status).to.be('not-installed'); - expect(res.vuln_mgmt.status).to.be('not-installed'); - expect(res.cspm.healthyAgents).to.be(0); - expect(res.cspm.installedPackagePolicies).to.be(1); + expect(res.cspm.status).to.eql( + 'not-deployed', + `expected not-deployed but got ${res.cspm.status} instead` + ); + expect(res.kspm.status).to.eql( + 'not-installed', + `expected not-installed but got ${res.kspm.status} instead` + ); + expect(res.vuln_mgmt.status).to.eql( + 'not-installed', + `expected not-installed but got ${res.vuln_mgmt.status} instead` + ); + expect(res.cspm.healthyAgents).to.eql( + 0, + `expected 0 but got ${res.cspm.healthyAgents} instead` + ); + expect(res.cspm.installedPackagePolicies).to.eql( + 1, + `expected 1 but got ${res.cspm.installedPackagePolicies} instead` + ); }); it(`Should return not-deployed when installed cnvm, no findings on either indices and no healthy agents`, async () => { @@ -97,11 +127,26 @@ export default function (providerContext: FtrProviderContext) { .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.cspm.status).to.be('not-installed'); - expect(res.kspm.status).to.be('not-installed'); - expect(res.vuln_mgmt.status).to.be('not-deployed'); - expect(res.vuln_mgmt.healthyAgents).to.be(0); - expect(res.vuln_mgmt.installedPackagePolicies).to.be(1); + expect(res.cspm.status).to.eql( + 'not-installed', + `expected not-installed but got ${res.cspm.status} instead` + ); + expect(res.kspm.status).to.eql( + 'not-installed', + `expected not-installed but got ${res.kspm.status} instead` + ); + expect(res.vuln_mgmt.status).to.eql( + 'not-deployed', + `expected not-deployed but got ${res.vuln_mgmt.status} instead` + ); + expect(res.vuln_mgmt.healthyAgents).to.eql( + 0, + `expected 0 but got ${res.vuln_mgmt.healthyAgents} instead` + ); + expect(res.vuln_mgmt.installedPackagePolicies).to.eql( + 1, + `expected 1 but got ${res.vuln_mgmt.installedPackagePolicies} instead` + ); }); }); }); diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts index 3127519b2bc4c..5dde5ab93cdab 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts @@ -83,9 +83,18 @@ export default function (providerContext: FtrProviderContext) { .auth(UNPRIVILEGED_USERNAME, 'changeme') .expect(200); - expect(res.kspm.status).to.be('unprivileged'); - expect(res.cspm.status).to.be('unprivileged'); - expect(res.vuln_mgmt.status).to.be('unprivileged'); + expect(res.kspm.status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.kspm.status} instead` + ); + expect(res.cspm.status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.cspm.status} instead` + ); + expect(res.vuln_mgmt.status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.vuln_mgmt.status} instead` + ); }); }); @@ -131,14 +140,35 @@ export default function (providerContext: FtrProviderContext) { .auth(UNPRIVILEGED_USERNAME, 'changeme') .expect(200); - expect(res.kspm.status).to.be('unprivileged'); - expect(res.cspm.status).to.be('unprivileged'); - expect(res.vuln_mgmt.status).to.be('unprivileged'); + expect(res.kspm.status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.kspm.status} instead` + ); + expect(res.cspm.status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.cspm.status} instead` + ); + expect(res.vuln_mgmt.status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.vuln_mgmt.status} instead` + ); - expect(res.indicesDetails[0].status).to.be('empty'); - expect(res.indicesDetails[1].status).to.be('empty'); - expect(res.indicesDetails[2].status).to.be('unprivileged'); - expect(res.indicesDetails[3].status).to.be('unprivileged'); + expect(res.indicesDetails[0].status).to.eql( + 'empty', + `expected empty but got ${res.indicesDetails[0].status} instead` + ); + expect(res.indicesDetails[1].status).to.eql( + 'empty', + `expected empty but got ${res.indicesDetails[1].status} instead` + ); + expect(res.indicesDetails[2].status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.indicesDetails[2].status} instead` + ); + expect(res.indicesDetails[3].status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.indicesDetails[3].status} instead` + ); }); it(`Return unprivileged when missing access to score index`, async () => { @@ -161,14 +191,35 @@ export default function (providerContext: FtrProviderContext) { .auth(UNPRIVILEGED_USERNAME, 'changeme') .expect(200); - expect(res.kspm.status).to.be('unprivileged'); - expect(res.cspm.status).to.be('unprivileged'); - expect(res.vuln_mgmt.status).to.be('unprivileged'); + expect(res.kspm.status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.kspm.status} instead` + ); + expect(res.cspm.status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.cspm.status} instead` + ); + expect(res.vuln_mgmt.status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.vuln_mgmt.status} instead` + ); - expect(res.indicesDetails[0].status).to.be('unprivileged'); - expect(res.indicesDetails[1].status).to.be('empty'); - expect(res.indicesDetails[2].status).to.be('empty'); - expect(res.indicesDetails[3].status).to.be('unprivileged'); + expect(res.indicesDetails[0].status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.indicesDetails[0].status} instead` + ); + expect(res.indicesDetails[1].status).to.eql( + 'empty', + `expected empty but got ${res.indicesDetails[1].status} instead` + ); + expect(res.indicesDetails[2].status).to.eql( + 'empty', + `expected empty but got ${res.indicesDetails[2].status} instead` + ); + expect(res.indicesDetails[3].status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.indicesDetails[3].status} instead` + ); }); it(`Return unprivileged when missing access to vulnerabilities_latest index`, async () => { @@ -194,14 +245,35 @@ export default function (providerContext: FtrProviderContext) { .auth(UNPRIVILEGED_USERNAME, 'changeme') .expect(200); - expect(res.kspm.status).to.be('unprivileged'); - expect(res.cspm.status).to.be('unprivileged'); - expect(res.vuln_mgmt.status).to.be('not-installed'); + expect(res.kspm.status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.kspm.status} instead` + ); + expect(res.cspm.status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.cspm.status} instead` + ); + expect(res.vuln_mgmt.status).to.eql( + 'not-installed', + `expected not-installed but got ${res.vuln_mgmt.status} instead` + ); - expect(res.indicesDetails[0].status).to.be('unprivileged'); - expect(res.indicesDetails[1].status).to.be('empty'); - expect(res.indicesDetails[2].status).to.be('unprivileged'); - expect(res.indicesDetails[3].status).to.be('empty'); + expect(res.indicesDetails[0].status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.indicesDetails[0].status} instead` + ); + expect(res.indicesDetails[1].status).to.eql( + 'empty', + `expected empty but got ${res.indicesDetails[1].status} instead` + ); + expect(res.indicesDetails[2].status).to.eql( + 'unprivileged', + `expected unprivileged but got ${res.indicesDetails[2].status} instead` + ); + expect(res.indicesDetails[3].status).to.eql( + 'empty', + `expected empty but got ${res.indicesDetails[3].status} instead` + ); }); }); }); diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_waiting_for_results.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_waiting_for_results.ts index 8153851124329..3543aa21edeba 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_waiting_for_results.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_waiting_for_results.ts @@ -89,7 +89,10 @@ export default function (providerContext: FtrProviderContext) { .get(`/internal/cloud_security_posture/status`) .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.kspm.status).to.be('waiting_for_results'); + expect(res.kspm.status).to.eql( + 'waiting_for_results', + `expected waiting_for_results but got ${res.kspm.status} instead` + ); }); it(`Should return waiting_for_result when installed cspm, has no findings and it has been less than 10 minutes since the installation`, async () => { @@ -114,7 +117,10 @@ export default function (providerContext: FtrProviderContext) { .get(`/internal/cloud_security_posture/status`) .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.cspm.status).to.be('waiting_for_results'); + expect(res.cspm.status).to.eql( + 'waiting_for_results', + `expected waiting_for_results but got ${res.cspm.status} instead` + ); }); it(`Should return waiting_for_result when installed cnvm, has no findings and it has been less than 4 hours minutes since the installation`, async () => { @@ -139,7 +145,10 @@ export default function (providerContext: FtrProviderContext) { .get(`/internal/cloud_security_posture/status`) .set('kbn-xsrf', 'xxxx') .expect(200); - expect(res.vuln_mgmt.status).to.be('waiting_for_results'); + expect(res.vuln_mgmt.status).to.eql( + 'waiting_for_results', + `expected waiting_for_results but got ${res.vuln_mgmt.status} instead` + ); }); }); }); From 45567c429ec474cb584e5f1e8c6b1b0daf08ce5c Mon Sep 17 00:00:00 2001 From: Ricky Ang Date: Wed, 28 Jun 2023 09:08:00 -0700 Subject: [PATCH 2/5] addressing pr comments --- .../get_csp_rule_template.ts | 16 ++- .../status/status_index_timeout.ts | 6 +- .../status/status_indexed.ts | 6 +- .../status/status_indexing.ts | 6 +- .../status_not_deployed_not_installed.ts | 30 ++--- .../status/status_unprivileged.ts | 103 ++++++++++++++---- .../status/status_waiting_for_results.ts | 6 +- 7 files changed, 117 insertions(+), 56 deletions(-) diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/get_csp_rule_template.ts b/x-pack/test/api_integration/apis/cloud_security_posture/get_csp_rule_template.ts index 2c705031e896a..99fa403c22635 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/get_csp_rule_template.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/get_csp_rule_template.ts @@ -57,7 +57,7 @@ export default function ({ getService }: FtrProviderContext) { expect(body.message).to.eql( 'Please provide either benchmarkId or packagePolicyId, but not both', - `expected 'Please provide either benchmarkId or packagePolicyId, but not both' but got ${body.message} instead` + `expected message to be 'Please provide either benchmarkId or packagePolicyId, but not both' but got ${body.message} instead` ); }); @@ -83,7 +83,7 @@ export default function ({ getService }: FtrProviderContext) { expect(body.message).to.eql( 'Please provide either benchmarkId or packagePolicyId, but not both', - `expected 'Please provide either benchmarkId or packagePolicyId, but not both' but got ${body.message} instead` + `expected message to be 'Please provide either benchmarkId or packagePolicyId, but not both' but got ${body.message} instead` ); }); @@ -97,8 +97,14 @@ export default function ({ getService }: FtrProviderContext) { }) .expect(404); - expect(body.statusCode).to.eql(404, `expected 404 but got ${body.statusCode} instead`); - expect(body.error).to.eql('Not Found', `expected 'Not Found' but got ${body.error} instead`); + expect(body.statusCode).to.eql( + 404, + `expected status code to be 404 but got ${body.statusCode} instead` + ); + expect(body.error).to.eql( + 'Not Found', + `expected error message to be 'Not Found' but got ${body.error} instead` + ); }); it(`Should return 200 status code and filter rules by benchmarkId`, async () => { @@ -221,7 +227,7 @@ export default function ({ getService }: FtrProviderContext) { expect(body.items.length).to.eql( perPage, - `expected ${perPage} but got ${body.items.length} instead` + `expected length to be ${perPage} but got ${body.items.length} instead` ); }); }); diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_index_timeout.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_index_timeout.ts index 86922921fc755..80523c54b8675 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_index_timeout.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_index_timeout.ts @@ -110,7 +110,7 @@ export default function (providerContext: FtrProviderContext) { expect(res.kspm.status).to.eql( 'index-timeout', - `expected index-timeout but got ${res.kspm.status} instead` + `expected kspm status to be index-timeout but got ${res.kspm.status} instead` ); }); @@ -139,7 +139,7 @@ export default function (providerContext: FtrProviderContext) { expect(res.cspm.status).to.eql( 'index-timeout', - `expected index-timeout but got ${res.cspm.status} instead` + `expected cspm status to be index-timeout but got ${res.cspm.status} instead` ); }); @@ -168,7 +168,7 @@ export default function (providerContext: FtrProviderContext) { expect(res.vuln_mgmt.status).to.eql( 'index-timeout', - `expected index-timeout but got ${res.vuln_mgmt.status} instead` + `expected vuln_mgmt status to be index-timeout but got ${res.vuln_mgmt.status} instead` ); }); }); diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexed.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexed.ts index 45bebfbc0e7bd..e154151b53213 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexed.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexed.ts @@ -76,7 +76,7 @@ export default function (providerContext: FtrProviderContext) { expect(res.kspm.status).to.eql( 'indexed', - `expected indexed but got ${res.kspm.status} instead` + `expected kspm status to be indexed but got ${res.kspm.status} instead` ); }); @@ -97,7 +97,7 @@ export default function (providerContext: FtrProviderContext) { expect(res.cspm.status).to.eql( 'indexed', - `expected indexed but got ${res.cspm.status} instead` + `expected cspm status to be indexed but got ${res.cspm.status} instead` ); }); @@ -118,7 +118,7 @@ export default function (providerContext: FtrProviderContext) { expect(res.vuln_mgmt.status).to.eql( 'indexed', - `expected indexed but got ${res.vuln_mgmt.status} instead` + `expected vuln_mgmt status to be indexed but got ${res.vuln_mgmt.status} instead` ); }); }); diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexing.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexing.ts index 3ce2b16a1740f..04ac8eacf1d53 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexing.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_indexing.ts @@ -75,7 +75,7 @@ export default function (providerContext: FtrProviderContext) { expect(res.kspm.status).to.eql( 'indexing', - `expected indexing but got ${res.kspm.status} instead` + `expected kspm status to be indexing but got ${res.kspm.status} instead` ); }); @@ -96,7 +96,7 @@ export default function (providerContext: FtrProviderContext) { expect(res.cspm.status).to.eql( 'indexing', - `expected indexing but got ${res.cspm.status} instead` + `expected cspm status to be indexing but got ${res.cspm.status} instead` ); }); @@ -117,7 +117,7 @@ export default function (providerContext: FtrProviderContext) { expect(res.vuln_mgmt.status).to.eql( 'indexing', - `expected indexing but got ${res.vuln_mgmt.status} instead` + `expected vuln_mgmt status to be indexing but got ${res.vuln_mgmt.status} instead` ); }); }); diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed.ts index c43f5fb42a41f..da93a346ae746 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed.ts @@ -55,23 +55,23 @@ export default function (providerContext: FtrProviderContext) { expect(res.kspm.status).to.eql( 'not-deployed', - `expected not-deployed but got ${res.kspm.status} instead` + `expected kspm status to be not-deployed but got ${res.kspm.status} instead` ); expect(res.cspm.status).to.eql( 'not-installed', - `expected not-installed but got ${res.cspm.status} instead` + `expected cspm status to be not-installed but got ${res.cspm.status} instead` ); expect(res.vuln_mgmt.status).to.eql( 'not-installed', - `expected not-installed but got ${res.vuln_mgmt.status} instead` + `expected vuln_mgmt status to be not-installed but got ${res.vuln_mgmt.status} instead` ); expect(res.kspm.healthyAgents).to.eql( 0, - `expected 0 but got ${res.kspm.healthyAgents} instead` + `expected number of kspm healthy agents to be 0 but got ${res.kspm.healthyAgents} instead` ); expect(res.kspm.installedPackagePolicies).to.eql( 1, - `expected 1 but got ${res.kspm.installedPackagePolicies} instead` + `expected number of kspm installed package policies to be 1 but got ${res.kspm.installedPackagePolicies} instead` ); }); @@ -92,23 +92,23 @@ export default function (providerContext: FtrProviderContext) { expect(res.cspm.status).to.eql( 'not-deployed', - `expected not-deployed but got ${res.cspm.status} instead` + `expected cspm status to be not-deployed but got ${res.cspm.status} instead` ); expect(res.kspm.status).to.eql( 'not-installed', - `expected not-installed but got ${res.kspm.status} instead` + `expected kspm status to be not-installed but got ${res.kspm.status} instead` ); expect(res.vuln_mgmt.status).to.eql( 'not-installed', - `expected not-installed but got ${res.vuln_mgmt.status} instead` + `expected vuln_mgmt status to be not-installed but got ${res.vuln_mgmt.status} instead` ); expect(res.cspm.healthyAgents).to.eql( 0, - `expected 0 but got ${res.cspm.healthyAgents} instead` + `expected number of cspm healthy agents to be 0 but got ${res.cspm.healthyAgents} instead` ); expect(res.cspm.installedPackagePolicies).to.eql( 1, - `expected 1 but got ${res.cspm.installedPackagePolicies} instead` + `expected number of cspm installed package policies to be 1 but got ${res.cspm.installedPackagePolicies} instead` ); }); @@ -129,23 +129,23 @@ export default function (providerContext: FtrProviderContext) { expect(res.cspm.status).to.eql( 'not-installed', - `expected not-installed but got ${res.cspm.status} instead` + `expected cspm status to be not-installed but got ${res.cspm.status} instead` ); expect(res.kspm.status).to.eql( 'not-installed', - `expected not-installed but got ${res.kspm.status} instead` + `expected kspm status to be not-installed but got ${res.kspm.status} instead` ); expect(res.vuln_mgmt.status).to.eql( 'not-deployed', - `expected not-deployed but got ${res.vuln_mgmt.status} instead` + `expected vuln_mgmt status to be not-deployed but got ${res.vuln_mgmt.status} instead` ); expect(res.vuln_mgmt.healthyAgents).to.eql( 0, - `expected 0 but got ${res.vuln_mgmt.healthyAgents} instead` + `expected number of vuln_mgmt healthy agents to be 0 but got ${res.vuln_mgmt.healthyAgents} instead` ); expect(res.vuln_mgmt.installedPackagePolicies).to.eql( 1, - `expected 1 but got ${res.vuln_mgmt.installedPackagePolicies} instead` + `expected number of vuln_mgmt installed package policies to be 1 but got ${res.vuln_mgmt.installedPackagePolicies} instead` ); }); }); diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts index 5dde5ab93cdab..946f22c27f77d 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts @@ -10,6 +10,7 @@ import { BENCHMARK_SCORE_INDEX_DEFAULT_NS, LATEST_FINDINGS_INDEX_DEFAULT_NS, LATEST_VULNERABILITIES_INDEX_DEFAULT_NS, + FINDINGS_INDEX_PATTERN, } from '@kbn/cloud-security-posture-plugin/common/constants'; import { FtrProviderContext } from '../../../ftr_provider_context'; import { @@ -153,21 +154,39 @@ export default function (providerContext: FtrProviderContext) { `expected unprivileged but got ${res.vuln_mgmt.status} instead` ); - expect(res.indicesDetails[0].status).to.eql( + expect( + res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status + ).to.eql( 'empty', - `expected empty but got ${res.indicesDetails[0].status} instead` + `expected empty but got ${ + res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status + } instead` ); - expect(res.indicesDetails[1].status).to.eql( + expect( + res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status + ).to.eql( 'empty', - `expected empty but got ${res.indicesDetails[1].status} instead` + `expected empty but got ${ + res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status + } instead` ); - expect(res.indicesDetails[2].status).to.eql( + expect( + res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status + ).to.eql( 'unprivileged', - `expected unprivileged but got ${res.indicesDetails[2].status} instead` + `expected unprivileged but got ${ + res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status + } instead` ); - expect(res.indicesDetails[3].status).to.eql( + expect( + res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS) + ?.status + ).to.eql( 'unprivileged', - `expected unprivileged but got ${res.indicesDetails[3].status} instead` + `expected unprivileged but got ${ + res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS) + ?.status + } instead` ); }); @@ -204,21 +223,39 @@ export default function (providerContext: FtrProviderContext) { `expected unprivileged but got ${res.vuln_mgmt.status} instead` ); - expect(res.indicesDetails[0].status).to.eql( + expect( + res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status + ).to.eql( 'unprivileged', - `expected unprivileged but got ${res.indicesDetails[0].status} instead` + `expected unprivileged but got ${ + res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status + } instead` ); - expect(res.indicesDetails[1].status).to.eql( + expect( + res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status + ).to.eql( 'empty', - `expected empty but got ${res.indicesDetails[1].status} instead` + `expected empty but got ${ + res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status + } instead` ); - expect(res.indicesDetails[2].status).to.eql( + expect( + res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status + ).to.eql( 'empty', - `expected empty but got ${res.indicesDetails[2].status} instead` + `expected empty but got ${ + res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status + } instead` ); - expect(res.indicesDetails[3].status).to.eql( + expect( + res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS) + ?.status + ).to.eql( 'unprivileged', - `expected unprivileged but got ${res.indicesDetails[3].status} instead` + `expected unprivileged but got ${ + res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS) + ?.status + } instead` ); }); @@ -258,21 +295,39 @@ export default function (providerContext: FtrProviderContext) { `expected not-installed but got ${res.vuln_mgmt.status} instead` ); - expect(res.indicesDetails[0].status).to.eql( + expect( + res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status + ).to.eql( 'unprivileged', - `expected unprivileged but got ${res.indicesDetails[0].status} instead` + `expected unprivileged but got ${ + res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status + } instead` ); - expect(res.indicesDetails[1].status).to.eql( + expect( + res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status + ).to.eql( 'empty', - `expected empty but got ${res.indicesDetails[1].status} instead` + `expected empty but got ${ + res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status + } instead` ); - expect(res.indicesDetails[2].status).to.eql( + expect( + res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status + ).to.eql( 'unprivileged', - `expected unprivileged but got ${res.indicesDetails[2].status} instead` + `expected unprivileged but got ${ + res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status + } instead` ); - expect(res.indicesDetails[3].status).to.eql( + expect( + res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS) + ?.status + ).to.eql( 'empty', - `expected empty but got ${res.indicesDetails[3].status} instead` + `expected empty but got ${ + res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS) + ?.status + } instead` ); }); }); diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_waiting_for_results.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_waiting_for_results.ts index 3543aa21edeba..bbf797b07280b 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_waiting_for_results.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_waiting_for_results.ts @@ -91,7 +91,7 @@ export default function (providerContext: FtrProviderContext) { .expect(200); expect(res.kspm.status).to.eql( 'waiting_for_results', - `expected waiting_for_results but got ${res.kspm.status} instead` + `expected kspm status to be waiting_for_results but got ${res.kspm.status} instead` ); }); @@ -119,7 +119,7 @@ export default function (providerContext: FtrProviderContext) { .expect(200); expect(res.cspm.status).to.eql( 'waiting_for_results', - `expected waiting_for_results but got ${res.cspm.status} instead` + `expected cspm status to be waiting_for_results but got ${res.cspm.status} instead` ); }); @@ -147,7 +147,7 @@ export default function (providerContext: FtrProviderContext) { .expect(200); expect(res.vuln_mgmt.status).to.eql( 'waiting_for_results', - `expected waiting_for_results but got ${res.vuln_mgmt.status} instead` + `expected vuln_mgmt status to be waiting_for_results but got ${res.vuln_mgmt.status} instead` ); }); }); From 05f554ecc18b5e5a11f27661e004eb73ebe14961 Mon Sep 17 00:00:00 2001 From: Ricky Ang Date: Thu, 29 Jun 2023 09:34:05 -0700 Subject: [PATCH 3/5] more pr comments --- .../apis/cloud_security_posture/helper.ts | 7 ++ .../status/status_unprivileged.ts | 119 +++--------------- 2 files changed, 26 insertions(+), 100 deletions(-) diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts b/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts index b659153b1bf69..62ac586495737 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts @@ -8,6 +8,8 @@ import type { SuperTest, Test } from 'supertest'; import { Client } from '@elastic/elasticsearch'; import { SecurityService } from '../../../../../test/common/services/security/security'; +import type { IndexDetails } from '../../../../../x-pack/plugins/cloud_security_posture/common/types'; +import expect from '@kbn/expect/expect'; export const deleteIndex = (es: Client, indexToBeDeleted: string[]) => { Promise.all([ @@ -141,3 +143,8 @@ export const deleteRole = async (security: SecurityService, roleName: string) => export const deleteUser = async (security: SecurityService, userName: string) => { await security.user.delete(userName); }; + +export const assertIndexStatus = (indicesDetails: IndexDetails[], indexName: string, expectedStatus: string) => { + const actualValue = indicesDetails.find((idx) => idx.index === indexName)?.status; + expect(actualValue).to.eql(expectedStatus, `expected ${indexName} to be ${expectedStatus} but got ${actualValue} instead`); +} diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts index 946f22c27f77d..e0c3242362533 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/status/status_unprivileged.ts @@ -20,6 +20,7 @@ import { deleteRole, deleteUser, deleteIndex, + assertIndexStatus, } from '../helper'; const UNPRIVILEGED_ROLE = 'unprivileged_test_role'; @@ -154,39 +155,13 @@ export default function (providerContext: FtrProviderContext) { `expected unprivileged but got ${res.vuln_mgmt.status} instead` ); - expect( - res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status - ).to.eql( - 'empty', - `expected empty but got ${ - res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status - } instead` - ); - expect( - res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status - ).to.eql( - 'empty', - `expected empty but got ${ - res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status - } instead` - ); - expect( - res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status - ).to.eql( - 'unprivileged', - `expected unprivileged but got ${ - res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status - } instead` - ); - expect( - res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS) - ?.status - ).to.eql( - 'unprivileged', - `expected unprivileged but got ${ - res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS) - ?.status - } instead` + assertIndexStatus(res.indicesDetails, LATEST_FINDINGS_INDEX_DEFAULT_NS, 'empty'); + assertIndexStatus(res.indicesDetails, FINDINGS_INDEX_PATTERN, 'empty'); + assertIndexStatus(res.indicesDetails, BENCHMARK_SCORE_INDEX_DEFAULT_NS, 'unprivileged'); + assertIndexStatus( + res.indicesDetails, + LATEST_VULNERABILITIES_INDEX_DEFAULT_NS, + 'unprivileged' ); }); @@ -223,39 +198,13 @@ export default function (providerContext: FtrProviderContext) { `expected unprivileged but got ${res.vuln_mgmt.status} instead` ); - expect( - res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status - ).to.eql( - 'unprivileged', - `expected unprivileged but got ${ - res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status - } instead` - ); - expect( - res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status - ).to.eql( - 'empty', - `expected empty but got ${ - res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status - } instead` - ); - expect( - res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status - ).to.eql( - 'empty', - `expected empty but got ${ - res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status - } instead` - ); - expect( - res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS) - ?.status - ).to.eql( - 'unprivileged', - `expected unprivileged but got ${ - res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS) - ?.status - } instead` + assertIndexStatus(res.indicesDetails, LATEST_FINDINGS_INDEX_DEFAULT_NS, 'unprivileged'); + assertIndexStatus(res.indicesDetails, FINDINGS_INDEX_PATTERN, 'empty'); + assertIndexStatus(res.indicesDetails, BENCHMARK_SCORE_INDEX_DEFAULT_NS, 'empty'); + assertIndexStatus( + res.indicesDetails, + LATEST_VULNERABILITIES_INDEX_DEFAULT_NS, + 'unprivileged' ); }); @@ -295,40 +244,10 @@ export default function (providerContext: FtrProviderContext) { `expected not-installed but got ${res.vuln_mgmt.status} instead` ); - expect( - res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status - ).to.eql( - 'unprivileged', - `expected unprivileged but got ${ - res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status - } instead` - ); - expect( - res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status - ).to.eql( - 'empty', - `expected empty but got ${ - res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status - } instead` - ); - expect( - res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status - ).to.eql( - 'unprivileged', - `expected unprivileged but got ${ - res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status - } instead` - ); - expect( - res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS) - ?.status - ).to.eql( - 'empty', - `expected empty but got ${ - res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS) - ?.status - } instead` - ); + assertIndexStatus(res.indicesDetails, LATEST_FINDINGS_INDEX_DEFAULT_NS, 'unprivileged'); + assertIndexStatus(res.indicesDetails, FINDINGS_INDEX_PATTERN, 'empty'); + assertIndexStatus(res.indicesDetails, BENCHMARK_SCORE_INDEX_DEFAULT_NS, 'unprivileged'); + assertIndexStatus(res.indicesDetails, LATEST_VULNERABILITIES_INDEX_DEFAULT_NS, 'empty'); }); }); }); From 6acff75f09c1e5774cff968d9a5f9e1c8a8c3525 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 29 Jun 2023 16:40:19 +0000 Subject: [PATCH 4/5] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../apis/cloud_security_posture/helper.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts b/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts index 62ac586495737..3203c1db5d212 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts @@ -7,9 +7,9 @@ import type { SuperTest, Test } from 'supertest'; import { Client } from '@elastic/elasticsearch'; +import expect from '@kbn/expect'; +import type { IndexDetails } from '@kbn/cloud-security-posture-plugin/common/types'; import { SecurityService } from '../../../../../test/common/services/security/security'; -import type { IndexDetails } from '../../../../../x-pack/plugins/cloud_security_posture/common/types'; -import expect from '@kbn/expect/expect'; export const deleteIndex = (es: Client, indexToBeDeleted: string[]) => { Promise.all([ @@ -144,7 +144,14 @@ export const deleteUser = async (security: SecurityService, userName: string) => await security.user.delete(userName); }; -export const assertIndexStatus = (indicesDetails: IndexDetails[], indexName: string, expectedStatus: string) => { - const actualValue = indicesDetails.find((idx) => idx.index === indexName)?.status; - expect(actualValue).to.eql(expectedStatus, `expected ${indexName} to be ${expectedStatus} but got ${actualValue} instead`); -} +export const assertIndexStatus = ( + indicesDetails: IndexDetails[], + indexName: string, + expectedStatus: string +) => { + const actualValue = indicesDetails.find((idx) => idx.index === indexName)?.status; + expect(actualValue).to.eql( + expectedStatus, + `expected ${indexName} to be ${expectedStatus} but got ${actualValue} instead` + ); +}; From 97d61f407025c409db1e4ea3cb0324ebb89323b8 Mon Sep 17 00:00:00 2001 From: Ricky Ang Date: Tue, 4 Jul 2023 09:12:18 -0700 Subject: [PATCH 5/5] pr comments --- .../apis/cloud_security_posture/helper.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts b/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts index 62ac586495737..79aede12385db 100644 --- a/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts +++ b/x-pack/test/api_integration/apis/cloud_security_posture/helper.ts @@ -7,9 +7,9 @@ import type { SuperTest, Test } from 'supertest'; import { Client } from '@elastic/elasticsearch'; +import expect from '@kbn/expect'; +import type { IndexDetails } from '@kbn/cloud-security-posture-plugin/common/types'; import { SecurityService } from '../../../../../test/common/services/security/security'; -import type { IndexDetails } from '../../../../../x-pack/plugins/cloud_security_posture/common/types'; -import expect from '@kbn/expect/expect'; export const deleteIndex = (es: Client, indexToBeDeleted: string[]) => { Promise.all([ @@ -144,7 +144,14 @@ export const deleteUser = async (security: SecurityService, userName: string) => await security.user.delete(userName); }; -export const assertIndexStatus = (indicesDetails: IndexDetails[], indexName: string, expectedStatus: string) => { - const actualValue = indicesDetails.find((idx) => idx.index === indexName)?.status; - expect(actualValue).to.eql(expectedStatus, `expected ${indexName} to be ${expectedStatus} but got ${actualValue} instead`); -} +export const assertIndexStatus = ( + indicesDetails: IndexDetails[], + indexName: string, + expectedStatus: string +) => { + const actualValue = indicesDetails.find((idx) => idx.index === indexName)?.status; + expect(actualValue).to.eql( + expectedStatus, + `expected ${indexName} status to be ${expectedStatus} but got ${actualValue} instead` + ); +};