-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.12] [Security Solution] Adds tests for coverage overview page (#16…
…8058) (#174549) # Backport This will backport the following commits from `main` to `8.12`: - [[Security Solution] Adds tests for coverage overview page (#168058)](#168058) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Davis Plumlee","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-01-09T19:09:40Z","message":"[Security Solution] Adds tests for coverage overview page (#168058)\n\n**Resolves: https://github.com/elastic/kibana/issues/162250**\r\n\r\n## Summary\r\n\r\nAdds remaining unit, api integration, and e2e cypress tests for the\r\ncoverage overview page in accordance to the [existing test\r\nplan](https://github.com/elastic/kibana/blob/main/x-pack/plugins/security_solution/docs/testing/test_plans/detection_response/rule_management/coverage_overview_dashboard.md)\r\n\r\n- [Flaky test runner\r\nbuild](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4756)\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [x] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"315cf9d399c62a69dd02a1aed5ce7118ffa9885a","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["technical debt","release_note:skip","Team:Detections and Resp","Team: SecuritySolution","Feature:Rule Management","Team:Detection Rule Management","v8.12.0","v8.13.0"],"number":168058,"url":"https://github.com/elastic/kibana/pull/168058","mergeCommit":{"message":"[Security Solution] Adds tests for coverage overview page (#168058)\n\n**Resolves: https://github.com/elastic/kibana/issues/162250**\r\n\r\n## Summary\r\n\r\nAdds remaining unit, api integration, and e2e cypress tests for the\r\ncoverage overview page in accordance to the [existing test\r\nplan](https://github.com/elastic/kibana/blob/main/x-pack/plugins/security_solution/docs/testing/test_plans/detection_response/rule_management/coverage_overview_dashboard.md)\r\n\r\n- [Flaky test runner\r\nbuild](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4756)\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [x] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"315cf9d399c62a69dd02a1aed5ce7118ffa9885a"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/168058","number":168058,"mergeCommit":{"message":"[Security Solution] Adds tests for coverage overview page (#168058)\n\n**Resolves: https://github.com/elastic/kibana/issues/162250**\r\n\r\n## Summary\r\n\r\nAdds remaining unit, api integration, and e2e cypress tests for the\r\ncoverage overview page in accordance to the [existing test\r\nplan](https://github.com/elastic/kibana/blob/main/x-pack/plugins/security_solution/docs/testing/test_plans/detection_response/rule_management/coverage_overview_dashboard.md)\r\n\r\n- [Flaky test runner\r\nbuild](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4756)\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [x] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"315cf9d399c62a69dd02a1aed5ce7118ffa9885a"}}]}] BACKPORT-->
- Loading branch information
Showing
26 changed files
with
1,624 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...on/api/detection_engine/rule_management/coverage_overview/coverage_overview_route.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { left } from 'fp-ts/lib/Either'; | ||
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; | ||
import { | ||
CoverageOverviewRequestBody, | ||
CoverageOverviewRuleActivity, | ||
CoverageOverviewRuleSource, | ||
} from './coverage_overview_route'; | ||
|
||
describe('Coverage overview request schema', () => { | ||
test('empty object validates', () => { | ||
const payload: CoverageOverviewRequestBody = {}; | ||
|
||
const decoded = CoverageOverviewRequestBody.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('validates with all fields populated', () => { | ||
const payload: CoverageOverviewRequestBody = { | ||
filter: { | ||
activity: [CoverageOverviewRuleActivity.Enabled, CoverageOverviewRuleActivity.Disabled], | ||
source: [CoverageOverviewRuleSource.Custom, CoverageOverviewRuleSource.Prebuilt], | ||
search_term: 'search term', | ||
}, | ||
}; | ||
|
||
const decoded = CoverageOverviewRequestBody.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('does NOT validate with extra fields', () => { | ||
const payload: CoverageOverviewRequestBody & { invalid_field: string } = { | ||
filter: { | ||
activity: [CoverageOverviewRuleActivity.Enabled, CoverageOverviewRuleActivity.Disabled], | ||
source: [CoverageOverviewRuleSource.Custom, CoverageOverviewRuleSource.Prebuilt], | ||
search_term: 'search term', | ||
}, | ||
invalid_field: 'invalid field', | ||
}; | ||
|
||
const decoded = CoverageOverviewRequestBody.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual(['invalid keys "invalid_field"']); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('does NOT validate with invalid filter values', () => { | ||
const payload: CoverageOverviewRequestBody = { | ||
filter: { | ||
// @ts-expect-error | ||
activity: ['Wrong activity field'], | ||
// @ts-expect-error | ||
source: ['Wrong source field'], | ||
search_term: 'search term', | ||
}, | ||
}; | ||
|
||
const decoded = CoverageOverviewRequestBody.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "Wrong activity field" supplied to "filter,activity"', | ||
'Invalid value "Wrong source field" supplied to "filter,source"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('does NOT validate with empty filter arrays', () => { | ||
const payload: CoverageOverviewRequestBody = { | ||
filter: { | ||
activity: [], | ||
source: [], | ||
search_term: 'search term', | ||
}, | ||
}; | ||
|
||
const decoded = CoverageOverviewRequestBody.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "[]" supplied to "filter,activity"', | ||
'Invalid value "[]" supplied to "filter,source"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('does NOT validate with empty search_term', () => { | ||
const payload: CoverageOverviewRequestBody = { | ||
filter: { | ||
search_term: '', | ||
}, | ||
}; | ||
|
||
const decoded = CoverageOverviewRequestBody.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "" supplied to "filter,search_term"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.