-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SIEM] [Detections Engine] Import rules unit tests #57466
Conversation
…me rule-id are imported
Pinging @elastic/siem (Team:SIEM) |
@elasticmachine merge upstream |
x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/__mocks__/request_responses.ts
Outdated
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/import_rules_route.test.ts
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/import_rules_route.test.ts
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/import_rules_route.test.ts
Outdated
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/import_rules_route.test.ts
Outdated
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/import_rules_route.test.ts
Outdated
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/import_rules_route.test.ts
Outdated
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/import_rules_route.test.ts
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/utils.test.ts
Outdated
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/utils.test.ts
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/utils.test.ts
Show resolved
Hide resolved
x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/rules/utils.test.ts
Outdated
Show resolved
Hide resolved
…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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
…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 <[email protected]> * 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 <[email protected]>
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-id
are imported. Previously, when rules with the samerule-id
were 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