mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[data.search] Use versioned router (#158520)
## Summary Step 1 of https://github.com/elastic/kibana/issues/157095. Uses the new versioned router capabilities for the search routes (`POST` and `DELETE`). ### 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 ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Matthias Wilhelm <matthias.wilhelm@elastic.co>
This commit is contained in:
parent
b8b4f75145
commit
34ada8a9a6
14 changed files with 235 additions and 78 deletions
|
@ -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({
|
||||
|
|
|
@ -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 });
|
||||
});
|
||||
});
|
||||
|
|
|
@ -12,82 +12,97 @@ import { reportServerError } from '@kbn/kibana-utils-plugin/server';
|
|||
import { getRequestAbortedSignal } from '../../lib';
|
||||
import type { DataPluginRouter } from '../types';
|
||||
|
||||
export const SEARCH_API_BASE_URL = '/internal/search';
|
||||
|
||||
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()),
|
||||
}),
|
||||
|
||||
body: schema.object(
|
||||
{
|
||||
legacyHitsTotal: schema.maybe(schema.boolean()),
|
||||
sessionId: schema.maybe(schema.string()),
|
||||
isStored: schema.maybe(schema.boolean()),
|
||||
isRestore: schema.maybe(schema.boolean()),
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ export class HasData {
|
|||
}): Promise<boolean> =>
|
||||
http
|
||||
.post<IndicesViaSearchResponse>(`/internal/search/ese`, {
|
||||
version: '1',
|
||||
body: JSON.stringify({
|
||||
params: {
|
||||
ignore_unavailable: true,
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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-*'],
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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<Record<string, any>> => {
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 })
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue