Skip to content

Commit

Permalink
Ignore security disabled HTTP response header (elastic#115945)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant authored Oct 26, 2021
1 parent c727af4 commit 77988c8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
33 changes: 25 additions & 8 deletions src/plugins/data/public/search/fetch/handle_response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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<any>;
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<any>;
const result = handleResponse(request, response);
expect(result).toBe(response);
expect(notifications.toasts.addWarning).not.toBeCalled();
});
});
9 changes: 8 additions & 1 deletion src/plugins/data/public/search/fetch/handle_response.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
Expand Down Expand Up @@ -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;
}

0 comments on commit 77988c8

Please sign in to comment.