diff --git a/src/plugins/data/public/search/fetch/handle_response.test.ts b/src/plugins/data/public/search/fetch/handle_response.test.ts index 1a430f860f438..aca3d3e35073c 100644 --- a/src/plugins/data/public/search/fetch/handle_response.test.ts +++ b/src/plugins/data/public/search/fetch/handle_response.test.ts @@ -14,14 +14,6 @@ import { notificationServiceMock } from '../../../../../core/public/notification import { setNotifications } from '../../services'; import { IKibanaSearchResponse } from 'src/plugins/data/common'; -jest.mock('@kbn/i18n', () => { - return { - i18n: { - translate: (id: string, { defaultMessage }: { defaultMessage: string }) => defaultMessage, - }, - }; -}); - describe('handleResponse', () => { const notifications = notificationServiceMock.createStartContract(); @@ -73,4 +65,29 @@ describe('handleResponse', () => { const result = handleResponse(request, response); expect(result).toBe(response); }); + + test('should notify if has warning', () => { + const request = { body: {} }; + const response = { + rawResponse: {}, + warning: 'a warning', + } as IKibanaSearchResponse; + const result = handleResponse(request, response); + expect(result).toBe(response); + expect(notifications.toasts.addWarning).toBeCalledWith( + expect.objectContaining({ title: expect.stringContaining(response.warning!) }) + ); + }); + + test("shouldn't notify on warning about disabled security", () => { + const request = { body: {} }; + const response = { + rawResponse: {}, + warning: + '299 Elasticsearch-7.16.0-SNAPSHOT-3e6393bc4ec8f0000b1bcd4371b2e607eb02a1d7 "Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.16/security-minimal-setup.html to enable security."', + } as IKibanaSearchResponse; + const result = handleResponse(request, response); + expect(result).toBe(response); + expect(notifications.toasts.addWarning).not.toBeCalled(); + }); }); diff --git a/src/plugins/data/public/search/fetch/handle_response.tsx b/src/plugins/data/public/search/fetch/handle_response.tsx index f4acebfb36060..c82479bcbfea9 100644 --- a/src/plugins/data/public/search/fetch/handle_response.tsx +++ b/src/plugins/data/public/search/fetch/handle_response.tsx @@ -17,7 +17,7 @@ import { SearchRequest } from '..'; export function handleResponse(request: SearchRequest, response: IKibanaSearchResponse) { const { rawResponse, warning } = response; - if (warning) { + if (warning && !shouldIgnoreWarning(warning)) { getNotifications().toasts.addWarning({ title: i18n.translate('data.search.searchSource.fetch.warningMessage', { defaultMessage: 'Warning: {warning}', @@ -64,3 +64,10 @@ export function handleResponse(request: SearchRequest, response: IKibanaSearchRe return response; } + +function shouldIgnoreWarning(warning: string): boolean { + // https://github.com/elastic/kibana/issues/115632 + if (warning.includes('Elasticsearch built-in security features are not enabled')) return true; + + return false; +}