Skip to content
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

[Security Solution][Detections] fixes tests related to prebuilt rules update #138625

Conversation

vitaliidm
Copy link
Contributor

@vitaliidm vitaliidm commented Aug 11, 2022

Summary

fixes tests related to prebuilt rules update tests failures(#138574 (comment)):

  • removed hardcoded rule version value
  • required_fields are not tested agains empty array, but agains actual immutable rule value

@vitaliidm vitaliidm self-assigned this Aug 11, 2022
@vitaliidm vitaliidm added Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Feature:Rule Management Security Solution Detection Rule Management area Team:Detection Rule Management Security Detection Rule Management Team v8.4.0 release_note:skip Skip the PR/issue when compiling release notes labels Aug 11, 2022
@vitaliidm vitaliidm requested review from a team and banderror and removed request for a team August 11, 2022 15:14
@vitaliidm vitaliidm added the backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) label Aug 11, 2022
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @vitaliidm

@vitaliidm vitaliidm marked this pull request as ready for review August 11, 2022 16:00
@vitaliidm vitaliidm requested a review from a team as a code owner August 11, 2022 16:00
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@@ -120,10 +120,27 @@ export default ({ getService }: FtrProviderContext) => {
rule_id: immutableRule.rule_id, // Rule id should match the same as the immutable rule
version: immutableRule.version, // This version number should not change when an immutable rule is updated
immutable: true, // It should stay immutable true when returning
required_fields: immutableRule.required_fields, // required_fields cannot be modified, so newRuleToUpdate will have required_fields from immutable rule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why required_fields are special so that we need to check them explicitly? What about other rule fields like related_integrations, index, etc? It feels like this expected object should be built based on immutableRule. Something like this:

        const expected = {
          ...immutableRule,
          immutable: true,
          actions: ...
          // and other properties that we expect to be changed

Copy link
Contributor Author

@vitaliidm vitaliidm Aug 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like this expected object should be built based on immutableRule

Agree on that. Here is a quick explanation why it's done like this

Scenarios written in this file are using immutable rule, fetching it by hardcoded ruleId.

       const immutableRule = await getRule(supertest, log, '9a1a2dae-0b5f-4c3d-8305-a268d404c306');
        const hookAction = await createNewAction(supertest, log);

Then rule mock data is created from getSimpleRule, that uses immutable rule id,
Existing immutable rule is getting updated with that mock, and then assertions are made against it.

        const newRuleToUpdate = getSimpleRule(immutableRule.rule_id);
        const ruleToUpdate = getRuleWithWebHookAction(hookAction.id, false, newRuleToUpdate);
        const updatedRule = await updateRule(supertest, log, ruleToUpdate);
        const bodyToCompare = removeServerGeneratedProperties(updatedRule);

I'm not sure, what is rationale for doing this. But I didn't want for a fix that unblocks another PR, start refactoring tests there, given BC4 soon.

We may look further, after release, as current implementation is not obvious for me, at least.
If you prefer I can look to refactor it now, but I'm not sure if no side effects will be discovered

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vitaliidm We should definitely unblock #138574 as soon as we can, so yea, let's merge this PR as is.

However, I think we should fix this test and make it more robust so it doesn't fail in the future for similar reasons. The fix could be safely backported to the 8.4 branch because it's a test 🙂 We don't have to wait for the release to happen, the test can be reworked in a follow-up PR right away.

Copy link
Contributor Author

@vitaliidm vitaliidm Aug 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @banderror
Here is a ticket to track it: #138757
I think it would make to schedule it in the next release, so next prebuilt update won't cause similar failures

Copy link
Contributor

@banderror banderror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vitaliidm Thank you for taking over this PR with rule updates (#138574) 🙏 My suggestion is to merge this PR as is and rework the test in a follow-up one.

@@ -120,10 +120,27 @@ export default ({ getService }: FtrProviderContext) => {
rule_id: immutableRule.rule_id, // Rule id should match the same as the immutable rule
version: immutableRule.version, // This version number should not change when an immutable rule is updated
immutable: true, // It should stay immutable true when returning
required_fields: immutableRule.required_fields, // required_fields cannot be modified, so newRuleToUpdate will have required_fields from immutable rule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vitaliidm We should definitely unblock #138574 as soon as we can, so yea, let's merge this PR as is.

However, I think we should fix this test and make it more robust so it doesn't fail in the future for similar reasons. The fix could be safely backported to the 8.4 branch because it's a test 🙂 We don't have to wait for the release to happen, the test can be reworked in a follow-up PR right away.

@vitaliidm vitaliidm merged commit 800cc72 into elastic:main Aug 12, 2022
@vitaliidm vitaliidm deleted the detections/fix-tests-related-prebuilt-rules-update branch August 12, 2022 16:02
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Aug 12, 2022
… update (elastic#138625)

## Summary

fixes tests related to prebuilt rules update tests failures(elastic#138574 (comment)):
- removed hardcoded rule version value
- required_fields are not tested agains empty array, but agains actual immutable rule value

(cherry picked from commit 800cc72)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.4

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Aug 15, 2022
… update (elastic#138625) (elastic#138754)

## Summary

fixes tests related to prebuilt rules update tests failures(elastic#138574 (comment)):
- removed hardcoded rule version value
- required_fields are not tested agains empty array, but agains actual immutable rule value

(cherry picked from commit 800cc72)

Co-authored-by: Vitalii Dmyterko <[email protected]>
Mpdreamz pushed a commit to Mpdreamz/kibana that referenced this pull request Sep 6, 2022
… update (elastic#138625)

## Summary

fixes tests related to prebuilt rules update tests failures(elastic#138574 (comment)):
- removed hardcoded rule version value
- required_fields are not tested agains empty array, but agains actual immutable rule value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Feature:Rule Management Security Solution Detection Rule Management area release_note:skip Skip the PR/issue when compiling release notes Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.4.0 v8.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants