forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Adds normalization for
query
fields before diff…
… algorithm comparison (elastic#203482) ## Summary Fixes elastic#203151 Adds a normalization for the `kql_query`, `eql_query`, and `esql_query` fields that trims the whitespace from the beginning and end of query strings for a more robust comparison in the diff algorithms. Since whitespace before or after the query string is purely a formatting choice and doesn't impact the query itself, we discard the excess whitespace characters before the direct string comparison. ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed
- Loading branch information
Showing
7 changed files
with
224 additions
and
4 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
61 changes: 61 additions & 0 deletions
61
...rity_solution/common/detection_engine/prebuilt_rules/diff/extract_rule_data_query.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,61 @@ | ||
/* | ||
* 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 { KqlQueryType } from '../../../api/detection_engine'; | ||
import { | ||
extractRuleEqlQuery, | ||
extractRuleEsqlQuery, | ||
extractRuleKqlQuery, | ||
} from './extract_rule_data_query'; | ||
|
||
describe('extract rule data queries', () => { | ||
describe('extractRuleKqlQuery', () => { | ||
it('extracts a trimmed version of the query field for inline query types', () => { | ||
const extractedKqlQuery = extractRuleKqlQuery('\nevent.kind:alert\n', 'kuery', [], undefined); | ||
|
||
expect(extractedKqlQuery).toEqual({ | ||
type: KqlQueryType.inline_query, | ||
query: 'event.kind:alert', | ||
language: 'kuery', | ||
filters: [], | ||
}); | ||
}); | ||
}); | ||
|
||
describe('extractRuleEqlQuery', () => { | ||
it('extracts a trimmed version of the query field', () => { | ||
const extractedEqlQuery = extractRuleEqlQuery({ | ||
query: '\n\nquery where true\n\n', | ||
language: 'eql', | ||
filters: [], | ||
eventCategoryOverride: undefined, | ||
timestampField: undefined, | ||
tiebreakerField: undefined, | ||
}); | ||
|
||
expect(extractedEqlQuery).toEqual({ | ||
query: 'query where true', | ||
language: 'eql', | ||
filters: [], | ||
event_category_override: undefined, | ||
timestamp_field: undefined, | ||
tiebreaker_field: undefined, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('extractRuleEsqlQuery', () => { | ||
it('extracts a trimmed version of the query field', () => { | ||
const extractedEsqlQuery = extractRuleEsqlQuery('\nFROM * where true\t\n', 'esql'); | ||
|
||
expect(extractedEsqlQuery).toEqual({ | ||
query: 'FROM * where true', | ||
language: 'esql', | ||
}); | ||
}); | ||
}); | ||
}); |
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