mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[SecuritySolution] Fix the error where the fork branch was inserted at the end of the query (#225227)
## Summary Fix the FORK removal logic to insert the branch in the correct position when only one FORK branch is valid. ### How to reproduce it * Start empty kibana * Generate data with resolve_generator `node x-pack/solutions/security/plugins/security_solution/scripts/endpoint/resolver_generator.js` * Go to "Privileged user monitoring" page and add some privileged users * On the Dashboard page, scroll down to "Privileged user activity" and click the "Authentications" tab * It should display "No results found" instead of an error ### Before fix  ### After fix  ### 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
This commit is contained in:
parent
b143c8448b
commit
33a0f44c8d
2 changed files with 36 additions and 11 deletions
|
@ -79,6 +79,33 @@ describe('removeInvalidForkBranchesFromESQL', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
it('should remove fork and insert valid branch into the right position', () => {
|
||||
const esql = `
|
||||
FROM test-index
|
||||
| EVAL new_field_1 = foo
|
||||
| EVAL new_field_2 = foo
|
||||
| FORK
|
||||
(
|
||||
EVAL new_field_3 = foo
|
||||
| EVAL new_field_4 = foo
|
||||
) (
|
||||
WHERE not_a_field IS NULL
|
||||
)
|
||||
| EVAL new_field_5 = foo
|
||||
| EVAL new_field_6 = foo`;
|
||||
|
||||
expect(esql).not.toBe(undefined);
|
||||
expect(removeInvalidForkBranchesFromESQL(fields, esql)).toMatchInlineSnapshot(`
|
||||
"FROM test-index
|
||||
| EVAL new_field_1 = foo
|
||||
| EVAL new_field_2 = foo
|
||||
| EVAL new_field_3 = foo
|
||||
| EVAL new_field_4 = foo
|
||||
| EVAL new_field_5 = foo
|
||||
| EVAL new_field_6 = foo"
|
||||
`);
|
||||
});
|
||||
|
||||
it('should remove invalid branches and return FORK query if multiple valid branches exist', () => {
|
||||
const esql =
|
||||
'FROM test-index | FORK (WHERE foo IS NULL) (WHERE bar IS NULL) (WHERE not_a_field IS NULL)';
|
||||
|
@ -104,15 +131,13 @@ describe('removeInvalidForkBranchesFromESQL', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
// Fix The ESQL walker doesn't enter the sort "order" node for some reason
|
||||
// This scenario will cause an error if the query sorts by a invalid field that was not present anywhere else
|
||||
// it('should remove fork if the invalid field is present inside a SORT command with order', () => {
|
||||
// const esql = 'FROM test-index | FORK (SORT foo) (SORT not_a_field ASC)';
|
||||
// expect(removeInvalidForkBranchesFromESQL(fields, esql)).toMatchInlineSnapshot(`
|
||||
// "FROM test-index
|
||||
// | WHERE foo IS NULL"
|
||||
// `);
|
||||
// });
|
||||
it('should remove fork if the invalid field is present inside a SORT command with order', () => {
|
||||
const esql = 'FROM test-index | FORK (SORT foo) (SORT not_a_field ASC)';
|
||||
expect(removeInvalidForkBranchesFromESQL(fields, esql)).toMatchInlineSnapshot(`
|
||||
"FROM test-index
|
||||
| SORT foo"
|
||||
`);
|
||||
});
|
||||
|
||||
it('should remove fork if the invalid field is present inside a WHERE command', () => {
|
||||
const esql = 'FROM test-index | FORK (WHERE foo IS NULL) (WHERE not_a_field IS NULL)';
|
||||
|
|
|
@ -87,10 +87,10 @@ function moveForkBranchToToplevel(
|
|||
forkCommand: ESQLCommand<'fork'>,
|
||||
validBranch: ESQLAstQueryExpression
|
||||
) {
|
||||
mutate.generic.commands.remove(root, forkCommand);
|
||||
|
||||
// Find where the fork index is to insert the valid branch
|
||||
const forkIndex = root.commands.findIndex((cmd) => cmd.name === 'fork');
|
||||
mutate.generic.commands.remove(root, forkCommand);
|
||||
|
||||
validBranch.commands.reverse().forEach((command) => {
|
||||
mutate.generic.commands.insert(root, command, forkIndex);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue