From b465da8e033248bec95fb1f125db9727d24579fa Mon Sep 17 00:00:00 2001 From: Josh Dover Date: Wed, 22 Jan 2020 14:16:28 -0700 Subject: [PATCH] Add smoke tests --- .../plugins/core_plugin_b/public/plugin.tsx | 14 +++++++++-- .../plugins/core_plugin_b/server/plugin.ts | 10 ++++++++ .../core_plugins/server_plugins.ts | 10 ++++++++ .../test_suites/core_plugins/ui_plugins.ts | 24 ++++++++++++++++++- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/test/plugin_functional/plugins/core_plugin_b/public/plugin.tsx b/test/plugin_functional/plugins/core_plugin_b/public/plugin.tsx index bda1557bdaf915..39290b066fab7c 100644 --- a/test/plugin_functional/plugins/core_plugin_b/public/plugin.tsx +++ b/test/plugin_functional/plugins/core_plugin_b/public/plugin.tsx @@ -17,7 +17,7 @@ * under the License. */ -import { CoreSetup, Plugin, PluginInitializerContext } from 'kibana/public'; +import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'kibana/public'; import { CorePluginAPluginSetup } from '../../core_plugin_a/public/plugin'; declare global { @@ -52,7 +52,17 @@ export class CorePluginBPlugin }; } - public start() {} + public async start(core: CoreStart, deps: {}) { + return { + sendSystemRequest: async (asSystemRequest: boolean) => { + const response = await core.http.post('/core_plugin_b/system_request', { + asSystemRequest, + }); + return `/core_plugin_b/system_request says: "${response}"`; + }, + }; + } + public stop() {} } diff --git a/test/plugin_functional/plugins/core_plugin_b/server/plugin.ts b/test/plugin_functional/plugins/core_plugin_b/server/plugin.ts index 91a4fe89c1c57e..d2bb9222a23fa1 100644 --- a/test/plugin_functional/plugins/core_plugin_b/server/plugin.ts +++ b/test/plugin_functional/plugins/core_plugin_b/server/plugin.ts @@ -54,6 +54,16 @@ export class CorePluginBPlugin implements Plugin { return res.ok({ body: `ID: ${req.query.id} - ${req.body.bar.toUpperCase()}` }); } ); + + router.post( + { + path: '/core_plugin_b/system_request', + validate: false, + }, + async (context, req, res) => { + return res.ok({ body: `System request? ${req.isSystemRequest}` }); + } + ); } public start() {} diff --git a/test/plugin_functional/test_suites/core_plugins/server_plugins.ts b/test/plugin_functional/test_suites/core_plugins/server_plugins.ts index eb232b14589917..f5b45d36944e1d 100644 --- a/test/plugin_functional/test_suites/core_plugins/server_plugins.ts +++ b/test/plugin_functional/test_suites/core_plugins/server_plugins.ts @@ -54,5 +54,15 @@ export default function({ getService }: PluginFunctionalProviderContext) { statusCode: 400, }); }); + + it('sets request.isSystemRequest when kbn-system-request header is set', async () => { + await supertest + .post('/core_plugin_b/system_request') + .set('kbn-xsrf', 'anything') + .set('kbn-system-request', 'true') + .send() + .expect(200) + .expect('System request? true'); + }); }); } diff --git a/test/plugin_functional/test_suites/core_plugins/ui_plugins.ts b/test/plugin_functional/test_suites/core_plugins/ui_plugins.ts index b76463ee767393..82267d73782af0 100644 --- a/test/plugin_functional/test_suites/core_plugins/ui_plugins.ts +++ b/test/plugin_functional/test_suites/core_plugins/ui_plugins.ts @@ -64,7 +64,7 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider }); }); - describe('have env data provided', function describeIndexTests() { + describe('have env data provided', () => { before(async () => { await PageObjects.common.navigateToApp('bar'); }); @@ -75,5 +75,27 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider expect(envData.packageInfo.version).to.be.a('string'); }); }); + + describe('http fetching', () => { + before(async () => { + await PageObjects.common.navigateToApp('settings'); + }); + + it('should send kbn-system-request header when asSystemRequest: true', async () => { + expect( + await browser.executeAsync(async cb => { + window.__coreProvider.start.plugins.core_plugin_b.sendSystemRequest(true).then(cb); + }) + ).to.be('/core_plugin_b/system_request says: "System request? true"'); + }); + + it('should not send kbn-system-request header when asSystemRequest: false', async () => { + expect( + await browser.executeAsync(async cb => { + window.__coreProvider.start.plugins.core_plugin_b.sendSystemRequest(false).then(cb); + }) + ).to.be('/core_plugin_b/system_request says: "System request? false"'); + }); + }); }); }