-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solutions] Fixes bug with the filter query compatibility fo…
…r transforms (#104559) ## Summary * Fixes bug with the filter query compatibility to allow multiple object types and match all * Adds unit tests for the file * Fixes up the README.md a bit * Adds more unit tests to the utils folder we didn't have before * Adds more JSDocs ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated
- Loading branch information
1 parent
2c6801e
commit 6e21285
Showing
21 changed files
with
1,146 additions
and
25 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
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
67 changes: 67 additions & 0 deletions
67
x-pack/plugins/security_solution/public/transforms/utils/adjust_timerange.test.ts
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,67 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { adjustTimeRange } from './adjust_timerange'; | ||
import moment from 'moment'; | ||
|
||
/** Get the return type of adjustTimeRange for TypeScript checks against expected */ | ||
type ReturnTypeAdjustTimeRange = ReturnType<typeof adjustTimeRange>; | ||
|
||
describe('adjust_timerange', () => { | ||
beforeEach(() => { | ||
// Adds extra switch to suppress deprecation warnings that moment does not expose in TypeScript | ||
(moment as typeof moment & { | ||
suppressDeprecationWarnings: boolean; | ||
}).suppressDeprecationWarnings = true; | ||
}); | ||
|
||
afterEach(() => { | ||
// Adds extra switch to suppress deprecation warnings that moment does not expose in TypeScript | ||
(moment as typeof moment & { | ||
suppressDeprecationWarnings: boolean; | ||
}).suppressDeprecationWarnings = false; | ||
}); | ||
|
||
test('it will adjust the time range from by rounding down by an hour within "from"', () => { | ||
expect( | ||
adjustTimeRange({ | ||
interval: '5m', | ||
to: '2021-07-06T22:07:56.972Z', | ||
from: '2021-07-06T22:07:56.972Z', | ||
}) | ||
).toMatchObject<Partial<ReturnTypeAdjustTimeRange>>({ | ||
timeRangeAdjusted: { | ||
interval: '5m', | ||
to: '2021-07-06T22:07:56.972Z', | ||
from: '2021-07-06T22:00:00.000Z', // <-- Rounded down by an hour | ||
}, | ||
}); | ||
}); | ||
|
||
test('it will compute the duration between to and and from', () => { | ||
expect( | ||
adjustTimeRange({ | ||
interval: '5m', | ||
to: '2021-07-06T22:08:56.972Z', | ||
from: '2021-07-06T22:07:56.972Z', | ||
}).duration?.asMinutes() | ||
).toEqual(1); | ||
}); | ||
|
||
test('it will return "undefined" if the to and from are invalid dateMath parsable', () => { | ||
expect( | ||
adjustTimeRange({ | ||
interval: '5m', | ||
to: 'now-invalid', | ||
from: 'now-invalid2', | ||
}) | ||
).toMatchObject<Partial<ReturnTypeAdjustTimeRange>>({ | ||
timeRangeAdjusted: undefined, | ||
duration: 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
31 changes: 31 additions & 0 deletions
31
x-pack/plugins/security_solution/public/transforms/utils/create_indices_from_prefix.test.ts
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,31 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { createIndicesFromPrefix } from './create_indices_from_prefix'; | ||
|
||
/** Get the return type of createIndicesFromPrefix for TypeScript checks against expected */ | ||
type ReturnTypeCreateIndicesFromPrefix = ReturnType<typeof createIndicesFromPrefix>; | ||
|
||
describe('create_indices_from_prefix', () => { | ||
test('returns empty array given an empty array', () => { | ||
expect( | ||
createIndicesFromPrefix({ | ||
transformIndices: [], | ||
prefix: 'prefix', | ||
}) | ||
).toEqual<ReturnTypeCreateIndicesFromPrefix>([]); | ||
}); | ||
|
||
test('returns expected prefix given a set of indices', () => { | ||
expect( | ||
createIndicesFromPrefix({ | ||
transformIndices: ['index_1', 'index_2'], | ||
prefix: 'prefix', | ||
}) | ||
).toEqual<ReturnTypeCreateIndicesFromPrefix>(['.estc_prefix_index_1', '.estc_prefix_index_2']); | ||
}); | ||
}); |
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
82 changes: 82 additions & 0 deletions
82
x-pack/plugins/security_solution/public/transforms/utils/get_settings_match.test.ts
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,82 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { getSettingsMatch } from './get_settings_match'; | ||
import { getTransformConfigSchemaMock } from './transform_config_schema.mock'; | ||
|
||
/** Get the return type of createIndicesFromPrefix for TypeScript checks against expected */ | ||
type ReturnTypeCreateIndicesFromPrefix = ReturnType<typeof getSettingsMatch>; | ||
|
||
describe('get_settings_match', () => { | ||
test('it returns undefined given an empty array of indices', () => { | ||
expect( | ||
getSettingsMatch({ | ||
indices: [], | ||
transformSettings: getTransformConfigSchemaMock(), | ||
}) | ||
).toEqual<ReturnTypeCreateIndicesFromPrefix>(undefined); | ||
}); | ||
|
||
test('it returns a setting given an index pattern that matches', () => { | ||
expect( | ||
getSettingsMatch({ | ||
indices: [ | ||
'auditbeat-*', | ||
'endgame-*', | ||
'filebeat-*', | ||
'logs-*', | ||
'packetbeat-*', | ||
'winlogbeat-*', | ||
], | ||
transformSettings: getTransformConfigSchemaMock(), | ||
}) | ||
).toEqual<ReturnTypeCreateIndicesFromPrefix>(getTransformConfigSchemaMock().settings[0]); | ||
}); | ||
|
||
test('it returns a setting given an index pattern that matches even if the indices are different order', () => { | ||
expect( | ||
getSettingsMatch({ | ||
indices: [ | ||
'endgame-*', | ||
'filebeat-*', | ||
'logs-*', | ||
'auditbeat-*', | ||
'packetbeat-*', | ||
'winlogbeat-*', | ||
], | ||
transformSettings: getTransformConfigSchemaMock(), | ||
}) | ||
).toEqual<ReturnTypeCreateIndicesFromPrefix>(getTransformConfigSchemaMock().settings[0]); | ||
}); | ||
|
||
test('it returns a setting given an index pattern that matches and removes any that have a dash in them meaning to subtract them', () => { | ||
expect( | ||
getSettingsMatch({ | ||
indices: [ | ||
'endgame-*', | ||
'filebeat-*', | ||
'logs-*', | ||
'auditbeat-*', | ||
'packetbeat-*', | ||
'winlogbeat-*', | ||
'-subtract-1', // extra dashed one that should still allow a match | ||
'-subtract-2', // extra dashed one that should still allow a match | ||
], | ||
transformSettings: getTransformConfigSchemaMock(), | ||
}) | ||
).toEqual<ReturnTypeCreateIndicesFromPrefix>(getTransformConfigSchemaMock().settings[0]); | ||
}); | ||
|
||
test('it returns "undefined" given a set of indices that do not match a setting', () => { | ||
expect( | ||
getSettingsMatch({ | ||
indices: ['endgame-*', 'filebeat-*', 'logs-*', 'auditbeat-*', 'packetbeat-*'], | ||
transformSettings: getTransformConfigSchemaMock(), | ||
}) | ||
).toEqual<ReturnTypeCreateIndicesFromPrefix>(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
Oops, something went wrong.