[SIEM] [Detections Engine] Import rules unit tests#57466
[SIEM] [Detections Engine] Import rules unit tests#57466yctercero merged 17 commits intoelastic:masterfrom
Conversation
…me rule-id are imported
|
Pinging @elastic/siem (Team:SIEM) |
|
@elasticmachine merge upstream |
…ts and pulling out repeated code into test utils
… into import_rules_unit_tests
| }, // using map (preserves ordering) | ||
| { | ||
| errors: new Map<string, BulkError>(), | ||
| rulesAcc: new Map<string, PromiseFromStreams>(), |
There was a problem hiding this comment.
Really awesome these are typed now and you are passing this through the reducer.
This function is a bit tricky to read and reason through (some functions are always like that) but with the tests and the way it is written I think I understand it.
FrankHassanabad
left a comment
There was a problem hiding this comment.
Checked it out, test ran it by doing
- fresh export, delete all custom rules, import
- fresh export, import (overwrite true)
- fresh export, import (no overwrite -- watch for errors)
- fresh export, delete all custom rules, hand duplicate them in the text file, import them again
Thank you for the unit tests and cleaning things up this looks really good and much more type safe code for us.
|
@yctercero Is it possible to throw in a test that will result in the |
dhurley14
left a comment
There was a problem hiding this comment.
LGTM - my comment on adding a test for the catch block on the import test is optional. Nice job!
@dhurley14 That's a good call. I added a test that throws on |
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
* Added unit tests for detection engine import_rules_route and moved out small portion of import_rules_route into a util to be unit tested as well. Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
* Added unit tests for detection engine import_rules_route and moved out small portion of import_rules_route into a util to be unit tested as well. Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
* Added unit tests for detection engine import_rules_route and moved out small portion of import_rules_route into a util to be unit tested as well. Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
…8019) * [SIEM] [Detections Engine] Import rules unit tests (#57466) * Added unit tests for detection engine import_rules_route and moved out small portion of import_rules_route into a util to be unit tested as well. Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * Updating tests to reflect state of 7.6. 7.7 and 8 include code from # 56814 that was not backported to 7.6 Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Summary
Added unit tests for import_rules_route. Moved out a small portion of route code into util to be tested and updated it so that a conflict error is reported now when two rules with the same
rule-idare imported. Previously, when rules with the samerule-idwere imported, no conflict was reported.To test, tried importing 4 rules - 2 of them had the same
rule-id, 1 had a syntax error.When importing with


overwrite=false:When importing with


overwrite=true:Big thanks to @FrankHassanabad for his help figuring out how to properly mock multipart payloads!
Checklist
Delete any items that are not applicable to this PR.
Any text added follows EUI's writing guidelines, uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)Documentation was added for features that require explanation or tutorialsThis was checked for keyboard-only and screenreader accessibilityThis renders correctly on smaller devices using a responsive layout. (You can test this in your browser[ ] This was checked for cross-browser compatibility, including a check against IE11For maintainers