diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/constants/archives_metadata.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/constants/archives_metadata.ts new file mode 100644 index 0000000000000..37a5dc2aa9a6f --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/constants/archives_metadata.ts @@ -0,0 +1,10 @@ +/* + * 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 archivesMetadata from '../../../../../../apm_api_integration/common/fixtures/es_archiver/archives_metadata'; + +export default archivesMetadata; diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts index e2662e40dd830..05946a76b4bc9 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts @@ -26,6 +26,7 @@ export default function apmApiIntegrationTests({ loadTestFile(require.resolve('./observability_overview')); loadTestFile(require.resolve('./latency')); loadTestFile(require.resolve('./infrastructure')); + loadTestFile(require.resolve('./inspect')); loadTestFile(require.resolve('./service_groups')); }); } diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/inspect/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/inspect/index.ts new file mode 100644 index 0000000000000..8169a30a04d0f --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/inspect/index.ts @@ -0,0 +1,14 @@ +/* + * 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('inspect', () => { + loadTestFile(require.resolve('./inspect.spec.ts')); + }); +} diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/inspect/inspect.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/inspect/inspect.spec.ts new file mode 100644 index 0000000000000..b2f93635b79f0 --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/inspect/inspect.spec.ts @@ -0,0 +1,94 @@ +/* + * 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 { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; +import { ARCHIVER_ROUTES } from '../constants/archiver'; +import archives_metadata from '../constants/archives_metadata'; + +export default function inspectFlagTests({ getService }: DeploymentAgnosticFtrProviderContext) { + const apmApiClient = getService('apmApi'); + const esArchiver = getService('esArchiver'); + + const archiveName = '8.0.0'; + const metadata = archives_metadata['apm_8.0.0']; + + describe('Inspect feature', () => { + before(async () => { + await esArchiver.load(ARCHIVER_ROUTES[archiveName]); + }); + after(async () => { + await esArchiver.unload(ARCHIVER_ROUTES[archiveName]); + }); + + describe('when omitting `_inspect` query param', () => { + it('returns response without `_inspect`', async () => { + const { status, body } = await apmApiClient.readUser({ + endpoint: 'GET /internal/apm/environments', + params: { + query: { + start: metadata.start, + end: metadata.end, + }, + }, + }); + + expect(status).to.be(200); + expect(body._inspect).to.be(undefined); + }); + }); + + describe('when passing `_inspect` as query param', () => { + describe('elasticsearch calls made with end-user auth are returned', () => { + it('for environments', async () => { + const { status, body } = await apmApiClient.readUser({ + endpoint: 'GET /internal/apm/environments', + params: { + query: { + start: metadata.start, + end: metadata.end, + _inspect: true, + }, + }, + }); + expect(status).to.be(200); + expect(body._inspect).not.to.be.empty(); + + // @ts-expect-error + expect(Object.keys(body._inspect[0])).to.eql([ + 'id', + 'json', + 'name', + 'response', + 'startTime', + 'stats', + 'status', + ]); + }); + }); + + describe('elasticsearch calls made with internal user should not leak internal queries', () => { + it('for custom links', async () => { + const { status, body } = await apmApiClient.readUser({ + endpoint: 'GET /internal/apm/settings/custom_links', + params: { + query: { + 'service.name': 'opbeans-node', + 'transaction.type': 'request', + _inspect: true, + }, + }, + }); + + expect(status).to.be(200); + expect(body._inspect).to.eql([]); + }); + }); + }); + }); +} diff --git a/x-pack/test/apm_api_integration/tests/inspect/inspect.spec.ts b/x-pack/test/apm_api_integration/tests/inspect/inspect.spec.ts index f15c9900488a0..b2e0931971a6e 100644 --- a/x-pack/test/apm_api_integration/tests/inspect/inspect.spec.ts +++ b/x-pack/test/apm_api_integration/tests/inspect/inspect.spec.ts @@ -8,79 +8,15 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../common/ftr_provider_context'; -import archives_metadata from '../../common/fixtures/es_archiver/archives_metadata'; - export default function inspectFlagTests({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); const archiveName = 'apm_8.0.0'; - const metadata = archives_metadata[archiveName]; registry.when('Inspect feature', { config: 'trial', archives: [archiveName] }, () => { - describe('when omitting `_inspect` query param', () => { - it('returns response without `_inspect`', async () => { - const { status, body } = await apmApiClient.readUser({ - endpoint: 'GET /internal/apm/environments', - params: { - query: { - start: metadata.start, - end: metadata.end, - }, - }, - }); - - expect(status).to.be(200); - expect(body._inspect).to.be(undefined); - }); - }); - describe('when passing `_inspect` as query param', () => { - describe('elasticsearch calls made with end-user auth are returned', () => { - it('for environments', async () => { - const { status, body } = await apmApiClient.readUser({ - endpoint: 'GET /internal/apm/environments', - params: { - query: { - start: metadata.start, - end: metadata.end, - _inspect: true, - }, - }, - }); - expect(status).to.be(200); - expect(body._inspect).not.to.be.empty(); - - // @ts-expect-error - expect(Object.keys(body._inspect[0])).to.eql([ - 'id', - 'json', - 'name', - 'response', - 'startTime', - 'stats', - 'status', - ]); - }); - }); - describe('elasticsearch calls made with internal user should not leak internal queries', () => { - it('for custom links', async () => { - const { status, body } = await apmApiClient.readUser({ - endpoint: 'GET /internal/apm/settings/custom_links', - params: { - query: { - 'service.name': 'opbeans-node', - 'transaction.type': 'request', - _inspect: true, - }, - }, - }); - - expect(status).to.be(200); - expect(body._inspect).to.eql([]); - }); - it('for agent configs', async () => { const { status, body } = await apmApiClient.readUser({ endpoint: 'GET /api/apm/settings/agent-configuration 2023-10-31',