Skip to content

Commit

Permalink
[ftr] migrating 'saved_objects_management/bulk' API integration test …
Browse files Browse the repository at this point in the history
…to deployment-agnostic one (elastic#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 <[email protected]>
  • Loading branch information
dmlemeshko and kibanamachine authored Sep 10, 2024
1 parent 4d28bd6 commit 4cd23a1
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 50 deletions.
2 changes: 0 additions & 2 deletions test/api_integration/apis/saved_objects_management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@

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';
const validObject = { type: 'visualization', id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab' };
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(() =>
Expand Down Expand Up @@ -60,32 +60,23 @@ 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);
expectBadRequest(0, body);
});

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@

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' };
const invalidObject = { type: 'wigwags', id: 'foo' };

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', () => {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}
3 changes: 2 additions & 1 deletion x-pack/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
Expand Down

0 comments on commit 4cd23a1

Please sign in to comment.