[Security Solution] Fix Coverage Overview API activity filter#163785
[Security Solution] Fix Coverage Overview API activity filter#163785maximpn merged 1 commit intoelastic:mainfrom
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) |
| 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.
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.
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.
| }); | ||
| }); | ||
|
|
||
| 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.
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
enabledanddisabledsimultaneously Coverage Overview endpoint returns the response filtered by the first value only.This PR fixes wrong behavior os if
enabledanddisabledvalues are set simultaneously the response contains combined results for bothenabledanddisabledactivity filter values.For example a request like below
would produce the same response as the following request
Checklist