-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rops/monitoring_ui_integration
- Loading branch information
Showing
230 changed files
with
7,428 additions
and
2,059 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
5.1.1 | ||
5.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { normalizeString, normalizeObject, normalizeDate } from './utils'; | ||
|
||
describe('normalizeString', () => { | ||
test('should return undefined for non string input', async () => { | ||
expect(normalizeString({})).toBe(undefined); | ||
expect(normalizeString(12344)).toBe(undefined); | ||
expect(normalizeString(null)).toBe(undefined); | ||
}); | ||
|
||
test('should return the string for string input', async () => { | ||
expect(normalizeString('logstash')).toBe('logstash'); | ||
}); | ||
}); | ||
|
||
describe('normalizeDate', () => { | ||
test('should return timestamp if timestamp is given', async () => { | ||
expect(normalizeDate(1654702414)).toBe(1654702414); | ||
}); | ||
|
||
test('should return null if NaN is given', async () => { | ||
expect(normalizeDate(NaN)).toBe(null); | ||
}); | ||
|
||
test('should return date if a date object is given', async () => { | ||
const date = Date.now(); | ||
expect(normalizeDate(date)).toBe(date); | ||
}); | ||
|
||
test('should return undefined for a string', async () => { | ||
expect(normalizeDate('test')).toBe('test'); | ||
}); | ||
|
||
test('should return the object if object is given', async () => { | ||
expect(normalizeDate({ test: 'test' })).toStrictEqual({ test: 'test' }); | ||
}); | ||
}); | ||
|
||
describe('normalizeObject', () => { | ||
test('should throw if a function is given as the object property', async () => { | ||
expect(() => { | ||
normalizeObject({ toJSON: () => alert('gotcha') }); | ||
}).toThrow('a function cannot be used as a property name'); | ||
}); | ||
|
||
test('should throw if a function is given on a nested object', async () => { | ||
expect(() => { | ||
normalizeObject({ test: { toJSON: () => alert('gotcha') } }); | ||
}).toThrow('a function cannot be used as a property name'); | ||
}); | ||
|
||
test('should return null for null', async () => { | ||
expect(normalizeObject(null)).toBe(null); | ||
}); | ||
|
||
test('should return null for undefined', async () => { | ||
expect(normalizeObject(undefined)).toBe(null); | ||
}); | ||
|
||
test('should return the object', async () => { | ||
expect(normalizeObject({ test: 'test' })).toStrictEqual({ test: 'test' }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import { ensureNoUnsafeProperties } from '@kbn/std'; | ||
|
||
export function normalizeDate(date: unknown) { | ||
if (typeof date === 'number') { | ||
return !isNaN(date) ? date : null; | ||
} else if (date instanceof Date) { | ||
return date; | ||
} else { | ||
return normalizeObject(date); | ||
} | ||
} | ||
|
||
/* | ||
Recursive function to check a nested object for a function property | ||
This function should run before JSON.stringify to ensure that functions such as toJSON | ||
are not invoked. We dont use the replacer function as it doesnt catch the toJSON function | ||
*/ | ||
export function checkObjectForFunctionProperty(object: unknown): boolean { | ||
if (object === null || object === undefined) { | ||
return false; | ||
} | ||
if (typeof object === 'function') { | ||
return true; | ||
} | ||
if (object && typeof object === 'object') { | ||
return Object.values(object).some( | ||
(value) => typeof value === 'function' || checkObjectForFunctionProperty(value) | ||
); | ||
} | ||
|
||
return false; | ||
} | ||
/* | ||
We want to be strict here when an object is passed to a Vega function | ||
- NaN (will be converted to null) | ||
- undefined (key will be removed) | ||
- Date (will be replaced by its toString value) | ||
- will throw an error when a function is found | ||
*/ | ||
export function normalizeObject(object: unknown) { | ||
if (checkObjectForFunctionProperty(object)) { | ||
throw new Error('a function cannot be used as a property name'); | ||
} | ||
const normalizedObject = object ? JSON.parse(JSON.stringify(object)) : null; | ||
ensureNoUnsafeProperties(normalizedObject); | ||
return normalizedObject; | ||
} | ||
|
||
export function normalizeString(string: unknown) { | ||
return typeof string === 'string' ? string : undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.