From 158a828a8e4cf78390fa8711666609c8e16a71ca Mon Sep 17 00:00:00 2001 From: Xavier Mouligneau Date: Tue, 19 Nov 2024 18:42:09 -0500 Subject: [PATCH] [CLOUD-UI] Cloud onboarding token (#198444) ## Summary The solution must be aware of the onboarding token from the cloud onboarding flow. With this information, it can redirect our users to the appropriate onboarding flow in Kibana based on their token. We need to create an API in kibana for cloud to save some basic data. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Christiane (Tina) Heiligers Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .buildkite/ftr_platform_stateful_configs.yml | 1 + .../current_fields.json | 1 + .../current_mappings.json | 4 + .../check_registered_types.test.ts | 1 + .../group3/type_registrations.test.ts | 1 + x-pack/plugins/cloud/server/plugin.ts | 14 ++- .../plugins/cloud/server/routes/constants.ts | 8 ++ ...earch_routes.ts => elasticsearch_route.ts} | 2 +- .../server/routes/get_cloud_data_route.ts | 43 +++++++ x-pack/plugins/cloud/server/routes/index.ts | 27 ++++ .../routes/set_cloud_data_route.test.ts | 119 ++++++++++++++++++ .../server/routes/set_cloud_data_route.ts | 92 ++++++++++++++ x-pack/plugins/cloud/server/routes/types.ts | 20 +++ .../cloud/server/saved_objects/index.ts | 27 ++++ .../cloud_data_model_versions.ts | 19 +++ .../saved_objects/model_versions/index.ts | 8 ++ x-pack/plugins/cloud/tsconfig.json | 1 + .../test/api_integration/apis/cloud/config.ts | 26 ++++ .../test/api_integration/apis/cloud/index.ts | 14 +++ .../apis/cloud/set_cloud_data_route.ts | 41 ++++++ 20 files changed, 465 insertions(+), 4 deletions(-) create mode 100644 x-pack/plugins/cloud/server/routes/constants.ts rename x-pack/plugins/cloud/server/routes/{elasticsearch_routes.ts => elasticsearch_route.ts} (96%) create mode 100644 x-pack/plugins/cloud/server/routes/get_cloud_data_route.ts create mode 100644 x-pack/plugins/cloud/server/routes/index.ts create mode 100644 x-pack/plugins/cloud/server/routes/set_cloud_data_route.test.ts create mode 100644 x-pack/plugins/cloud/server/routes/set_cloud_data_route.ts create mode 100644 x-pack/plugins/cloud/server/routes/types.ts create mode 100644 x-pack/plugins/cloud/server/saved_objects/index.ts create mode 100644 x-pack/plugins/cloud/server/saved_objects/model_versions/cloud_data_model_versions.ts create mode 100644 x-pack/plugins/cloud/server/saved_objects/model_versions/index.ts create mode 100644 x-pack/test/api_integration/apis/cloud/config.ts create mode 100644 x-pack/test/api_integration/apis/cloud/index.ts create mode 100644 x-pack/test/api_integration/apis/cloud/set_cloud_data_route.ts diff --git a/.buildkite/ftr_platform_stateful_configs.yml b/.buildkite/ftr_platform_stateful_configs.yml index 3db1d194e59aa..f55fc2f7b4898 100644 --- a/.buildkite/ftr_platform_stateful_configs.yml +++ b/.buildkite/ftr_platform_stateful_configs.yml @@ -375,3 +375,4 @@ enabled: - x-pack/test/custom_branding/config.ts # stateful config files that run deployment-agnostic tests - x-pack/test/api_integration/deployment_agnostic/configs/stateful/platform.stateful.config.ts + - x-pack/test/api_integration/apis/cloud/config.ts diff --git a/packages/kbn-check-mappings-update-cli/current_fields.json b/packages/kbn-check-mappings-update-cli/current_fields.json index 020b9a97753b4..619bdd6c29321 100644 --- a/packages/kbn-check-mappings-update-cli/current_fields.json +++ b/packages/kbn-check-mappings-update-cli/current_fields.json @@ -233,6 +233,7 @@ "payload.connector.type", "type" ], + "cloud": [], "cloud-security-posture-settings": [], "config": [ "buildNum" diff --git a/packages/kbn-check-mappings-update-cli/current_mappings.json b/packages/kbn-check-mappings-update-cli/current_mappings.json index 2409b7578da84..d6ec30393e099 100644 --- a/packages/kbn-check-mappings-update-cli/current_mappings.json +++ b/packages/kbn-check-mappings-update-cli/current_mappings.json @@ -788,6 +788,10 @@ } } }, + "cloud": { + "dynamic": false, + "properties": {} + }, "cloud-security-posture-settings": { "dynamic": false, "properties": {} diff --git a/src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts b/src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts index 0f186fba94b54..f16c956107c7b 100644 --- a/src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts +++ b/src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts @@ -80,6 +80,7 @@ describe('checking migration metadata changes on all registered SO types', () => "cases-rules": "6d1776f5c46a99e1a0f3085c537146c1cdfbc829", "cases-telemetry": "f219eb7e26772884342487fc9602cfea07b3cedc", "cases-user-actions": "483f10db9b3bd1617948d7032a98b7791bf87414", + "cloud": "b549f4f7ab1fd41aab366a66afa52a2a008aefea", "cloud-security-posture-settings": "e0f61c68bbb5e4cfa46ce8994fa001e417df51ca", "config": "179b3e2bc672626aafce3cf92093a113f456af38", "config-global": "8e8a134a2952df700d7d4ec51abb794bbd4cf6da", diff --git a/src/core/server/integration_tests/saved_objects/migrations/group3/type_registrations.test.ts b/src/core/server/integration_tests/saved_objects/migrations/group3/type_registrations.test.ts index 3ceba522d08cb..cee7f307ee67d 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/group3/type_registrations.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/group3/type_registrations.test.ts @@ -32,6 +32,7 @@ const previouslyRegisteredTypes = [ 'canvas-element', 'canvas-workpad', 'canvas-workpad-template', + 'cloud', 'cloud-security-posture-settings', 'cases', 'cases-comments', diff --git a/x-pack/plugins/cloud/server/plugin.ts b/x-pack/plugins/cloud/server/plugin.ts index 9821aa318e264..8b20906c30f89 100644 --- a/x-pack/plugins/cloud/server/plugin.ts +++ b/x-pack/plugins/cloud/server/plugin.ts @@ -9,6 +9,7 @@ import type { Logger } from '@kbn/logging'; import type { CoreSetup, Plugin, PluginInitializerContext } from '@kbn/core/server'; import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server'; import type { SolutionId } from '@kbn/core-chrome-browser'; + import { registerCloudDeploymentMetadataAnalyticsContext } from '../common/register_cloud_deployment_id_analytics_context'; import type { CloudConfigType } from './config'; import { registerCloudUsageCollector } from './collectors'; @@ -18,7 +19,9 @@ import { decodeCloudId, DecodedCloudId } from '../common/decode_cloud_id'; import { parseOnboardingSolution } from '../common/parse_onboarding_default_solution'; import { getFullCloudUrl } from '../common/utils'; import { readInstanceSizeMb } from './env'; -import { defineRoutes } from './routes/elasticsearch_routes'; +import { defineRoutes } from './routes'; +import { CloudRequestHandlerContext } from './routes/types'; +import { setupSavedObjects } from './saved_objects'; interface PluginsSetup { usageCollection?: UsageCollectionSetup; @@ -202,10 +205,15 @@ export class CloudPlugin implements Plugin { if (this.config.id) { decodedId = decodeCloudId(this.config.id, this.logger); } - const router = core.http.createRouter(); + const router = core.http.createRouter(); const elasticsearchUrl = core.elasticsearch.publicBaseUrl || decodedId?.elasticsearchUrl; - defineRoutes({ logger: this.logger, router, elasticsearchUrl }); + defineRoutes({ + logger: this.logger, + router, + elasticsearchUrl, + }); + setupSavedObjects(core.savedObjects, this.logger); return { ...this.getCloudUrls(), cloudId: this.config.id, diff --git a/x-pack/plugins/cloud/server/routes/constants.ts b/x-pack/plugins/cloud/server/routes/constants.ts new file mode 100644 index 0000000000000..a1bfb699ac6b1 --- /dev/null +++ b/x-pack/plugins/cloud/server/routes/constants.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export const CLOUD_DATA_SAVED_OBJECT_ID = 'cloud-data-saved-object-id'; diff --git a/x-pack/plugins/cloud/server/routes/elasticsearch_routes.ts b/x-pack/plugins/cloud/server/routes/elasticsearch_route.ts similarity index 96% rename from x-pack/plugins/cloud/server/routes/elasticsearch_routes.ts rename to x-pack/plugins/cloud/server/routes/elasticsearch_route.ts index d3a5c4bebf305..41537a6dc075b 100644 --- a/x-pack/plugins/cloud/server/routes/elasticsearch_routes.ts +++ b/x-pack/plugins/cloud/server/routes/elasticsearch_route.ts @@ -10,7 +10,7 @@ import { Logger } from '@kbn/logging'; import { ElasticsearchConfigType } from '../../common/types'; import { ELASTICSEARCH_CONFIG_ROUTE } from '../../common/constants'; -export function defineRoutes({ +export function setElasticsearchRoute({ elasticsearchUrl, logger, router, diff --git a/x-pack/plugins/cloud/server/routes/get_cloud_data_route.ts b/x-pack/plugins/cloud/server/routes/get_cloud_data_route.ts new file mode 100644 index 0000000000000..c905e4b641c0c --- /dev/null +++ b/x-pack/plugins/cloud/server/routes/get_cloud_data_route.ts @@ -0,0 +1,43 @@ +/* + * 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 { RouteOptions } from '.'; +import { CLOUD_DATA_SAVED_OBJECT_ID } from './constants'; +import { CLOUD_DATA_SAVED_OBJECT_TYPE } from '../saved_objects'; +import { CloudDataAttributes } from './types'; + +export const setGetCloudSolutionDataRoute = ({ router }: RouteOptions) => { + router.versioned + .get({ + path: `/internal/cloud/solution`, + access: 'internal', + summary: 'Get cloud data for solutions', + }) + .addVersion( + { + version: '1', + validate: { + request: {}, + }, + }, + async (context, request, response) => { + const coreContext = await context.core; + const savedObjectsClient = coreContext.savedObjects.getClient({ + includedHiddenTypes: [CLOUD_DATA_SAVED_OBJECT_TYPE], + }); + try { + const cloudDataSo = await savedObjectsClient.get( + CLOUD_DATA_SAVED_OBJECT_TYPE, + CLOUD_DATA_SAVED_OBJECT_ID + ); + return response.ok({ body: cloudDataSo?.attributes ?? null }); + } catch (error) { + return response.customError(error); + } + } + ); +}; diff --git a/x-pack/plugins/cloud/server/routes/index.ts b/x-pack/plugins/cloud/server/routes/index.ts new file mode 100644 index 0000000000000..5db24b880881c --- /dev/null +++ b/x-pack/plugins/cloud/server/routes/index.ts @@ -0,0 +1,27 @@ +/* + * 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 { IRouter } from '@kbn/core/server'; +import { Logger } from '@kbn/logging'; +import { setPostCloudSolutionDataRoute } from './set_cloud_data_route'; +import { CloudRequestHandlerContext } from './types'; +import { setElasticsearchRoute } from './elasticsearch_route'; +import { setGetCloudSolutionDataRoute } from './get_cloud_data_route'; + +export interface RouteOptions { + logger: Logger; + router: IRouter; + elasticsearchUrl?: string; +} + +export function defineRoutes(opts: RouteOptions) { + const { logger, elasticsearchUrl, router } = opts; + + setElasticsearchRoute({ logger, elasticsearchUrl, router }); + setGetCloudSolutionDataRoute({ logger, router }); + setPostCloudSolutionDataRoute({ logger, router }); +} diff --git a/x-pack/plugins/cloud/server/routes/set_cloud_data_route.test.ts b/x-pack/plugins/cloud/server/routes/set_cloud_data_route.test.ts new file mode 100644 index 0000000000000..c36e49206a287 --- /dev/null +++ b/x-pack/plugins/cloud/server/routes/set_cloud_data_route.test.ts @@ -0,0 +1,119 @@ +/* + * 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 { httpServerMock, httpServiceMock } from '@kbn/core/server/mocks'; +import { + RequestHandlerContext, + RouteValidatorConfig, + SavedObjectsErrorHelpers, + kibanaResponseFactory, +} from '@kbn/core/server'; +import { CLOUD_DATA_SAVED_OBJECT_TYPE } from '../saved_objects'; +import { CLOUD_DATA_SAVED_OBJECT_ID } from './constants'; +import { setPostCloudSolutionDataRoute } from './set_cloud_data_route'; +import { RouteOptions } from '.'; + +const mockSavedObjectsClientGet = jest.fn(); +const mockSavedObjectsClientCreate = jest.fn(); +const mockSavedObjectsClientUpdate = jest.fn(); + +const mockRouteContext = { + core: { + savedObjects: { + getClient: () => ({ + get: mockSavedObjectsClientGet, + create: mockSavedObjectsClientCreate, + update: mockSavedObjectsClientUpdate, + }), + }, + }, +} as unknown as RequestHandlerContext; + +describe('POST /internal/cloud/solution', () => { + const setup = async () => { + const httpService = httpServiceMock.createSetupContract(); + const router = httpService.createRouter(); + + setPostCloudSolutionDataRoute({ + router, + } as unknown as RouteOptions); + + const [routeDefinition, routeHandler] = + router.versioned.post.mock.results[0].value.addVersion.mock.calls[0]; + + return { + routeValidation: routeDefinition.validate as RouteValidatorConfig<{}, {}, {}>, + routeHandler, + }; + }; + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('should create cloud data if it does not exist', async () => { + const { routeHandler } = await setup(); + + mockSavedObjectsClientGet.mockRejectedValue( + SavedObjectsErrorHelpers.createGenericNotFoundError() + ); + + const request = httpServerMock.createKibanaRequest({ + body: { + onboardingData: { + solutionType: 'security', + token: 'test-token', + }, + }, + method: 'post', + }); + + await routeHandler(mockRouteContext, request, kibanaResponseFactory); + + expect(mockSavedObjectsClientGet).toHaveBeenCalledWith( + CLOUD_DATA_SAVED_OBJECT_TYPE, + CLOUD_DATA_SAVED_OBJECT_ID + ); + expect(mockSavedObjectsClientCreate).toHaveBeenCalledWith( + CLOUD_DATA_SAVED_OBJECT_TYPE, + { onboardingData: request.body.onboardingData }, + { id: CLOUD_DATA_SAVED_OBJECT_ID } + ); + }); + + it('should update cloud data if it exists', async () => { + const { routeHandler } = await setup(); + + mockSavedObjectsClientGet.mockResolvedValue({ + id: CLOUD_DATA_SAVED_OBJECT_ID, + attributes: { + onboardingData: { solutionType: 'o11y', token: 'test-33' }, + }, + }); + + const request = httpServerMock.createKibanaRequest({ + body: { + onboardingData: { + solutionType: 'security', + token: 'test-token', + }, + }, + method: 'post', + }); + + await routeHandler(mockRouteContext, request, kibanaResponseFactory); + + expect(mockSavedObjectsClientGet).toHaveBeenCalledWith( + CLOUD_DATA_SAVED_OBJECT_TYPE, + CLOUD_DATA_SAVED_OBJECT_ID + ); + expect(mockSavedObjectsClientUpdate).toHaveBeenCalledWith( + CLOUD_DATA_SAVED_OBJECT_TYPE, + CLOUD_DATA_SAVED_OBJECT_ID, + { onboardingData: request.body.onboardingData } + ); + }); +}); diff --git a/x-pack/plugins/cloud/server/routes/set_cloud_data_route.ts b/x-pack/plugins/cloud/server/routes/set_cloud_data_route.ts new file mode 100644 index 0000000000000..511c8dc2081f0 --- /dev/null +++ b/x-pack/plugins/cloud/server/routes/set_cloud_data_route.ts @@ -0,0 +1,92 @@ +/* + * 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 { schema } from '@kbn/config-schema'; +import { ReservedPrivilegesSet, SavedObjectsErrorHelpers } from '@kbn/core/server'; +import { RouteOptions } from '.'; +import { CLOUD_DATA_SAVED_OBJECT_ID } from './constants'; +import { CLOUD_DATA_SAVED_OBJECT_TYPE } from '../saved_objects'; +import { CloudDataAttributes } from './types'; + +const createBodySchemaV1 = schema.object({ + onboardingData: schema.object({ + solutionType: schema.oneOf([ + schema.literal('security'), + schema.literal('observability'), + schema.literal('search'), + schema.literal('elasticsearch'), + ]), + token: schema.string(), + }), +}); + +export const setPostCloudSolutionDataRoute = ({ router }: RouteOptions) => { + router.versioned + .post({ + path: `/internal/cloud/solution`, + access: 'internal', + summary: 'Save cloud data for solutions', + security: { + authz: { + requiredPrivileges: [ReservedPrivilegesSet.superuser], + }, + }, + }) + .addVersion( + { + version: '1', + validate: { + request: { + body: createBodySchemaV1, + }, + }, + }, + async (context, request, response) => { + const coreContext = await context.core; + const savedObjectsClient = coreContext.savedObjects.getClient({ + includedHiddenTypes: [CLOUD_DATA_SAVED_OBJECT_TYPE], + }); + let cloudDataSo = null; + try { + cloudDataSo = await savedObjectsClient.get( + CLOUD_DATA_SAVED_OBJECT_TYPE, + CLOUD_DATA_SAVED_OBJECT_ID + ); + } catch (error) { + if (SavedObjectsErrorHelpers.isNotFoundError(error)) { + cloudDataSo = null; + } else { + return response.customError(error); + } + } + + try { + if (cloudDataSo === null) { + await savedObjectsClient.create( + CLOUD_DATA_SAVED_OBJECT_TYPE, + { + onboardingData: request.body.onboardingData, + }, + { id: CLOUD_DATA_SAVED_OBJECT_ID } + ); + } else { + await savedObjectsClient.update( + CLOUD_DATA_SAVED_OBJECT_TYPE, + CLOUD_DATA_SAVED_OBJECT_ID, + { + onboardingData: request.body.onboardingData, + } + ); + } + } catch (error) { + return response.badRequest(error); + } + + return response.ok(); + } + ); +}; diff --git a/x-pack/plugins/cloud/server/routes/types.ts b/x-pack/plugins/cloud/server/routes/types.ts new file mode 100644 index 0000000000000..d69877c7b326e --- /dev/null +++ b/x-pack/plugins/cloud/server/routes/types.ts @@ -0,0 +1,20 @@ +/* + * 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 { CustomRequestHandlerContext } from '@kbn/core/server'; + +/** + * @internal + */ +export type CloudRequestHandlerContext = CustomRequestHandlerContext<{}>; + +export interface CloudDataAttributes { + onboardingData: { + solutionType: 'security' | 'observability' | 'search' | 'elasticsearch'; + token: string; + }; +} diff --git a/x-pack/plugins/cloud/server/saved_objects/index.ts b/x-pack/plugins/cloud/server/saved_objects/index.ts new file mode 100644 index 0000000000000..295e6d81a39fb --- /dev/null +++ b/x-pack/plugins/cloud/server/saved_objects/index.ts @@ -0,0 +1,27 @@ +/* + * 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 { Logger, SavedObjectsServiceSetup } from '@kbn/core/server'; + +export const CLOUD_DATA_SAVED_OBJECT_TYPE = 'cloud' as const; + +export function setupSavedObjects(savedObjects: SavedObjectsServiceSetup, logger: Logger) { + savedObjects.registerType({ + name: CLOUD_DATA_SAVED_OBJECT_TYPE, + hidden: true, + hiddenFromHttpApis: true, + namespaceType: 'agnostic', + mappings: { + dynamic: false, + properties: {}, + }, + management: { + importableAndExportable: false, + }, + modelVersions: {}, + }); +} diff --git a/x-pack/plugins/cloud/server/saved_objects/model_versions/cloud_data_model_versions.ts b/x-pack/plugins/cloud/server/saved_objects/model_versions/cloud_data_model_versions.ts new file mode 100644 index 0000000000000..051a733d39178 --- /dev/null +++ b/x-pack/plugins/cloud/server/saved_objects/model_versions/cloud_data_model_versions.ts @@ -0,0 +1,19 @@ +/* + * 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 { SavedObjectsModelVersionMap } from '@kbn/core-saved-objects-server'; +import { schema } from '@kbn/config-schema'; + +export const cloudDataModelVersions: SavedObjectsModelVersionMap = { + '1': { + changes: [], + schemas: { + forwardCompatibility: schema.object({}).extends({}, { unknowns: 'ignore' }), + create: schema.object({}), + }, + }, +}; diff --git a/x-pack/plugins/cloud/server/saved_objects/model_versions/index.ts b/x-pack/plugins/cloud/server/saved_objects/model_versions/index.ts new file mode 100644 index 0000000000000..51e8b5431c547 --- /dev/null +++ b/x-pack/plugins/cloud/server/saved_objects/model_versions/index.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export { cloudDataModelVersions } from './cloud_data_model_versions'; diff --git a/x-pack/plugins/cloud/tsconfig.json b/x-pack/plugins/cloud/tsconfig.json index dd25064897758..37d0b6f4b4de0 100644 --- a/x-pack/plugins/cloud/tsconfig.json +++ b/x-pack/plugins/cloud/tsconfig.json @@ -17,6 +17,7 @@ "@kbn/config-schema", "@kbn/logging-mocks", "@kbn/logging", + "@kbn/core-saved-objects-server", ], "exclude": [ "target/**/*", diff --git a/x-pack/test/api_integration/apis/cloud/config.ts b/x-pack/test/api_integration/apis/cloud/config.ts new file mode 100644 index 0000000000000..87000e8fc5427 --- /dev/null +++ b/x-pack/test/api_integration/apis/cloud/config.ts @@ -0,0 +1,26 @@ +/* + * 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 { FtrConfigProviderContext } from '@kbn/test'; + +export default async function ({ readConfigFile }: FtrConfigProviderContext) { + const baseIntegrationTestsConfig = await readConfigFile(require.resolve('../../config.ts')); + + return { + ...baseIntegrationTestsConfig.getAll(), + testFiles: [require.resolve('.')], + kbnTestServer: { + ...baseIntegrationTestsConfig.get('kbnTestServer'), + serverArgs: [ + ...baseIntegrationTestsConfig.get('kbnTestServer.serverArgs'), + '--xpack.cloud.id="ftr_fake_cloud_id:aGVsbG8uY29tOjQ0MyRFUzEyM2FiYyRrYm4xMjNhYmM="', + '--xpack.cloud.base_url="https://cloud.elastic.co"', + '--xpack.spaces.allowSolutionVisibility=true', + ], + }, + }; +} diff --git a/x-pack/test/api_integration/apis/cloud/index.ts b/x-pack/test/api_integration/apis/cloud/index.ts new file mode 100644 index 0000000000000..819a9474e0752 --- /dev/null +++ b/x-pack/test/api_integration/apis/cloud/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 { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('cloud data', function () { + loadTestFile(require.resolve('./set_cloud_data_route')); + }); +} diff --git a/x-pack/test/api_integration/apis/cloud/set_cloud_data_route.ts b/x-pack/test/api_integration/apis/cloud/set_cloud_data_route.ts new file mode 100644 index 0000000000000..84331ab4c129d --- /dev/null +++ b/x-pack/test/api_integration/apis/cloud/set_cloud_data_route.ts @@ -0,0 +1,41 @@ +/* + * 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 { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + + describe('POST /internal/cloud/solution', () => { + it('set solution data', async () => { + await supertest + .post('/internal/cloud/solution') + .set('kbn-xsrf', 'xxx') + .set('x-elastic-internal-origin', 'cloud') + .set('elastic-api-version', '1') + .send({ + onboardingData: { + solutionType: 'search', + token: 'connectors', + }, + }) + .expect(200); + + const { + body: { onboardingData }, + } = await supertest + .get('/internal/cloud/solution') + .set('kbn-xsrf', 'xxx') + .set('x-elastic-internal-origin', 'cloud') + .set('elastic-api-version', '1') + .expect(200); + + expect(onboardingData).to.eql({ solutionType: 'search', token: 'connectors' }); + }); + }); +}