diff --git a/src/plugins/data/public/search/search_interceptor/search_interceptor.ts b/src/plugins/data/public/search/search_interceptor/search_interceptor.ts index cdc91a49e29a0..00ed4226fea3d 100644 --- a/src/plugins/data/public/search/search_interceptor/search_interceptor.ts +++ b/src/plugins/data/public/search/search_interceptor/search_interceptor.ts @@ -298,10 +298,12 @@ export class SearchInterceptor { isSavedToBackground = true; }); - const cancel = once(() => { - if (id && !isSavedToBackground) this.deps.http.delete(`/internal/search/${strategy}/${id}`); + const sendCancelRequest = once(() => { + this.deps.http.delete(`/internal/search/${strategy}/${id}`, { version: '1' }); }); + const cancel = () => id && !isSavedToBackground && sendCancelRequest(); + return pollSearch(search, cancel, { pollInterval: this.deps.searchConfig.asyncSearch.pollInterval, ...options, @@ -346,6 +348,7 @@ export class SearchInterceptor { const { executionContext, strategy, ...searchOptions } = this.getSerializableOptions(options); return this.deps.http .post(`/internal/search/${strategy}${request.id ? `/${request.id}` : ''}`, { + version: '1', signal: abortSignal, context: executionContext, body: JSON.stringify({ diff --git a/src/plugins/data/server/search/routes/search.test.ts b/src/plugins/data/server/search/routes/search.test.ts index c10401dd12f77..10b7755b2c30f 100644 --- a/src/plugins/data/server/search/routes/search.test.ts +++ b/src/plugins/data/server/search/routes/search.test.ts @@ -27,7 +27,15 @@ describe('Search service', () => { registerSearchRoute(mockCoreSetup.http.createRouter()); const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; - const handler = mockRouter.post.mock.calls[0][1]; + const handler = mockRouter.versioned.post.mock.results[0].value.addVersion.mock.calls[0][1]; + await handler(mockContext as unknown as RequestHandlerContext, mockRequest, mockResponse); + } + + async function runMockDelete(mockContext: any, mockRequest: any, mockResponse: any) { + registerSearchRoute(mockCoreSetup.http.createRouter()); + + const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; + const handler = mockRouter.versioned.delete.mock.results[0].value.addVersion.mock.calls[0][1]; await handler(mockContext as unknown as RequestHandlerContext, mockRequest, mockResponse); } @@ -156,4 +164,26 @@ describe('Search service', () => { expect(error.body.message).toBe('This is odd'); expect(error.body.attributes).toBe(undefined); }); + + it('DELETE request calls cancel with the given ID and strategy', async () => { + const mockContext = { + search: { + cancel: jest.fn(), + }, + }; + + const id = '1234'; + const strategy = 'foo'; + const params = { id, strategy }; + + const mockRequest = httpServerMock.createKibanaRequest({ + params, + }); + const mockResponse = httpServerMock.createResponseFactory(); + + await runMockDelete(mockContext, mockRequest, mockResponse); + + expect(mockContext.search.cancel).toBeCalled(); + expect(mockContext.search.cancel).toBeCalledWith(id, { strategy }); + }); }); diff --git a/src/plugins/data/server/search/routes/search.ts b/src/plugins/data/server/search/routes/search.ts index 94f26aebb5e1d..9d338095f25c0 100644 --- a/src/plugins/data/server/search/routes/search.ts +++ b/src/plugins/data/server/search/routes/search.ts @@ -12,82 +12,97 @@ import { reportServerError } from '@kbn/kibana-utils-plugin/server'; import { getRequestAbortedSignal } from '../../lib'; import type { DataPluginRouter } from '../types'; -export function registerSearchRoute(router: DataPluginRouter): void { - router.post( - { - path: '/internal/search/{strategy}/{id?}', - validate: { - params: schema.object({ - strategy: schema.string(), - id: schema.maybe(schema.string()), - }), +export const SEARCH_API_BASE_URL = '/internal/search'; - body: schema.object( - { - legacyHitsTotal: schema.maybe(schema.boolean()), - sessionId: schema.maybe(schema.string()), - isStored: schema.maybe(schema.boolean()), - isRestore: schema.maybe(schema.boolean()), +export function registerSearchRoute(router: DataPluginRouter): void { + router.versioned + .post({ + path: `${SEARCH_API_BASE_URL}/{strategy}/{id?}`, + access: 'internal', + }) + .addVersion( + { + version: '1', + validate: { + request: { + params: schema.object({ + strategy: schema.string(), + id: schema.maybe(schema.string()), + }), + body: schema.object( + { + legacyHitsTotal: schema.maybe(schema.boolean()), + sessionId: schema.maybe(schema.string()), + isStored: schema.maybe(schema.boolean()), + isRestore: schema.maybe(schema.boolean()), + }, + { unknowns: 'allow' } + ), }, - { unknowns: 'allow' } - ), + }, }, - }, - async (context, request, res) => { - const { - legacyHitsTotal = true, - sessionId, - isStored, - isRestore, - ...searchRequest - } = request.body; - const { strategy, id } = request.params; - const abortSignal = getRequestAbortedSignal(request.events.aborted$); + async (context, request, res) => { + const { + legacyHitsTotal = true, + sessionId, + isStored, + isRestore, + ...searchRequest + } = request.body; + const { strategy, id } = request.params; + const abortSignal = getRequestAbortedSignal(request.events.aborted$); - try { - const search = await context.search; - const response = await search - .search( - { ...searchRequest, id }, - { - abortSignal, - strategy, - legacyHitsTotal, - sessionId, - isStored, - isRestore, - } - ) - .pipe(first()) - .toPromise(); + try { + const search = await context.search; + const response = await search + .search( + { ...searchRequest, id }, + { + abortSignal, + strategy, + legacyHitsTotal, + sessionId, + isStored, + isRestore, + } + ) + .pipe(first()) + .toPromise(); - return res.ok({ body: response }); - } catch (err) { - return reportServerError(res, err); + return res.ok({ body: response }); + } catch (err) { + return reportServerError(res, err); + } } - } - ); + ); - router.delete( - { + router.versioned + .delete({ path: '/internal/search/{strategy}/{id}', - validate: { - params: schema.object({ - strategy: schema.string(), - id: schema.string(), - }), + access: 'internal', + }) + .addVersion( + { + version: '1', + validate: { + request: { + params: schema.object({ + strategy: schema.string(), + id: schema.string(), + }), + }, + }, }, - }, - async (context, request, res) => { - const { strategy, id } = request.params; + async (context, request, res) => { + const { strategy, id } = request.params; - try { - const search = await context.search; - await search.cancel(id, { strategy }); - return res.ok(); - } catch (err) { - return reportServerError(res, err); + try { + const search = await context.search; + await search.cancel(id, { strategy }); + return res.ok(); + } catch (err) { + return reportServerError(res, err); + } } - } - ); + ); } diff --git a/src/plugins/data_views/public/services/has_data.ts b/src/plugins/data_views/public/services/has_data.ts index 64a561620c82e..0586a08bc046c 100644 --- a/src/plugins/data_views/public/services/has_data.ts +++ b/src/plugins/data_views/public/services/has_data.ts @@ -82,6 +82,7 @@ export class HasData { }): Promise => http .post(`/internal/search/ese`, { + version: '1', body: JSON.stringify({ params: { ignore_unavailable: true, diff --git a/test/api_integration/apis/search/search.ts b/test/api_integration/apis/search/search.ts index 96e7f6ab7161b..1ddb074576e2d 100644 --- a/test/api_integration/apis/search/search.ts +++ b/test/api_integration/apis/search/search.ts @@ -6,6 +6,7 @@ * Side Public License, v 1. */ +import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import expect from '@kbn/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; import { painlessErrReq } from './painless_err_req'; @@ -28,6 +29,7 @@ export default function ({ getService }: FtrProviderContext) { it('should return 200 when correctly formatted searches are provided', async () => { const resp = await supertest .post(`/internal/search/es`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .send({ params: { body: { @@ -43,11 +45,13 @@ export default function ({ getService }: FtrProviderContext) { expect(resp.body.isPartial).to.be(false); expect(resp.body.isRunning).to.be(false); expect(resp.body).to.have.property('rawResponse'); + expect(resp.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1'); }); it('should return 200 if terminated early', async () => { const resp = await supertest .post(`/internal/search/es`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .send({ params: { terminateAfter: 1, @@ -66,11 +70,13 @@ export default function ({ getService }: FtrProviderContext) { expect(resp.body.isPartial).to.be(false); expect(resp.body.isRunning).to.be(false); expect(resp.body.rawResponse.terminated_early).to.be(true); + expect(resp.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1'); }); it('should return 404 when if no strategy is provided', async () => { const resp = await supertest .post(`/internal/search`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .send({ body: { query: { @@ -86,6 +92,7 @@ export default function ({ getService }: FtrProviderContext) { it('should return 404 when if unknown strategy is provided', async () => { const resp = await supertest .post(`/internal/search/banana`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .send({ body: { query: { @@ -97,11 +104,13 @@ export default function ({ getService }: FtrProviderContext) { verifyErrorResponse(resp.body, 404); expect(resp.body.message).to.contain('banana not found'); + expect(resp.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1'); }); it('should return 400 with illegal ES argument', async () => { const resp = await supertest .post(`/internal/search/es`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .send({ params: { timeout: 1, // This should be a time range string! @@ -122,6 +131,7 @@ export default function ({ getService }: FtrProviderContext) { it('should return 400 with a bad body', async () => { const resp = await supertest .post(`/internal/search/es`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .send({ params: { body: { @@ -136,7 +146,11 @@ export default function ({ getService }: FtrProviderContext) { }); it('should return 400 for a painless error', async () => { - const resp = await supertest.post(`/internal/search/es`).send(painlessErrReq).expect(400); + const resp = await supertest + .post(`/internal/search/es`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .send(painlessErrReq) + .expect(400); verifyErrorResponse(resp.body, 400, 'search_phase_execution_exception', true); }); @@ -144,14 +158,23 @@ export default function ({ getService }: FtrProviderContext) { describe('delete', () => { it('should return 404 when no search id provided', async () => { - const resp = await supertest.delete(`/internal/search/es`).send().expect(404); + const resp = await supertest + .delete(`/internal/search/es`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .send() + .expect(404); verifyErrorResponse(resp.body, 404); }); it('should return 400 when trying a delete on a non supporting strategy', async () => { - const resp = await supertest.delete(`/internal/search/es/123`).send().expect(400); + const resp = await supertest + .delete(`/internal/search/es/123`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .send() + .expect(400); verifyErrorResponse(resp.body, 400); expect(resp.body.message).to.contain("Search strategy es doesn't support cancellations"); + expect(resp.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1'); }); }); }); diff --git a/test/api_integration/apis/search/sql_search.ts b/test/api_integration/apis/search/sql_search.ts index c57d424e56fc7..93fd822775184 100644 --- a/test/api_integration/apis/search/sql_search.ts +++ b/test/api_integration/apis/search/sql_search.ts @@ -7,6 +7,7 @@ */ import expect from '@kbn/expect'; +import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { @@ -28,6 +29,7 @@ export default function ({ getService }: FtrProviderContext) { it('should return 200 when correctly formatted searches are provided', async () => { const resp = await supertest .post(`/internal/search/sql`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .send({ params: { query: sqlQuery, @@ -39,11 +41,13 @@ export default function ({ getService }: FtrProviderContext) { expect(resp.body).to.have.property('isPartial'); expect(resp.body).to.have.property('isRunning'); expect(resp.body).to.have.property('rawResponse'); + expect(resp.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1'); }); it('should fetch search results by id', async () => { const resp1 = await supertest .post(`/internal/search/sql`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .send({ params: { query: sqlQuery, @@ -53,13 +57,17 @@ export default function ({ getService }: FtrProviderContext) { .expect(200); const id = resp1.body.id; - const resp2 = await supertest.post(`/internal/search/sql/${id}`).send({}); + const resp2 = await supertest + .post(`/internal/search/sql/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .send({}); expect(resp2.status).to.be(200); expect(resp2.body.id).to.be(id); expect(resp2.body).to.have.property('isPartial'); expect(resp2.body).to.have.property('isRunning'); expect(resp2.body).to.have.property('rawResponse'); + expect(resp2.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1'); }); }); @@ -67,6 +75,7 @@ export default function ({ getService }: FtrProviderContext) { it('should delete search', async () => { const resp1 = await supertest .post(`/internal/search/sql`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .send({ params: { query: sqlQuery, @@ -77,13 +86,25 @@ export default function ({ getService }: FtrProviderContext) { const id = resp1.body.id; // confirm it was saved - await supertest.post(`/internal/search/sql/${id}`).send({}).expect(200); + await supertest + .post(`/internal/search/sql/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .send({}) + .expect(200); // delete it - await supertest.delete(`/internal/search/sql/${id}`).send().expect(200); + await supertest + .delete(`/internal/search/sql/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .send() + .expect(200); // check it was deleted - await supertest.post(`/internal/search/sql/${id}`).send({}).expect(404); + await supertest + .post(`/internal/search/sql/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .send({}) + .expect(404); }); }); }); diff --git a/test/common/services/bsearch.ts b/test/common/services/bsearch.ts index 2a0278840a7c8..f8efafe7e0ae4 100644 --- a/test/common/services/bsearch.ts +++ b/test/common/services/bsearch.ts @@ -10,6 +10,7 @@ import expect from '@kbn/expect'; import request from 'superagent'; import type SuperTest from 'supertest'; import { IEsSearchResponse } from '@kbn/data-plugin/common'; +import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { FtrService } from '../ftr_provider_context'; /** @@ -69,6 +70,7 @@ export class BsearchService extends FtrService { const { body } = await this.retry.try(async () => { return supertest .post(`${spaceUrl}/internal/search/${strategy}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .send(options) .expect(200); diff --git a/x-pack/test/api_integration/apis/search/search.ts b/x-pack/test/api_integration/apis/search/search.ts index f4f3c2e414003..0aed1ac636126 100644 --- a/x-pack/test/api_integration/apis/search/search.ts +++ b/x-pack/test/api_integration/apis/search/search.ts @@ -7,6 +7,7 @@ import expect from '@kbn/expect'; import { parse as parseCookie } from 'tough-cookie'; +import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { FtrProviderContext } from '../../ftr_provider_context'; import { verifyErrorResponse } from '../../../../../test/api_integration/apis/search/verify_error'; @@ -57,6 +58,7 @@ export default function ({ getService }: FtrProviderContext) { it('should return 200 with final response without search id if wait_for_completion_timeout is long enough', async function () { const resp = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ params: { @@ -82,6 +84,7 @@ export default function ({ getService }: FtrProviderContext) { const resp = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ params: { @@ -108,6 +111,7 @@ export default function ({ getService }: FtrProviderContext) { const resp = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ params: { @@ -132,6 +136,7 @@ export default function ({ getService }: FtrProviderContext) { await retry.tryForTime(10000, async () => { const resp2 = await supertest .post(`/internal/search/ese/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({}) .expect(200); @@ -149,6 +154,7 @@ export default function ({ getService }: FtrProviderContext) { const resp = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ params: { @@ -170,6 +176,7 @@ export default function ({ getService }: FtrProviderContext) { const resp2 = await supertest .post(`/internal/search/ese/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({}) .expect(200); @@ -182,6 +189,7 @@ export default function ({ getService }: FtrProviderContext) { it('should fail without kbn-xref header', async () => { const resp = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .send({ params: { body: { @@ -199,6 +207,7 @@ export default function ({ getService }: FtrProviderContext) { it('should return 400 when unknown index type is provided', async () => { const resp = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ indexType: 'baad', @@ -218,6 +227,7 @@ export default function ({ getService }: FtrProviderContext) { it('should return 400 if invalid id is provided', async () => { const resp = await supertest .post(`/internal/search/ese/123`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ params: { @@ -238,6 +248,7 @@ export default function ({ getService }: FtrProviderContext) { .post( `/internal/search/ese/FkxOb21iV1g2VGR1S2QzaWVtRU9fMVEbc3JWeWc1VHlUdDZ6MENxcXlYVG1Fdzo2NDg4` ) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ params: { @@ -255,6 +266,7 @@ export default function ({ getService }: FtrProviderContext) { it('should return 400 with a bad body', async () => { const resp = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ params: { @@ -293,6 +305,7 @@ export default function ({ getService }: FtrProviderContext) { await supertestNoAuth .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .set('Cookie', sessionCookie!.cookieString()) .send({ @@ -323,6 +336,7 @@ export default function ({ getService }: FtrProviderContext) { it('should return 400 if rollup search is called without index', async () => { const resp = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ indexType: 'rollup', @@ -341,6 +355,7 @@ export default function ({ getService }: FtrProviderContext) { it('should return 400 if rollup search is without non-existent index', async () => { const resp = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ indexType: 'rollup', @@ -361,6 +376,7 @@ export default function ({ getService }: FtrProviderContext) { it('should rollup search', async () => { await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ indexType: 'rollup', @@ -380,12 +396,18 @@ export default function ({ getService }: FtrProviderContext) { describe('delete', () => { it('should return 404 when no search id provided', async () => { - await supertest.delete(`/internal/search/ese`).set('kbn-xsrf', 'foo').send().expect(404); + await supertest + .delete(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') + .set('kbn-xsrf', 'foo') + .send() + .expect(404); }); it('should return 400 when trying a delete a bad id', async () => { const resp = await supertest .delete(`/internal/search/ese/123`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send() .expect(400); @@ -397,6 +419,7 @@ export default function ({ getService }: FtrProviderContext) { const resp = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ params: { @@ -418,6 +441,7 @@ export default function ({ getService }: FtrProviderContext) { await supertest .delete(`/internal/search/ese/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send() .expect(200); @@ -425,6 +449,7 @@ export default function ({ getService }: FtrProviderContext) { // try to re-fetch await supertest .post(`/internal/search/ese/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({}) .expect(404); @@ -435,6 +460,7 @@ export default function ({ getService }: FtrProviderContext) { const resp = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ params: { @@ -459,6 +485,7 @@ export default function ({ getService }: FtrProviderContext) { await retry.tryForTime(10000, async () => { const resp2 = await supertest .post(`/internal/search/ese/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({}) .expect(200); @@ -472,6 +499,7 @@ export default function ({ getService }: FtrProviderContext) { await supertest .delete(`/internal/search/ese/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send() .expect(200); @@ -479,6 +507,7 @@ export default function ({ getService }: FtrProviderContext) { // try to re-fetch await supertest .post(`/internal/search/ese/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({}) .expect(404); diff --git a/x-pack/test/api_integration/apis/search/session.ts b/x-pack/test/api_integration/apis/search/session.ts index 88f5bd92fd165..6021968c53ab3 100644 --- a/x-pack/test/api_integration/apis/search/session.ts +++ b/x-pack/test/api_integration/apis/search/session.ts @@ -7,6 +7,7 @@ import expect from '@kbn/expect'; import { SearchSessionStatus } from '@kbn/data-plugin/common'; +import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { @@ -138,6 +139,7 @@ export default function ({ getService }: FtrProviderContext) { // run search, this will not be persisted because session is not saved yet const searchRes1 = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ sessionId, @@ -172,6 +174,7 @@ export default function ({ getService }: FtrProviderContext) { // run search const searchRes2 = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ sessionId, @@ -256,6 +259,7 @@ export default function ({ getService }: FtrProviderContext) { // run search const searchRes = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ sessionId, @@ -281,6 +285,7 @@ export default function ({ getService }: FtrProviderContext) { // run search to persist into a session await supertest .post(`/internal/search/ese/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ sessionId, @@ -517,6 +522,7 @@ export default function ({ getService }: FtrProviderContext) { // run search const searchRes = await supertest .post(`/s/${spaceId}/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ sessionId, @@ -542,6 +548,7 @@ export default function ({ getService }: FtrProviderContext) { // run search to persist into a session await supertest .post(`/s/${spaceId}/internal/search/ese/${id}`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'foo') .send({ sessionId, diff --git a/x-pack/test/api_integration/apis/security_solution/sources.ts b/x-pack/test/api_integration/apis/security_solution/sources.ts index 7f5c46610d607..e0d76301f700a 100644 --- a/x-pack/test/api_integration/apis/security_solution/sources.ts +++ b/x-pack/test/api_integration/apis/security_solution/sources.ts @@ -7,6 +7,7 @@ import expect from '@kbn/expect'; +import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { @@ -20,6 +21,7 @@ export default function ({ getService }: FtrProviderContext) { it('Make sure that we get source information when auditbeat indices is there', async () => { const { body: sourceStatus } = await supertest .post('/internal/search/indexFields/') + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .send({ indices: ['auditbeat-*'], @@ -35,6 +37,7 @@ export default function ({ getService }: FtrProviderContext) { it('should find indexes as being available when they exist', async () => { const { body: sourceStatus } = await supertest .post('/internal/search/indexFields/') + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .send({ indices: ['auditbeat-*', 'filebeat-*'], @@ -49,6 +52,7 @@ export default function ({ getService }: FtrProviderContext) { it('should not find indexes as existing when there is an empty array of them', async () => { const { body: sourceStatus } = await supertest .post('/internal/search/indexFields/') + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .send({ indices: [], @@ -63,6 +67,7 @@ export default function ({ getService }: FtrProviderContext) { it('should not find indexes as existing when there is a _all within it', async () => { const { body: sourceStatus } = await supertest .post('/internal/search/indexFields/') + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .send({ indices: ['_all'], @@ -77,6 +82,7 @@ export default function ({ getService }: FtrProviderContext) { it('should not find indexes as existing when there are empty strings within it', async () => { const { body: sourceStatus } = await supertest .post('/internal/search/indexFields/') + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .send({ indices: [''], @@ -91,6 +97,7 @@ export default function ({ getService }: FtrProviderContext) { it('should not find indexes as existing when there are blank spaces within it', async () => { const { body: sourceStatus } = await supertest .post('/internal/search/indexFields/') + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .send({ indices: [' '], @@ -105,6 +112,7 @@ export default function ({ getService }: FtrProviderContext) { it('should find indexes when one is an empty index but the others are valid', async () => { const { body: sourceStatus } = await supertest .post('/internal/search/indexFields/') + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .send({ indices: ['', 'auditbeat-*'], diff --git a/x-pack/test/api_integration/apis/uptime/rest/certs.ts b/x-pack/test/api_integration/apis/uptime/rest/certs.ts index f52ed57a3d39a..746d3c8047dd0 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/certs.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/certs.ts @@ -13,6 +13,7 @@ import { processCertsResult, getCertsRequestBody, } from '@kbn/synthetics-plugin/common/requests/get_certs_request_body'; +import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { FtrProviderContext } from '../../../ftr_provider_context'; import { makeChecksWithStatus } from './helper/make_checks'; @@ -26,6 +27,7 @@ export default function ({ getService }: FtrProviderContext) { it('returns empty array for no data', async () => { const apiResponse = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .send({ params: { @@ -82,6 +84,7 @@ export default function ({ getService }: FtrProviderContext) { it('retrieves expected cert data', async () => { const { body } = await supertest .post(`/internal/search/ese`) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .send({ params: { diff --git a/x-pack/test/common/services/bsearch_secure.ts b/x-pack/test/common/services/bsearch_secure.ts index b7bff074afc07..21904d1bcff99 100644 --- a/x-pack/test/common/services/bsearch_secure.ts +++ b/x-pack/test/common/services/bsearch_secure.ts @@ -12,6 +12,7 @@ import expect from '@kbn/expect'; import request from 'superagent'; import type SuperTest from 'supertest'; import { IEsSearchResponse } from '@kbn/data-plugin/common'; +import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { FtrService } from '../ftr_provider_context'; const parseBfetchResponse = (resp: request.Response): Array> => { @@ -58,6 +59,7 @@ export class BsearchSecureService extends FtrService { result = await supertestWithoutAuth .post(url) .auth(auth.username, auth.password) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('referer', referer) .set('kbn-version', kibanaVersion) .set('kbn-xsrf', 'true') @@ -66,6 +68,7 @@ export class BsearchSecureService extends FtrService { result = await supertestWithoutAuth .post(url) .auth(auth.username, auth.password) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('referer', referer) .set('kbn-xsrf', 'true') .send(options); @@ -73,6 +76,7 @@ export class BsearchSecureService extends FtrService { result = await supertestWithoutAuth .post(url) .auth(auth.username, auth.password) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-version', kibanaVersion) .set('kbn-xsrf', 'true') .send(options); @@ -80,6 +84,7 @@ export class BsearchSecureService extends FtrService { result = await supertestWithoutAuth .post(url) .auth(auth.username, auth.password) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('x-elastic-internal-origin', internalOrigin) .set('kbn-xsrf', 'true') .send(options); @@ -87,6 +92,7 @@ export class BsearchSecureService extends FtrService { result = await supertestWithoutAuth .post(url) .auth(auth.username, auth.password) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .send(options); } diff --git a/x-pack/test/timeline/security_and_spaces/tests/basic/events.ts b/x-pack/test/timeline/security_and_spaces/tests/basic/events.ts index 5ab0bb94d1383..8fd411b9b41e8 100644 --- a/x-pack/test/timeline/security_and_spaces/tests/basic/events.ts +++ b/x-pack/test/timeline/security_and_spaces/tests/basic/events.ts @@ -14,6 +14,7 @@ import { Direction, TimelineEventsQueries, } from '@kbn/security-solution-plugin/common/search_strategy'; +import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { User } from '../../../../rule_registry/common/lib/authentication/types'; import { getSpaceUrlPrefix } from '../../../../rule_registry/common/lib/authentication/spaces'; @@ -126,6 +127,7 @@ export default ({ getService }: FtrProviderContext) => { const resp = await supertestWithoutAuth .post(`${getSpaceUrlPrefix(space)}${TEST_URL}`) .auth(username, password) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .set('Content-Type', 'application/json') .send({ ...body }) @@ -157,6 +159,7 @@ export default ({ getService }: FtrProviderContext) => { const resp = await supertestWithoutAuth .post(`${getSpaceUrlPrefix(space)}${TEST_URL}`) .auth(username, password) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .set('Content-Type', 'application/json') .send({ ...body }) @@ -178,6 +181,7 @@ export default ({ getService }: FtrProviderContext) => { await supertestWithoutAuth .post(`${getSpaceUrlPrefix(space)}${TEST_URL}`) .auth(username, password) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .set('Content-Type', 'application/json') .send({ ...body }) diff --git a/x-pack/test/timeline/security_and_spaces/tests/trial/events.ts b/x-pack/test/timeline/security_and_spaces/tests/trial/events.ts index 89a5f6d7df442..d08a89e4504c3 100644 --- a/x-pack/test/timeline/security_and_spaces/tests/trial/events.ts +++ b/x-pack/test/timeline/security_and_spaces/tests/trial/events.ts @@ -16,6 +16,7 @@ import { Direction, TimelineEventsQueries, } from '@kbn/security-solution-plugin/common/search_strategy'; +import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import { User } from '../../../../rule_registry/common/lib/authentication/types'; import { getSpaceUrlPrefix } from '../../../../rule_registry/common/lib/authentication/spaces'; @@ -138,6 +139,7 @@ export default ({ getService }: FtrProviderContext) => { const resp = await supertestWithoutAuth .post(`${getSpaceUrlPrefix(space)}${TEST_URL}`) .auth(username, password) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .set('Content-Type', 'application/json') .send({ ...body }) @@ -168,6 +170,7 @@ export default ({ getService }: FtrProviderContext) => { await supertestWithoutAuth .post(`${getSpaceUrlPrefix(space)}${TEST_URL}`) .auth(username, password) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .set('Content-Type', 'application/json') .send({ ...body }) @@ -209,6 +212,7 @@ export default ({ getService }: FtrProviderContext) => { await supertestWithoutAuth .post(`${getSpaceUrlPrefix(SPACE_1)}${TEST_URL}`) .auth(superUser.username, superUser.password) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .set('Content-Type', 'application/json') .send({ @@ -241,6 +245,7 @@ export default ({ getService }: FtrProviderContext) => { await supertestWithoutAuth .post(`${getSpaceUrlPrefix(SPACE_2)}${TEST_URL}`) .auth(obsMinRead.username, obsMinRead.password) + .set(ELASTIC_HTTP_VERSION_HEADER, '1') .set('kbn-xsrf', 'true') .set('Content-Type', 'application/json') .send({