Skip to content

Commit

Permalink
Merge branch 'master' into alerting/view-in-app
Browse files Browse the repository at this point in the history
* master:
  [License Management] NP migration (elastic#60250)
  Fix create alert button from not showing in alerts list (elastic#60444)
  [SIEM][Case] Update connector through flyout (elastic#60307)
  add data-test-subj where possible on SO management table (elastic#60226)
  Enforce `required` presence for value/key validation of `recordOf` and `mapOf`. (elastic#60406)
  • Loading branch information
gmmorris committed Mar 18, 2020
2 parents ff45d00 + 2a8a7d7 commit 4584654
Show file tree
Hide file tree
Showing 137 changed files with 3,855 additions and 3,800 deletions.
12 changes: 8 additions & 4 deletions packages/kbn-config-schema/src/internals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ export const internals = Joi.extend([
for (const [entryKey, entryValue] of value) {
const { value: validatedEntryKey, error: keyError } = Joi.validate(
entryKey,
params.key
params.key,
{ presence: 'required' }
);

if (keyError) {
Expand All @@ -323,7 +324,8 @@ export const internals = Joi.extend([

const { value: validatedEntryValue, error: valueError } = Joi.validate(
entryValue,
params.value
params.value,
{ presence: 'required' }
);

if (valueError) {
Expand Down Expand Up @@ -374,7 +376,8 @@ export const internals = Joi.extend([
for (const [entryKey, entryValue] of Object.entries(value)) {
const { value: validatedEntryKey, error: keyError } = Joi.validate(
entryKey,
params.key
params.key,
{ presence: 'required' }
);

if (keyError) {
Expand All @@ -383,7 +386,8 @@ export const internals = Joi.extend([

const { value: validatedEntryValue, error: valueError } = Joi.validate(
entryValue,
params.value
params.value,
{ presence: 'required' }
);

if (valueError) {
Expand Down
18 changes: 18 additions & 0 deletions packages/kbn-config-schema/src/types/map_of_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@ test('object within mapOf', () => {
expect(type.validate(value)).toEqual(expected);
});

test('enforces required object fields within mapOf', () => {
const type = schema.mapOf(
schema.string(),
schema.object({
bar: schema.object({
baz: schema.number(),
}),
})
);
const value = {
foo: {},
};

expect(() => type.validate(value)).toThrowErrorMatchingInlineSnapshot(
`"[foo.bar.baz]: expected value of type [number] but got [undefined]"`
);
});

test('error preserves full path', () => {
const type = schema.object({
grandParentKey: schema.object({
Expand Down
5 changes: 4 additions & 1 deletion packages/kbn-config-schema/src/types/map_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export class MapOfType<K, V> extends Type<Map<K, V>> {
path.length,
0,
// If `key` validation failed, let's stress that to make error more obvious.
type === 'map.key' ? `key("${entryKey}")` : entryKey.toString()
type === 'map.key' ? `key("${entryKey}")` : entryKey.toString(),
// Error could have happened deep inside value/key schema and error message should
// include full path.
...(reason instanceof SchemaTypeError ? reason.path : [])
);

return reason instanceof SchemaTypesError
Expand Down
18 changes: 18 additions & 0 deletions packages/kbn-config-schema/src/types/record_of_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@ test('object within recordOf', () => {
expect(type.validate(value)).toEqual({ foo: { bar: 123 } });
});

test('enforces required object fields within recordOf', () => {
const type = schema.recordOf(
schema.string(),
schema.object({
bar: schema.object({
baz: schema.number(),
}),
})
);
const value = {
foo: {},
};

expect(() => type.validate(value)).toThrowErrorMatchingInlineSnapshot(
`"[foo.bar.baz]: expected value of type [number] but got [undefined]"`
);
});

test('error preserves full path', () => {
const type = schema.object({
grandParentKey: schema.object({
Expand Down
5 changes: 4 additions & 1 deletion packages/kbn-config-schema/src/types/record_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export class RecordOfType<K extends string, V> extends Type<Record<K, V>> {
path.length,
0,
// If `key` validation failed, let's stress that to make error more obvious.
type === 'record.key' ? `key("${entryKey}")` : entryKey.toString()
type === 'record.key' ? `key("${entryKey}")` : entryKey.toString(),
// Error could have happened deep inside value/key schema and error message should
// include full path.
...(reason instanceof SchemaTypeError ? reason.path : [])
);

return reason instanceof SchemaTypesError
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export class Table extends PureComponent {
{ defaultMessage: 'Type of the saved object' }
),
sortable: false,
'data-test-subj': 'savedObjectsTableRowType',
render: (type, object) => {
return (
<EuiToolTip position="top" content={getSavedObjectLabel(type)}>
Expand All @@ -201,6 +202,7 @@ export class Table extends PureComponent {
),
dataType: 'string',
sortable: false,
'data-test-subj': 'savedObjectsTableRowTitle',
render: (title, object) => {
const { path } = object.meta.inAppUrl || {};
const canGoInApp = this.props.canGoInApp(object);
Expand Down Expand Up @@ -230,6 +232,7 @@ export class Table extends PureComponent {
icon: 'inspect',
onClick: object => goInspectObject(object),
available: object => !!object.meta.editUrl,
'data-test-subj': 'savedObjectsTableAction-inspect',
},
{
name: i18n.translate(
Expand All @@ -246,10 +249,12 @@ export class Table extends PureComponent {
type: 'icon',
icon: 'kqlSelector',
onClick: object => onShowRelationships(object),
'data-test-subj': 'savedObjectsTableAction-relationships',
},
...this.extraActions.map(action => {
return {
...action.euiAction,
'data-test-subj': `savedObjectsTableAction-${action.id}`,
onClick: object => {
this.setState({
activeAction: action,
Expand Down Expand Up @@ -372,6 +377,9 @@ export class Table extends PureComponent {
pagination={pagination}
selection={selection}
onChange={onTableChange}
rowProps={item => ({
'data-test-subj': `savedObjectsTableRow row-${item.id}`,
})}
/>
</div>
</Fragment>
Expand Down
2 changes: 1 addition & 1 deletion x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"xpack.infra": "plugins/infra",
"xpack.ingestManager": "plugins/ingest_manager",
"xpack.lens": "legacy/plugins/lens",
"xpack.licenseMgmt": "legacy/plugins/license_management",
"xpack.licenseMgmt": "plugins/license_management",
"xpack.licensing": "plugins/licensing",
"xpack.logstash": "legacy/plugins/logstash",
"xpack.main": "legacy/plugins/xpack_main",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { logstash } from './legacy/plugins/logstash';
import { beats } from './legacy/plugins/beats_management';
import { apm } from './legacy/plugins/apm';
import { maps } from './legacy/plugins/maps';
import { licenseManagement } from './legacy/plugins/license_management';
import { indexManagement } from './legacy/plugins/index_management';
import { indexLifecycleManagement } from './legacy/plugins/index_lifecycle_management';
import { spaces } from './legacy/plugins/spaces';
Expand Down Expand Up @@ -52,7 +51,6 @@ module.exports = function(kibana) {
apm(kibana),
maps(kibana),
canvas(kibana),
licenseManagement(kibana),
indexManagement(kibana),
indexLifecycleManagement(kibana),
infra(kibana),
Expand Down
Loading

0 comments on commit 4584654

Please sign in to comment.