-
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
[Security Solution] Fix Coverage Overview API activity filter #163785
[Security Solution] Fix Coverage Overview API activity filter #163785
Conversation
💚 Build Succeeded
Metrics [docs]
To update your PR or re-run it, just comment with: cc @maximpn |
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
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.
Tested locally and reviewed the changes. Everything looks good and works fine 👍
I left a few minor comments for your consideration @maximpn. Thank you for the fix.
enabled: | ||
(activitySet.has(CoverageOverviewRuleActivity.Enabled) && | ||
activitySet.has(CoverageOverviewRuleActivity.Disabled)) || | ||
(!activitySet.has(CoverageOverviewRuleActivity.Enabled) && | ||
!activitySet.has(CoverageOverviewRuleActivity.Disabled)) | ||
? undefined | ||
: activitySet.has(CoverageOverviewRuleActivity.Enabled), |
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.
Nit: We could extract it to a function and use if
instead of ternaries to make this code a bit more readable.
...
enabled: getIsEnabledFilter(activitySet)
...
function getIsEnabledFilter(activitySet: Set<CoverageOverviewRuleActivity>): boolean | undefined {
const bothSpecified =
activitySet.has(CoverageOverviewRuleActivity.Enabled) &&
activitySet.has(CoverageOverviewRuleActivity.Disabled);
const noneSpecified =
!activitySet.has(CoverageOverviewRuleActivity.Enabled) &&
!activitySet.has(CoverageOverviewRuleActivity.Disabled);
return bothSpecified || noneSpecified
? undefined
: activitySet.has(CoverageOverviewRuleActivity.Enabled);
}
|
||
it('returns response filtered by enabled and disabled rules equal to response if enabled and disabled are not set', async () => { | ||
const expectedRule1 = await createRule(supertest, log, { | ||
...getSimpleRule('rule-1'), |
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.
getSimpleRule('rule-1', false)
would be a more robust expression, in case someone removes the enabled
parameter or changes its default value. This can be important for this particular test that actually depends on this.
@@ -341,6 +341,51 @@ export default ({ getService }: FtrProviderContext): void => { | |||
}, | |||
}); | |||
}); | |||
|
|||
it('returns response filtered by enabled and disabled rules equal to response if enabled and disabled are not set', async () => { |
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.
Nit: returns all rules if both enabled and disabled filters are specified in the request
**Relates to:** #158246 ## Summary If activity filter contains both allowed values `enabled` and `disabled` simultaneously Coverage Overview endpoint returns the response filtered by the first value only. This PR fixes wrong behavior os if `enabled` and `disabled` values are set simultaneously the response contains combined results for both `enabled` and `disabled` activity filter values. For example a request like below ```sh curl -X POST --user elastic:changeme -H 'Content-Type: application/json' -H 'kbn-xsrf: 123' -d '{"filter":{"activity": ["enabled","disabled"]}}' http://localhost:5601/kbn/internal/detection_engine/rules/_coverage_overview --verbose ``` would produce the same response as the following request ```sh curl -X POST --user elastic:changeme -H 'Content-Type: application/json' -H 'kbn-xsrf: 123' http://localhost:5601/kbn/internal/detection_engine/rules/_coverage_overview --verbose ``` ### Checklist - [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
Relates to: #158246
Summary
If activity filter contains both allowed values
enabled
anddisabled
simultaneously Coverage Overview endpoint returns the response filtered by the first value only.This PR fixes wrong behavior os if
enabled
anddisabled
values are set simultaneously the response contains combined results for bothenabled
anddisabled
activity filter values.For example a request like below
would produce the same response as the following request
Checklist