From 4cd23a1df7579a6605be0f23f2db32b61ebdfe8f Mon Sep 17 00:00:00 2001 From: Dzmitry Lemechko Date: Tue, 10 Sep 2024 12:33:32 +0200 Subject: [PATCH] [ftr] migrating 'saved_objects_management/bulk' API integration test to deployment-agnostic one (#192070) ## Summary _The goal is to consolidate 2 existing test files with identical logic into a single, deployment-agnostic test file:_ Files to be replaced: - test/api_integration/apis/saved_objects_management/bulk_delete.ts - test/api_integration/apis/saved_objects_management/bulk_get.ts - x-pack/test_serverless/api_integration/test_suites/common/saved_objects_management/bulk_delete.ts - x-pack/test_serverless/api_integration/test_suites/common/saved_objects_management/bulk_get.ts New test file: - x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/bulk_delete.ts - x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/bulk_get.ts The migration leverages the serverless test file as a basis for the new deployment-agnostic test. Necessary modifications are minimal and include FTR context provider & its services to ensure compatibility across different environments. Lastly new file has to be loaded into both the serverless and stateful config files under `x-pack/test/api_integration/deployment_agnostic/configs` This approach ensures that the test logic remains consistent while reducing redundancy and maintenance effort. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .../apis/saved_objects_management/index.ts | 2 -- .../saved_objects_management/bulk_delete.ts | 33 +++++++---------- .../saved_objects_management/bulk_get.ts | 36 +++++++------------ .../apis/saved_objects_management/index.ts | 15 ++++++++ .../configs/serverless/oblt.index.ts | 1 + .../configs/serverless/search.index.ts | 1 + .../configs/serverless/security.index.ts | 1 + .../configs/stateful/platform.index.ts | 1 + x-pack/test/tsconfig.json | 3 +- .../common/saved_objects_management/index.ts | 2 -- 10 files changed, 45 insertions(+), 50 deletions(-) rename x-pack/{test_serverless/api_integration/test_suites/common => test/api_integration/deployment_agnostic/apis}/saved_objects_management/bulk_delete.ts (69%) rename x-pack/{test_serverless/api_integration/test_suites/common => test/api_integration/deployment_agnostic/apis}/saved_objects_management/bulk_get.ts (68%) create mode 100644 x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/index.ts diff --git a/test/api_integration/apis/saved_objects_management/index.ts b/test/api_integration/apis/saved_objects_management/index.ts index a2397148d5de8..66b72e89205da 100644 --- a/test/api_integration/apis/saved_objects_management/index.ts +++ b/test/api_integration/apis/saved_objects_management/index.ts @@ -12,8 +12,6 @@ import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ loadTestFile }: FtrProviderContext) { describe('saved objects management apis', () => { loadTestFile(require.resolve('./find')); - loadTestFile(require.resolve('./bulk_delete')); - loadTestFile(require.resolve('./bulk_get')); loadTestFile(require.resolve('./relationships')); loadTestFile(require.resolve('./scroll_count')); }); diff --git a/x-pack/test_serverless/api_integration/test_suites/common/saved_objects_management/bulk_delete.ts b/x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/bulk_delete.ts similarity index 69% rename from x-pack/test_serverless/api_integration/test_suites/common/saved_objects_management/bulk_delete.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/bulk_delete.ts index 33ef0942bb61f..80540ec06df11 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/saved_objects_management/bulk_delete.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/bulk_delete.ts @@ -7,15 +7,13 @@ import expect from '@kbn/expect'; import { SavedObjectWithMetadata } from '@kbn/saved-objects-management-plugin/common'; -import { FtrProviderContext } from '../../../ftr_provider_context'; -import { RoleCredentials } from '../../../../shared/services'; +import { DeploymentAgnosticFtrProviderContext } from '../../ftr_provider_context'; +import { SupertestWithRoleScopeType } from '../../services'; -export default function ({ getService }: FtrProviderContext) { - const svlCommonApi = getService('svlCommonApi'); - const svlUserManager = getService('svlUserManager'); - const supertestWithoutAuth = getService('supertestWithoutAuth'); +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const kibanaServer = getService('kibanaServer'); - let roleAuthc: RoleCredentials; + const roleScopedSupertest = getService('roleScopedSupertest'); + let supertestWithAdminScope: SupertestWithRoleScopeType; describe('_bulk_delete', () => { const endpoint = '/internal/kibana/management/saved_objects/_bulk_delete'; @@ -23,11 +21,13 @@ export default function ({ getService }: FtrProviderContext) { const invalidObject = { type: 'wigwags', id: 'foo' }; before(async () => { - roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin'); + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); }); after(async () => { - await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc); + await supertestWithAdminScope.destroy(); }); beforeEach(() => @@ -60,21 +60,14 @@ export default function ({ getService }: FtrProviderContext) { } it('should return 200 for an existing object', async () => { - const { body } = await supertestWithoutAuth - .post(endpoint) - .set(svlCommonApi.getInternalRequestHeader()) - .set(roleAuthc.apiKeyHeader) - .send([validObject]) - .expect(200); + const { body } = await supertestWithAdminScope.post(endpoint).send([validObject]).expect(200); expect(body).to.have.length(1); expectSuccess(0, body); }); it('should return error for invalid object type', async () => { - const { body } = await supertestWithoutAuth + const { body } = await supertestWithAdminScope .post(endpoint) - .set(svlCommonApi.getInternalRequestHeader()) - .set(roleAuthc.apiKeyHeader) .send([invalidObject]) .expect(200); expect(body).to.have.length(1); @@ -82,10 +75,8 @@ export default function ({ getService }: FtrProviderContext) { }); it('should return mix of successes and errors', async () => { - const { body } = await supertestWithoutAuth + const { body } = await supertestWithAdminScope .post(endpoint) - .set(svlCommonApi.getInternalRequestHeader()) - .set(roleAuthc.apiKeyHeader) .send([validObject, invalidObject]) .expect(200); expect(body).to.have.length(2); diff --git a/x-pack/test_serverless/api_integration/test_suites/common/saved_objects_management/bulk_get.ts b/x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/bulk_get.ts similarity index 68% rename from x-pack/test_serverless/api_integration/test_suites/common/saved_objects_management/bulk_get.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/bulk_get.ts index a215c72c41e1f..5a69530376004 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/saved_objects_management/bulk_get.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/bulk_get.ts @@ -7,15 +7,13 @@ import expect from '@kbn/expect'; import { SavedObjectWithMetadata } from '@kbn/saved-objects-management-plugin/common'; -import { FtrProviderContext } from '../../../ftr_provider_context'; -import { RoleCredentials } from '../../../../shared/services'; +import { DeploymentAgnosticFtrProviderContext } from '../../ftr_provider_context'; +import { SupertestWithRoleScopeType } from '../../services'; -export default function ({ getService }: FtrProviderContext) { - const svlCommonApi = getService('svlCommonApi'); - const svlUserManager = getService('svlUserManager'); - const supertestWithoutAuth = getService('supertestWithoutAuth'); +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const kibanaServer = getService('kibanaServer'); - let roleAuthc: RoleCredentials; + const roleScopedSupertest = getService('roleScopedSupertest'); + let supertestWithAdminScope: SupertestWithRoleScopeType; const URL = '/api/kibana/management/saved_objects/_bulk_get'; const validObject = { type: 'visualization', id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab' }; @@ -23,11 +21,13 @@ export default function ({ getService }: FtrProviderContext) { describe('_bulk_get', () => { before(async () => { - roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin'); + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); }); after(async () => { - await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc); + await supertestWithAdminScope.destroy(); }); describe('get objects in bulk', () => { @@ -62,32 +62,20 @@ export default function ({ getService }: FtrProviderContext) { } it('should return 200 for object that exists and inject metadata', async () => { - const { body } = await supertestWithoutAuth - .post(URL) - .set(svlCommonApi.getInternalRequestHeader()) - .set(roleAuthc.apiKeyHeader) - .send([validObject]) - .expect(200); + const { body } = await supertestWithAdminScope.post(URL).send([validObject]).expect(200); expect(body).to.have.length(1); expectSuccess(0, body); }); it('should return error for invalid object type', async () => { - const { body } = await supertestWithoutAuth - .post(URL) - .set(svlCommonApi.getInternalRequestHeader()) - .set(roleAuthc.apiKeyHeader) - .send([invalidObject]) - .expect(200); + const { body } = await supertestWithAdminScope.post(URL).send([invalidObject]).expect(200); expect(body).to.have.length(1); expectBadRequest(0, body); }); it('should return mix of successes and errors', async () => { - const { body } = await supertestWithoutAuth + const { body } = await supertestWithAdminScope .post(URL) - .set(svlCommonApi.getInternalRequestHeader()) - .set(roleAuthc.apiKeyHeader) .send([validObject, invalidObject]) .expect(200); expect(body).to.have.length(2); diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/index.ts new file mode 100644 index 0000000000000..40f106ad9cde8 --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/saved_objects_management/index.ts @@ -0,0 +1,15 @@ +/* + * 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 { DeploymentAgnosticFtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) { + describe('saved objects management apis', () => { + loadTestFile(require.resolve('./bulk_get')); + loadTestFile(require.resolve('./bulk_delete')); + }); +} diff --git a/x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.index.ts b/x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.index.ts index 6a2a8c3a7a51e..27ea0edba9432 100644 --- a/x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.index.ts +++ b/x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.index.ts @@ -12,6 +12,7 @@ export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) loadTestFile(require.resolve('../../apis/console')); loadTestFile(require.resolve('../../apis/core')); loadTestFile(require.resolve('../../apis/painless_lab')); + loadTestFile(require.resolve('../../apis/saved_objects_management')); loadTestFile(require.resolve('../../apis/observability/alerting')); }); } diff --git a/x-pack/test/api_integration/deployment_agnostic/configs/serverless/search.index.ts b/x-pack/test/api_integration/deployment_agnostic/configs/serverless/search.index.ts index 20acbd0d3b610..d7e95c89ee522 100644 --- a/x-pack/test/api_integration/deployment_agnostic/configs/serverless/search.index.ts +++ b/x-pack/test/api_integration/deployment_agnostic/configs/serverless/search.index.ts @@ -11,5 +11,6 @@ export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) // load new search and platform deployment-agnostic test here loadTestFile(require.resolve('../../apis/console')); loadTestFile(require.resolve('../../apis/core')); + loadTestFile(require.resolve('../../apis/saved_objects_management')); }); } diff --git a/x-pack/test/api_integration/deployment_agnostic/configs/serverless/security.index.ts b/x-pack/test/api_integration/deployment_agnostic/configs/serverless/security.index.ts index c091dfb0999b4..e3c01c76e99bd 100644 --- a/x-pack/test/api_integration/deployment_agnostic/configs/serverless/security.index.ts +++ b/x-pack/test/api_integration/deployment_agnostic/configs/serverless/security.index.ts @@ -12,5 +12,6 @@ export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) loadTestFile(require.resolve('../../apis/console')); loadTestFile(require.resolve('../../apis/core')); loadTestFile(require.resolve('../../apis/painless_lab')); + loadTestFile(require.resolve('../../apis/saved_objects_management')); }); } diff --git a/x-pack/test/api_integration/deployment_agnostic/configs/stateful/platform.index.ts b/x-pack/test/api_integration/deployment_agnostic/configs/stateful/platform.index.ts index 838c33af03054..2f7bb2281362f 100644 --- a/x-pack/test/api_integration/deployment_agnostic/configs/stateful/platform.index.ts +++ b/x-pack/test/api_integration/deployment_agnostic/configs/stateful/platform.index.ts @@ -13,5 +13,6 @@ export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) loadTestFile(require.resolve('../../apis/console')); loadTestFile(require.resolve('../../apis/core')); loadTestFile(require.resolve('../../apis/painless_lab')); + loadTestFile(require.resolve('../../apis/saved_objects_management')); }); } diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index 1173ef6b4d492..8918b2848bc36 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -180,6 +180,7 @@ "@kbn/security-solution-plugin/public/management/cypress", "@kbn/management-settings-ids", "@kbn/mock-idp-utils", - "@kbn/cloud-security-posture-common" + "@kbn/cloud-security-posture-common", + "@kbn/saved-objects-management-plugin" ] } diff --git a/x-pack/test_serverless/api_integration/test_suites/common/saved_objects_management/index.ts b/x-pack/test_serverless/api_integration/test_suites/common/saved_objects_management/index.ts index f5e6cdf72c90d..9a0b49d5fc8e8 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/saved_objects_management/index.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/saved_objects_management/index.ts @@ -12,8 +12,6 @@ export default function ({ loadTestFile }: FtrProviderContext) { this.tags(['esGate']); loadTestFile(require.resolve('./find')); - loadTestFile(require.resolve('./bulk_get')); - loadTestFile(require.resolve('./bulk_delete')); loadTestFile(require.resolve('./scroll_count')); loadTestFile(require.resolve('./relationships')); });