forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cloud Security] Set up first api integration tests in serverless (el…
…astic#167169) ## Summary This PR is copying over part of the API integration tests for the `cloud_security_posture` plugin. It's a part of the work on elastic/security-team#7439. Some tests are not yet copied over as they need more research, as they rely on either creating new users in Kibana or on fleet utils. This functionality is not yet available in serverless out of the box. Why copy? From [Kibana Serverless e2e Test Guide](https://docs.google.com/document/d/1tiax7xoDYwFXYZjRTgVKkVMjN-SQzBWk4yn1JY6Z5UY/edit): > Stateful tests should be copied over and modified as required for these features to ensure thorough coverage. which tests are copied and adopted for serverless: `tests/api_integration/apis/cloud_security_posture/status/status_not_deployed_not_installed` `tests/api_integration/apis/cloud_security_posture/status/status_indexed` `tests/api_integration/apis/cloud_security_posture/status/status_indexing` `tests/api_integration/apis/cloud_security_posture/benchmark` `tests/api_integration/apis/cloud_security_posture/get_csp_rule_template` `tests/cloud_security_posture_api/telemetry` which tests are not yet adopted for serverless: `tests/api_integration/apis/cloud_security_posture/status/status_unprivileged` (user/roles model is different in serverless) `tests/api_integration/apis/cloud_security_posture/status/status_waiting_for_results` (fleet test utils are not available) `tests/api_integration/apis/cloud_security_posture/status/status_index_timeout` (fleet test utils are not available) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
650c156
commit 31f285a
Showing
13 changed files
with
1,307 additions
and
126 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
.../test_serverless/api_integration/test_suites/security/cloud_security_posture/benchmark.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import expect from '@kbn/expect'; | ||
import type { GetBenchmarkResponse } from '@kbn/cloud-security-posture-plugin/common/types'; | ||
import { | ||
ELASTIC_HTTP_VERSION_HEADER, | ||
X_ELASTIC_INTERNAL_ORIGIN_REQUEST, | ||
} from '@kbn/core-http-common'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { createPackagePolicy } from '../../../../../test/api_integration/apis/cloud_security_posture/helper'; // eslint-disable-line @kbn/imports/no_boundary_crossing | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
const esArchiver = getService('esArchiver'); | ||
const kibanaServer = getService('kibanaServer'); | ||
|
||
describe('GET /internal/cloud_security_posture/benchmark', () => { | ||
let agentPolicyId: string; | ||
let agentPolicyId2: string; | ||
let agentPolicyId3: string; | ||
let agentPolicyId4: string; | ||
|
||
beforeEach(async () => { | ||
await kibanaServer.savedObjects.cleanStandardList(); | ||
await esArchiver.load('x-pack/test/functional/es_archives/fleet/empty_fleet_server'); | ||
|
||
const { body: agentPolicyResponse } = await supertest | ||
.post(`/api/fleet/agent_policies`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ | ||
name: 'Test policy', | ||
namespace: 'default', | ||
}); | ||
|
||
agentPolicyId = agentPolicyResponse.item.id; | ||
|
||
const { body: agentPolicyResponse2 } = await supertest | ||
.post(`/api/fleet/agent_policies`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ | ||
name: 'Test policy 2', | ||
namespace: 'default', | ||
}); | ||
|
||
agentPolicyId2 = agentPolicyResponse2.item.id; | ||
|
||
const { body: agentPolicyResponse3 } = await supertest | ||
.post(`/api/fleet/agent_policies`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ | ||
name: 'Test policy 3', | ||
namespace: 'default', | ||
}); | ||
|
||
agentPolicyId3 = agentPolicyResponse3.item.id; | ||
|
||
const { body: agentPolicyResponse4 } = await supertest | ||
.post(`/api/fleet/agent_policies`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ | ||
name: 'Test policy 4', | ||
namespace: 'default', | ||
}); | ||
|
||
agentPolicyId4 = agentPolicyResponse4.item.id; | ||
|
||
await createPackagePolicy( | ||
supertest, | ||
agentPolicyId, | ||
'cspm', | ||
'cloudbeat/cis_aws', | ||
'aws', | ||
'cspm', | ||
'CSPM-1' | ||
); | ||
|
||
await createPackagePolicy( | ||
supertest, | ||
agentPolicyId2, | ||
'kspm', | ||
'cloudbeat/cis_k8s', | ||
'vanilla', | ||
'kspm', | ||
'KSPM-1' | ||
); | ||
|
||
await createPackagePolicy( | ||
supertest, | ||
agentPolicyId3, | ||
'vuln_mgmt', | ||
'cloudbeat/vuln_mgmt_aws', | ||
'aws', | ||
'vuln_mgmt', | ||
'CNVM-1' | ||
); | ||
|
||
await createPackagePolicy( | ||
supertest, | ||
agentPolicyId4, | ||
'kspm', | ||
'cloudbeat/cis_k8s', | ||
'vanilla', | ||
'kspm', | ||
'KSPM-2' | ||
); | ||
}); | ||
|
||
afterEach(async () => { | ||
await kibanaServer.savedObjects.cleanStandardList(); | ||
await esArchiver.unload('x-pack/test/functional/es_archives/fleet/empty_fleet_server'); | ||
}); | ||
|
||
it(`Should return non-empty array filled with Rules if user has CSP integrations`, async () => { | ||
const { body: res }: { body: GetBenchmarkResponse } = await supertest | ||
.get(`/internal/cloud_security_posture/benchmarks`) | ||
.set(ELASTIC_HTTP_VERSION_HEADER, '1') | ||
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'xxx') | ||
.set('kbn-xsrf', 'xxxx') | ||
.expect(200); | ||
|
||
expect(res.items.length).equal(3); | ||
expect(res.total).equal(3); | ||
}); | ||
|
||
it(`Should return array size 2 when we set per page to be only 2 (total element is still 3)`, async () => { | ||
const { body: res }: { body: GetBenchmarkResponse } = await supertest | ||
.get(`/internal/cloud_security_posture/benchmarks?per_page=2`) | ||
.set(ELASTIC_HTTP_VERSION_HEADER, '1') | ||
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'xxx') | ||
.set('kbn-xsrf', 'xxxx') | ||
.expect(200); | ||
|
||
expect(res.items.length).equal(2); | ||
expect(res.total).equal(3); | ||
}); | ||
|
||
it(`Should return array size 2 when we set per page to be only 2 (total element is still 3)`, async () => { | ||
const { body: res }: { body: GetBenchmarkResponse } = await supertest | ||
.get(`/internal/cloud_security_posture/benchmarks?per_page=2&page=2`) | ||
.set(ELASTIC_HTTP_VERSION_HEADER, '1') | ||
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'xxx') | ||
.set('kbn-xsrf', 'xxxx') | ||
.expect(200); | ||
|
||
expect(res.items.length).equal(1); | ||
expect(res.total).equal(3); | ||
}); | ||
|
||
it(`Should return empty array when we set page to be above the last page number`, async () => { | ||
const { body: res }: { body: GetBenchmarkResponse } = await supertest | ||
.get(`/internal/cloud_security_posture/benchmarks?per_page=2&page=3`) | ||
.set(ELASTIC_HTTP_VERSION_HEADER, '1') | ||
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'xxx') | ||
.set('kbn-xsrf', 'xxxx') | ||
.expect(200); | ||
|
||
expect(res.items.length).equal(0); | ||
expect(res.total).equal(3); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.