Skip to content

Commit f4726da

Browse files
Merge branch 'master' into ilm_fix_test
2 parents 21b982e + 06fbfd9 commit f4726da

114 files changed

Lines changed: 1175 additions & 5169 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/plugins/console/server/lib/spec_definitions/json/overrides/ilm.put_lifecycle.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"forcemerge": {
3232
"max_num_segments": 1
3333
}
34-
}
34+
}
3535
},
3636
"min_age": "1d",
3737
"actions": {
@@ -69,7 +69,6 @@
6969
"set_priority": {
7070
"priority": 0
7171
},
72-
"freeze": {},
7372
"allocate": {
7473
"number_of_replicas": 1,
7574
"include": {
@@ -85,14 +84,13 @@
8584
"_ip": ""
8685
}
8786
}
88-
}
87+
}
8988
},
9089
"min_age": "1d",
9190
"actions": {
9291
"set_priority": {
9392
"priority": 0
9493
},
95-
"freeze": {},
9694
"unfollow": {},
9795
"allocate": {
9896
"number_of_replicas": 1,
@@ -123,7 +121,7 @@
123121
"max_docs": 1000,
124122
"max_size": "5gb"
125123
}
126-
}
124+
}
127125
},
128126
"min_age": "1d",
129127
"actions": {
@@ -154,4 +152,4 @@
154152
}
155153
}
156154
}
157-
}
155+
}

src/plugins/data/public/ui/filter_bar/filter_bar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ function FilterBarUI(props: Props) {
5555
}
5656
}
5757

58+
const onAddFilterClick = () => setIsAddFilterPopoverOpen(!isAddFilterPopoverOpen);
59+
5860
function renderItems() {
5961
return props.filters.map((filter, i) => (
6062
<EuiFlexItem key={i} grow={false} className="globalFilterBar__flexItem">
@@ -81,7 +83,7 @@ function FilterBarUI(props: Props) {
8183
const button = (
8284
<EuiButtonEmpty
8385
size="s"
84-
onClick={() => setIsAddFilterPopoverOpen(true)}
86+
onClick={onAddFilterClick}
8587
data-test-subj="addFilter"
8688
className="globalFilterBar__addButton"
8789
>

src/plugins/data_views/common/data_views/data_view.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { map, last } from 'lodash';
1010

1111
import { IndexPattern } from './data_view';
1212

13-
import { DuplicateField } from '../../../kibana_utils/common';
13+
import { CharacterNotAllowedInField, DuplicateField } from '../../../kibana_utils/common';
1414

1515
import { IndexPatternField } from '../fields';
1616

@@ -207,6 +207,14 @@ describe('IndexPattern', () => {
207207
expect(e).toBeInstanceOf(DuplicateField);
208208
}
209209
});
210+
211+
test('should not allow scripted field with * in name', async () => {
212+
try {
213+
await indexPattern.addScriptedField('test*123', "'new script'", 'string');
214+
} catch (e) {
215+
expect(e).toBeInstanceOf(CharacterNotAllowedInField);
216+
}
217+
});
210218
});
211219

212220
describe('setFieldFormat and deleteFieldFormaat', () => {
@@ -267,6 +275,14 @@ describe('IndexPattern', () => {
267275
});
268276
expect(indexPattern.toSpec()!.fields!.new_field).toBeUndefined();
269277
});
278+
279+
test('should not allow runtime field with * in name', async () => {
280+
try {
281+
await indexPattern.addRuntimeField('test*123', runtime);
282+
} catch (e) {
283+
expect(e).toBeInstanceOf(CharacterNotAllowedInField);
284+
}
285+
});
270286
});
271287

272288
describe('getFormatterForField', () => {

src/plugins/data_views/common/data_views/data_view.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { castEsToKbnFieldTypeName, ES_FIELD_TYPES, KBN_FIELD_TYPES } from '@kbn/
1313
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
1414
import { FieldAttrs, FieldAttrSet, DataViewAttributes } from '..';
1515
import type { RuntimeField } from '../types';
16-
import { DuplicateField } from '../../../kibana_utils/common';
16+
import { CharacterNotAllowedInField, DuplicateField } from '../../../kibana_utils/common';
1717

1818
import { IIndexPattern, IFieldType } from '../../common';
1919
import { DataViewField, IIndexPatternFieldList, fieldList } from '../fields';
@@ -237,6 +237,10 @@ export class DataView implements IIndexPattern {
237237
const scriptedFields = this.getScriptedFields();
238238
const names = _.map(scriptedFields, 'name');
239239

240+
if (name.includes('*')) {
241+
throw new CharacterNotAllowedInField('*', name);
242+
}
243+
240244
if (_.includes(names, name)) {
241245
throw new DuplicateField(name);
242246
}
@@ -358,6 +362,11 @@ export class DataView implements IIndexPattern {
358362
*/
359363
addRuntimeField(name: string, runtimeField: RuntimeField) {
360364
const existingField = this.getFieldByName(name);
365+
366+
if (name.includes('*')) {
367+
throw new CharacterNotAllowedInField('*', name);
368+
}
369+
361370
if (existingField) {
362371
existingField.runtimeField = runtimeField;
363372
} else {

src/plugins/index_pattern_field_editor/public/components/field_editor/form_schema.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { fieldValidators } from '../../shared_imports';
1111

1212
import { RUNTIME_FIELD_OPTIONS } from './constants';
1313

14-
const { emptyField, numberGreaterThanField } = fieldValidators;
14+
const { containsCharsField, emptyField, numberGreaterThanField } = fieldValidators;
1515

1616
export const schema = {
1717
name: {
@@ -29,6 +29,17 @@ export const schema = {
2929
)
3030
),
3131
},
32+
{
33+
validator: containsCharsField({
34+
message: i18n.translate(
35+
'indexPatternFieldEditor.editor.form.validations.starCharacterNotAllowedValidationErrorMessage',
36+
{
37+
defaultMessage: 'The field cannot have * in the name.',
38+
}
39+
),
40+
chars: '*',
41+
}),
42+
},
3243
],
3344
},
3445
type: {

src/plugins/index_pattern_management/public/components/field_editor/__snapshots__/field_editor.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,25 @@ describe('FieldEditor', () => {
292292
component.update();
293293
expect(component).toMatchSnapshot();
294294
});
295+
296+
it('should not allow field to have * in the name', async () => {
297+
const testField = {
298+
...field,
299+
name: 'test-field',
300+
};
301+
const component = createComponentWithContext<FieldEdiorProps>(
302+
FieldEditor,
303+
{
304+
indexPattern,
305+
spec: testField as unknown as IndexPatternField,
306+
services,
307+
},
308+
mockContext
309+
);
310+
311+
await new Promise((resolve) => process.nextTick(resolve));
312+
(component.instance() as FieldEditor).onFieldChange('name', 'test*123');
313+
component.update();
314+
expect(component.html().includes('The field cannot have * in the name.')).toBe(true);
315+
});
295316
});

src/plugins/index_pattern_management/public/components/field_editor/field_editor.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ export class FieldEditor extends PureComponent<FieldEdiorProps, FieldEditorState
267267

268268
renderName() {
269269
const { isCreating, spec } = this.state;
270-
const isInvalid = !spec.name || !spec.name.trim();
270+
const starCheck = spec?.name?.includes('*');
271+
const isInvalid = !spec.name || !spec.name.trim() || starCheck;
271272

272273
return isCreating ? (
273274
<EuiFormRow
@@ -298,11 +299,17 @@ export class FieldEditor extends PureComponent<FieldEdiorProps, FieldEditorState
298299
}
299300
isInvalid={isInvalid}
300301
error={
301-
isInvalid
302-
? i18n.translate('indexPatternManagement.nameErrorMessage', {
302+
isInvalid &&
303+
(starCheck
304+
? i18n.translate(
305+
'indexPatternManagement.starCharacterNotAllowedValidationErrorMessage',
306+
{
307+
defaultMessage: 'The field cannot have * in the name.',
308+
}
309+
)
310+
: i18n.translate('indexPatternManagement.nameErrorMessage', {
303311
defaultMessage: 'Name is required',
304-
})
305-
: null
312+
}))
306313
}
307314
>
308315
<EuiFieldText

src/plugins/kibana_utils/common/errors/errors.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ export class DuplicateField extends KbnError {
2626
}
2727
}
2828

29+
/**
30+
* when a user is attempting to create a field with disallowed character in the name, like *
31+
* @param {String} character - the character not allowed in name
32+
* @param {String} name - the field name
33+
*/
34+
export class CharacterNotAllowedInField extends KbnError {
35+
constructor(character: string, name: string) {
36+
super(`The field "${name}" cannot have "${character}" in the name`);
37+
}
38+
}
39+
2940
/**
3041
* A saved object was not found
3142
*/

test/accessibility/apps/filter_panel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
2424
it('a11y test on add filter panel', async () => {
2525
await PageObjects.discover.openAddFilterPanel();
2626
await a11y.testAppSnapshot();
27+
await PageObjects.discover.closeAddFilterPanel();
2728
await filterBar.addFilter('OriginCityName', 'is', 'Rome');
2829
});
2930

0 commit comments

Comments
 (0)