Skip to content

Commit bf1137f

Browse files
[CLOUD] Add deployment data in the onboarding route (#235847)
## Summary elastic/cloud-ui#103 The data will be available via the `/internal/cloud/solution` API, the field is `resource_data.deployment.name` ### 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: kibanamachine <[email protected]>
1 parent b0ed513 commit bf1137f

File tree

3 files changed

+115
-2
lines changed

3 files changed

+115
-2
lines changed

x-pack/platform/plugins/shared/cloud/common/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export interface ResourceData {
2525
type: 'general' | 'vector' | 'timeseries';
2626
};
2727
};
28+
deployment?: {
29+
id?: string;
30+
name?: string;
31+
};
2832
}
2933
export interface CloudSecurityAnswer {
3034
useCase: 'siem' | 'cloud' | 'edr' | 'other';

x-pack/platform/plugins/shared/cloud/server/plugin.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,12 @@ export class CloudPlugin implements Plugin<CloudSetup, CloudStart> {
265265
),
266266
})
267267
),
268-
// Can be added in the future if needed:
269-
// deployment: schema.maybe(schema.object({})),
268+
deployment: schema.maybe(
269+
schema.object({
270+
id: schema.maybe(schema.string()),
271+
name: schema.maybe(schema.string()),
272+
})
273+
),
270274
})
271275
),
272276
},

x-pack/platform/test/functional_cloud/tests/onboarding.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,111 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
294294
});
295295
});
296296

297+
it('Redirect and save deployment at creation time', async () => {
298+
const resourceDataString = '{"deployment":{"id":"deployment-id","name":"deployment-name"}}';
299+
300+
await browser.get(
301+
deployment.getHostPort() +
302+
`/app/cloud/onboarding?onboarding_token=vector&resource_data=${resourceDataString}&next=${encodeURIComponent(
303+
'/app/security/get_started'
304+
)}#some=hash-value`
305+
);
306+
await find.byCssSelector('[data-test-subj="userMenuButton"]', 20000);
307+
308+
// We need to make sure that both path and hash are respected.
309+
const currentURL = parse(await browser.getCurrentUrl());
310+
expect(currentURL.pathname).to.eql('/app/security/get_started');
311+
expect(currentURL.hash).to.eql('#some=hash-value');
312+
313+
const {
314+
body: { onboardingData, resourceData },
315+
} = await supertest
316+
.get('/internal/cloud/solution')
317+
.set('kbn-xsrf', 'xxx')
318+
.set('x-elastic-internal-origin', 'cloud')
319+
.set('elastic-api-version', '1')
320+
.expect(200);
321+
expect(onboardingData).to.eql({
322+
token: 'vector',
323+
});
324+
325+
expect(resourceData).to.eql({
326+
deployment: {
327+
id: 'deployment-id',
328+
name: 'deployment-name',
329+
},
330+
});
331+
});
332+
333+
it('Redirect and update deployment', async () => {
334+
const resourceDataString = '{"deployment":{"id":"deployment-id","name":"deployment-name"}}';
335+
336+
await browser.get(
337+
deployment.getHostPort() +
338+
`/app/cloud/onboarding?onboarding_token=token&resource_data=${resourceDataString}&next=${encodeURIComponent(
339+
'/app/security/get_started'
340+
)}#some=hash-value`
341+
);
342+
await find.byCssSelector('[data-test-subj="userMenuButton"]', 20000);
343+
344+
// We need to make sure that both path and hash are respected.
345+
const currentURL = parse(await browser.getCurrentUrl());
346+
expect(currentURL.pathname).to.eql('/app/security/get_started');
347+
expect(currentURL.hash).to.eql('#some=hash-value');
348+
349+
const {
350+
body: { onboardingData, resourceData },
351+
} = await supertest
352+
.get('/internal/cloud/solution')
353+
.set('kbn-xsrf', 'xxx')
354+
.set('x-elastic-internal-origin', 'cloud')
355+
.set('elastic-api-version', '1')
356+
.expect(200);
357+
358+
expect(onboardingData).to.eql({
359+
token: 'token',
360+
});
361+
362+
expect(resourceData).to.eql({
363+
deployment: {
364+
id: 'deployment-id',
365+
name: 'deployment-name',
366+
},
367+
});
368+
369+
const resourceDataStringUpdated =
370+
'{"deployment":{"id":"new-deployment-id","name":"new-deployment-name"}}';
371+
372+
await browser.get(
373+
deployment.getHostPort() +
374+
`/app/cloud/onboarding?resource_data=${resourceDataStringUpdated}&next=${encodeURIComponent(
375+
'/app/security/get_started'
376+
)}#some=hash-value`
377+
);
378+
379+
await find.byCssSelector('[data-test-subj="userMenuButton"]', 20000);
380+
381+
const {
382+
body: { onboardingData: onboardingDataUpdated, resourceData: resourceDataUpdated },
383+
} = await supertest
384+
.get('/internal/cloud/solution')
385+
.set('kbn-xsrf', 'xxx')
386+
.set('x-elastic-internal-origin', 'cloud')
387+
.set('elastic-api-version', '1')
388+
.expect(200);
389+
390+
expect(onboardingDataUpdated).to.eql({
391+
token: 'token',
392+
});
393+
394+
expect(resourceDataUpdated).to.eql({
395+
deployment: {
396+
id: 'new-deployment-id',
397+
name: 'new-deployment-name',
398+
},
399+
});
400+
});
401+
297402
it(`Redirect and keep initial onboarding token when it's not provided on update`, async () => {
298403
const securityDetails = '{"use_case":"siem","migration":{"value":true,"type":"splunk"}}';
299404

0 commit comments

Comments
 (0)