forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Adds tests for coverage overview page (elastic#16…
…8058) **Resolves: elastic#162250 ## Summary Adds remaining unit, api integration, and e2e cypress tests for the coverage overview page in accordance to the [existing test plan](https://github.com/elastic/kibana/blob/main/x-pack/plugins/security_solution/docs/testing/test_plans/detection_response/rule_management/coverage_overview_dashboard.md) - [Flaky test runner build](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4756) ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [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 ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- Loading branch information
Showing
28 changed files
with
1,626 additions
and
610 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
Validating CODEOWNERS rules …
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.