From ed7ea12fbc976cc377cc171084e4783fbb1582f4 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Fri, 31 Aug 2018 13:43:55 -0700 Subject: [PATCH 1/5] Rename containsInvalidCharacters to containsIllegalCharacters and return a value which accurately reflects the name. --- .../step_index_pattern/step_index_pattern.js | 4 ++-- .../contains_invalid_characters.test.js | 16 ++++++++-------- ...racters.js => contains_illegal_characters.js} | 4 ++-- .../create_index_pattern_wizard/lib/index.js | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) rename src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/{contains_invalid_characters.js => contains_illegal_characters.js} (86%) diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js index bf6468c3bf15b..f94a3ebf2ebb4 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js @@ -22,7 +22,7 @@ import PropTypes from 'prop-types'; import { ILLEGAL_CHARACTERS, MAX_SEARCH_SIZE } from '../../constants'; import { getIndices, - containsInvalidCharacters, + containsIllegalCharacters, getMatchedIndices, canAppendWildcard, ensureMinimumTime @@ -240,7 +240,7 @@ export class StepIndexPatternComponent extends Component { // This is an error scenario but do not report an error containsErrors = true; } - else if (!containsInvalidCharacters(query, ILLEGAL_CHARACTERS)) { + else if (containsIllegalCharacters(query, ILLEGAL_CHARACTERS)) { const errorMessage = intl.formatMessage( { id: 'kbn.management.createIndexPattern.step.invalidCharactersErrorMessage', diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/__tests__/contains_invalid_characters.test.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/__tests__/contains_invalid_characters.test.js index 2385f3baec6bc..05c4aba2571bd 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/__tests__/contains_invalid_characters.test.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/__tests__/contains_invalid_characters.test.js @@ -17,16 +17,16 @@ * under the License. */ -import { containsInvalidCharacters } from '../contains_invalid_characters'; +import { containsIllegalCharacters } from '../contains_illegal_characters'; -describe('containsInvalidCharacters', () => { - it('should fail with illegal characters', () => { - const valid = containsInvalidCharacters('abc', ['a']); - expect(valid).toBeFalsy(); +describe('containsIllegalCharacters', () => { + it('returns true with illegal characters', () => { + const isInvalid = containsIllegalCharacters('abc', ['a']); + expect(isInvalid).toBe(true); }); - it('should pass with no illegal characters', () => { - const valid = containsInvalidCharacters('abc', ['%']); - expect(valid).toBeTruthy(); + it('returns false with no illegal characters', () => { + const isInvalid = containsIllegalCharacters('abc', ['%']); + expect(isInvalid).toBe(false); }); }); diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/contains_invalid_characters.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/contains_illegal_characters.js similarity index 86% rename from src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/contains_invalid_characters.js rename to src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/contains_illegal_characters.js index 5dbe3d7111061..31485bb3daaa2 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/contains_invalid_characters.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/contains_illegal_characters.js @@ -17,6 +17,6 @@ * under the License. */ -export function containsInvalidCharacters(pattern, illegalCharacters) { - return !illegalCharacters.some(char => pattern.includes(char)); +export function containsIllegalCharacters(pattern, illegalCharacters) { + return illegalCharacters.some(char => pattern.includes(char)); } diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/index.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/index.js index 22efa498c84ab..0930eb82514e1 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/index.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/index.js @@ -25,6 +25,6 @@ export { getIndices } from './get_indices'; export { getMatchedIndices } from './get_matched_indices'; -export { containsInvalidCharacters } from './contains_invalid_characters'; +export { containsIllegalCharacters } from './contains_illegal_characters'; export { extractTimeFields } from './extract_time_fields'; From daa88c80f18f2ab4cea6c1e1742a0746b99edb5b Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Fri, 31 Aug 2018 13:54:50 -0700 Subject: [PATCH 2/5] Move illegal index pattern characters from Management into ui/public/index_patterns. --- .../step_index_pattern/step_index_pattern.js | 2 +- .../constants/index.js | 3 ++- .../public/index_patterns/constants/index.js | 21 +++++++++++++++++++ src/ui/public/index_patterns/index.js | 6 ++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/ui/public/index_patterns/constants/index.js diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js index f94a3ebf2ebb4..494fa397ce898 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js @@ -19,7 +19,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import { ILLEGAL_CHARACTERS, MAX_SEARCH_SIZE } from '../../constants'; +import { INDEX_PATTERN_ILLEGAL_CHARACTERS as ILLEGAL_CHARACTERS, MAX_SEARCH_SIZE } from '../../constants'; import { getIndices, containsIllegalCharacters, diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/constants/index.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/constants/index.js index 79bdbaed0d732..1b97cd9e6e992 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/constants/index.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/constants/index.js @@ -17,6 +17,8 @@ * under the License. */ +export { INDEX_PATTERN_ILLEGAL_CHARACTERS } from 'ui/index_patterns'; + // This isn't ideal. We want to avoid searching for 20 indices // then filtering out the majority of them because they are system indices. // We'd like to filter system indices out in the query @@ -26,4 +28,3 @@ export const MAX_NUMBER_OF_MATCHING_INDICES = 100; export const MAX_SEARCH_SIZE = MAX_NUMBER_OF_MATCHING_INDICES + ESTIMATED_NUMBER_OF_SYSTEM_INDICES; export const PER_PAGE_INCREMENTS = [5, 10, 20, 50]; -export const ILLEGAL_CHARACTERS = ['\\', '/', '?', '"', '<', '>', '|', ' ']; diff --git a/src/ui/public/index_patterns/constants/index.js b/src/ui/public/index_patterns/constants/index.js new file mode 100644 index 0000000000000..b22c1682173ca --- /dev/null +++ b/src/ui/public/index_patterns/constants/index.js @@ -0,0 +1,21 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export const INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE = ['\\', '/', '?', '"', '<', '>', '|']; +export const INDEX_PATTERN_ILLEGAL_CHARACTERS = INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE.concat(' '); diff --git a/src/ui/public/index_patterns/index.js b/src/ui/public/index_patterns/index.js index 025c0248b0848..5df0b7bb8a614 100644 --- a/src/ui/public/index_patterns/index.js +++ b/src/ui/public/index_patterns/index.js @@ -18,6 +18,12 @@ */ export { IndexPatternsProvider } from './index_patterns'; + export { IndexPatternsApiClientProvider, } from './index_patterns_api_client_provider'; + +export { + INDEX_PATTERN_ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, +} from './constants'; From 79452c64f1e46e727516d8dc56558a8b2a375f9e Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Fri, 31 Aug 2018 15:19:25 -0700 Subject: [PATCH 3/5] Address nit. --- .../components/step_index_pattern/step_index_pattern.js | 3 ++- .../indices/create_index_pattern_wizard/constants/index.js | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js index 494fa397ce898..133154de52619 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js @@ -19,7 +19,8 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import { INDEX_PATTERN_ILLEGAL_CHARACTERS as ILLEGAL_CHARACTERS, MAX_SEARCH_SIZE } from '../../constants'; +import { INDEX_PATTERN_ILLEGAL_CHARACTERS as ILLEGAL_CHARACTERS } from 'ui/index_patterns'; +import { MAX_SEARCH_SIZE } from '../../constants'; import { getIndices, containsIllegalCharacters, diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/constants/index.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/constants/index.js index 1b97cd9e6e992..86246903b4440 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/constants/index.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/constants/index.js @@ -17,8 +17,6 @@ * under the License. */ -export { INDEX_PATTERN_ILLEGAL_CHARACTERS } from 'ui/index_patterns'; - // This isn't ideal. We want to avoid searching for 20 indices // then filtering out the majority of them because they are system indices. // We'd like to filter system indices out in the query From ba4adea4de450614cd9ff68c7e494c33b34cb748 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Sat, 1 Sep 2018 19:03:00 -0700 Subject: [PATCH 4/5] Fix broken Jest tests. --- .../create_index_pattern_wizard/__tests__/render.test.js | 4 ++++ .../step_index_pattern/__tests__/step_index_pattern.test.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/__tests__/render.test.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/__tests__/render.test.js index 16da9009f5d5f..b2354f44dab30 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/__tests__/render.test.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/__tests__/render.test.js @@ -22,6 +22,10 @@ const unmountComponentAtNode = jest.fn(); jest.doMock('react-dom', () => ({ render, unmountComponentAtNode })); +jest.mock('ui/index_patterns', () => ({ + INDEX_PATTERN_ILLEGAL_CHARACTERS: ['\\', '/', '?', '"', '<', '>', '|', ' '], +})); + jest.mock('ui/chrome', () => ({ getUiSettingsClient: () => ({ get: () => '', diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/step_index_pattern.test.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/step_index_pattern.test.js index 3b05ec4b71ec4..7dc1f5e0f17d7 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/step_index_pattern.test.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/step_index_pattern.test.js @@ -26,6 +26,10 @@ jest.mock('../../../lib/ensure_minimum_time', () => ({ ensureMinimumTime: async (promises) => Array.isArray(promises) ? await Promise.all(promises) : await promises })); +jest.mock('ui/index_patterns', () => ({ + INDEX_PATTERN_ILLEGAL_CHARACTERS: ['\\', '/', '?', '"', '<', '>', '|', ' '], +})); + jest.mock('ui/chrome', () => ({ getUiSettingsClient: () => ({ get: () => '', From 0177d55af91576bde52021f541c9642510dd7287 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Tue, 4 Sep 2018 09:44:11 -0700 Subject: [PATCH 5/5] Add comments. --- .../create_index_pattern_wizard/__tests__/render.test.js | 2 ++ .../step_index_pattern/__tests__/step_index_pattern.test.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/__tests__/render.test.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/__tests__/render.test.js index b2354f44dab30..9ef4a3e38ee9b 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/__tests__/render.test.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/__tests__/render.test.js @@ -22,6 +22,8 @@ const unmountComponentAtNode = jest.fn(); jest.doMock('react-dom', () => ({ render, unmountComponentAtNode })); +// If we don't mock this, Jest fails with the error `TypeError: Cannot redefine property: prototype +// at Function.defineProperties`. jest.mock('ui/index_patterns', () => ({ INDEX_PATTERN_ILLEGAL_CHARACTERS: ['\\', '/', '?', '"', '<', '>', '|', ' '], })); diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/step_index_pattern.test.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/step_index_pattern.test.js index 7dc1f5e0f17d7..37df9762b54df 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/step_index_pattern.test.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/step_index_pattern.test.js @@ -26,6 +26,8 @@ jest.mock('../../../lib/ensure_minimum_time', () => ({ ensureMinimumTime: async (promises) => Array.isArray(promises) ? await Promise.all(promises) : await promises })); +// If we don't mock this, Jest fails with the error `TypeError: Cannot redefine property: prototype +// at Function.defineProperties`. jest.mock('ui/index_patterns', () => ({ INDEX_PATTERN_ILLEGAL_CHARACTERS: ['\\', '/', '?', '"', '<', '>', '|', ' '], }));