-
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.
[Security Solution][Endpoint] Add event filters summary card to the f…
…leet endpoint tab (#100668) (#100915) * Shows event filters card on fleet page * Uses aggs instead of while loop to retrieve summary data * Add request and response types in the lists package * Fixes old import * Removes old i18n keys * Removes more old i18n keys * Use consts for exception lists url and endpoint event filter list id * Uses event filters service to retrieve summary data * Fixes addressed pr comments such as changing the route without underscore, adding aggs type, validating response, and more * Uses useMemo instead of useState to memoize object * Add new e2e test for summart endpoint * Handle api errors on event filters and trusted apps summary api calls * Add api error message to the toast * Fix wrong i18n key * Change span tag by react fragment * Uses styled components instead of modify compontent style directly and small improvements on test -> ts * Adds curls script for summary route Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: David Sánchez <[email protected]>
- Loading branch information
1 parent
3c7b809
commit 499d47a
Showing
29 changed files
with
857 additions
and
56 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
17 changes: 17 additions & 0 deletions
17
...securitysolution-io-ts-list-types/src/request/summary_exception_list_schema/index.mock.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,17 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ID, LIST_ID, NAMESPACE_TYPE } from '../../constants/index.mock'; | ||
|
||
import { SummaryExceptionListSchema } from '.'; | ||
|
||
export const getSummaryExceptionListSchemaMock = (): SummaryExceptionListSchema => ({ | ||
id: ID, | ||
list_id: LIST_ID, | ||
namespace_type: NAMESPACE_TYPE, | ||
}); |
126 changes: 126 additions & 0 deletions
126
...securitysolution-io-ts-list-types/src/request/summary_exception_list_schema/index.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,126 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { left } from 'fp-ts/lib/Either'; | ||
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; | ||
|
||
import { getSummaryExceptionListSchemaMock } from './index.mock'; | ||
import { SummaryExceptionListSchema, summaryExceptionListSchema } from '.'; | ||
|
||
describe('summary_exception_list_schema', () => { | ||
test('it should validate a typical exception list request', () => { | ||
const payload = getSummaryExceptionListSchemaMock(); | ||
const decoded = summaryExceptionListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should accept an undefined for "id"', () => { | ||
const payload = getSummaryExceptionListSchemaMock(); | ||
delete payload.id; | ||
const decoded = summaryExceptionListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should accept an undefined for "list_id"', () => { | ||
const payload = getSummaryExceptionListSchemaMock(); | ||
delete payload.list_id; | ||
const decoded = summaryExceptionListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should accept an undefined for "namespace_type" but default to "single"', () => { | ||
const payload = getSummaryExceptionListSchemaMock(); | ||
delete payload.namespace_type; | ||
const decoded = summaryExceptionListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(getSummaryExceptionListSchemaMock()); | ||
}); | ||
|
||
test('it should accept an undefined for "id", "list_id", "namespace_type" but default "namespace_type" to "single"', () => { | ||
const payload = getSummaryExceptionListSchemaMock(); | ||
delete payload.id; | ||
delete payload.namespace_type; | ||
delete payload.list_id; | ||
const output = getSummaryExceptionListSchemaMock(); | ||
delete output.id; | ||
delete output.list_id; | ||
const decoded = summaryExceptionListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(output); | ||
}); | ||
|
||
test('it should accept an undefined for "id", "list_id"', () => { | ||
const payload = getSummaryExceptionListSchemaMock(); | ||
delete payload.id; | ||
delete payload.list_id; | ||
const decoded = summaryExceptionListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should accept an undefined for "id", "namespace_type" but default "namespace_type" to "single"', () => { | ||
const payload = getSummaryExceptionListSchemaMock(); | ||
delete payload.id; | ||
delete payload.namespace_type; | ||
const output = getSummaryExceptionListSchemaMock(); | ||
delete output.id; | ||
const decoded = summaryExceptionListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(output); | ||
}); | ||
|
||
test('it should accept an undefined for "list_id", "namespace_type" but default "namespace_type" to "single"', () => { | ||
const payload = getSummaryExceptionListSchemaMock(); | ||
delete payload.namespace_type; | ||
delete payload.list_id; | ||
const output = getSummaryExceptionListSchemaMock(); | ||
delete output.list_id; | ||
const decoded = summaryExceptionListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(output); | ||
}); | ||
|
||
test('it should not allow an extra key to be sent in', () => { | ||
const payload: SummaryExceptionListSchema & { | ||
extraKey?: string; | ||
} = getSummaryExceptionListSchemaMock(); | ||
payload.extraKey = 'some new value'; | ||
const decoded = summaryExceptionListSchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = foldLeftRight(checked); | ||
expect(getPaths(left(message.errors))).toEqual(['invalid keys "extraKey"']); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
.../kbn-securitysolution-io-ts-list-types/src/request/summary_exception_list_schema/index.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,33 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import * as t from 'io-ts'; | ||
|
||
import { NamespaceType } from '../../common/default_namespace'; | ||
import { RequiredKeepUndefined } from '../../common/required_keep_undefined'; | ||
import { id } from '../../common/id'; | ||
import { list_id } from '../../common/list_id'; | ||
import { namespace_type } from '../../common/namespace_type'; | ||
|
||
export const summaryExceptionListSchema = t.exact( | ||
t.partial({ | ||
id, | ||
list_id, | ||
namespace_type, // defaults to 'single' if not set during decode | ||
}) | ||
); | ||
|
||
export type SummaryExceptionListSchema = t.OutputOf<typeof summaryExceptionListSchema>; | ||
|
||
// This type is used after a decode since some things are defaults after a decode. | ||
export type SummaryExceptionListSchemaDecoded = Omit< | ||
RequiredKeepUndefined<t.TypeOf<typeof summaryExceptionListSchema>>, | ||
'namespace_type' | ||
> & { | ||
namespace_type: NamespaceType; | ||
}; |
16 changes: 16 additions & 0 deletions
16
...ecuritysolution-io-ts-list-types/src/response/exception_list_summary_schema/index.mock.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,16 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ExceptionListSummarySchema } from '.'; | ||
|
||
export const getListSummaryResponseMock = (): ExceptionListSummarySchema => ({ | ||
windows: 0, | ||
linux: 1, | ||
macos: 2, | ||
total: 3, | ||
}); |
94 changes: 94 additions & 0 deletions
94
...ecuritysolution-io-ts-list-types/src/response/exception_list_summary_schema/index.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,94 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { left } from 'fp-ts/lib/Either'; | ||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; | ||
|
||
import { getListSummaryResponseMock } from './index.mock'; | ||
import { ExceptionListSummarySchema, exceptionListSummarySchema } from '.'; | ||
|
||
describe('list_summary_schema', () => { | ||
test('it should validate a typical list summary response', () => { | ||
const payload = getListSummaryResponseMock(); | ||
const decoded = exceptionListSummarySchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it should NOT accept an undefined for "windows"', () => { | ||
const payload = getListSummaryResponseMock(); | ||
// @ts-expect-error | ||
delete payload.windows; | ||
const decoded = exceptionListSummarySchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "undefined" supplied to "windows"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should NOT accept an undefined for "linux"', () => { | ||
const payload = getListSummaryResponseMock(); | ||
// @ts-expect-error | ||
delete payload.linux; | ||
const decoded = exceptionListSummarySchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "undefined" supplied to "linux"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should NOT accept an undefined for "macos"', () => { | ||
const payload = getListSummaryResponseMock(); | ||
// @ts-expect-error | ||
delete payload.macos; | ||
const decoded = exceptionListSummarySchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "undefined" supplied to "macos"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should NOT accept an undefined for "total"', () => { | ||
const payload = getListSummaryResponseMock(); | ||
// @ts-expect-error | ||
delete payload.total; | ||
const decoded = exceptionListSummarySchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
|
||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "undefined" supplied to "total"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it should not allow an extra key to be sent in', () => { | ||
const payload: ExceptionListSummarySchema & { | ||
extraKey?: string; | ||
} = getListSummaryResponseMock(); | ||
payload.extraKey = 'some new value'; | ||
const decoded = exceptionListSummarySchema.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual(['invalid keys "extraKey"']); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
...kbn-securitysolution-io-ts-list-types/src/response/exception_list_summary_schema/index.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,21 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { PositiveInteger } from '@kbn/securitysolution-io-ts-types'; | ||
import * as t from 'io-ts'; | ||
|
||
export const exceptionListSummarySchema = t.exact( | ||
t.type({ | ||
windows: PositiveInteger, | ||
linux: PositiveInteger, | ||
macos: PositiveInteger, | ||
total: PositiveInteger, | ||
}) | ||
); | ||
|
||
export type ExceptionListSummarySchema = t.TypeOf<typeof exceptionListSummarySchema>; |
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.