Skip to content
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][Endpoint] Add event filters summary card to the fleet endpoint tab #100668

Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f6934d2
Shows event filters card on fleet page
dasansol92 May 26, 2021
3864d72
Uses aggs instead of while loop to retrieve summary data
dasansol92 May 26, 2021
64e9d65
Add request and response types in the lists package
dasansol92 May 26, 2021
06a8f0c
Fixes old import
dasansol92 May 26, 2021
41c0bd7
Merge branch 'master' into feature/olm-add_event_filters_summary_card…
dasansol92 May 26, 2021
0ad0902
Removes old i18n keys
dasansol92 May 26, 2021
662c59b
Removes more old i18n keys
dasansol92 May 26, 2021
aca55cd
Use consts for exception lists url and endpoint event filter list id
dasansol92 May 26, 2021
84d46a4
Uses event filters service to retrieve summary data
dasansol92 May 27, 2021
e42bf61
Fixes addressed pr comments such as changing the route without unders…
dasansol92 May 27, 2021
9f6b620
Uses useMemo instead of useState to memoize object
dasansol92 May 27, 2021
5b17fd5
Add new e2e test for summart endpoint
dasansol92 May 27, 2021
39c8133
Handle api errors on event filters and trusted apps summary api calls
dasansol92 May 27, 2021
b0d77b2
Add api error message to the toast
dasansol92 May 27, 2021
9324dc3
Fix wrong i18n key
dasansol92 May 27, 2021
0cc6766
Change span tag by react fragment
dasansol92 May 27, 2021
29014e8
Uses styled components instead of modify compontent style directly an…
dasansol92 May 28, 2021
8993d4e
Adds curls script for summary route
dasansol92 May 28, 2021
31538c7
Merge branch 'master' into feature/olm-add_event_filters_summary_card…
kibanamachine May 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export * from './read_exception_list_item_schema';
export * from './read_exception_list_schema';
export * from './read_list_item_schema';
export * from './read_list_schema';
export * from './summary_exception_list_schema';
export * from './update_endpoint_list_item_schema';
export * from './update_exception_list_item_schema';
export * from './update_exception_list_item_validation';
Expand Down
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,
});
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({});
});
});
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;
};
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,
});
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({});
});
});
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>;
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export * from './found_list_item_schema';
export * from './found_list_schema';
export * from './list_item_schema';
export * from './list_schema';
export * from './exception_list_summary_schema';
export * from './list_item_index_exist_schema';
export * from './search_list_item_schema';
1 change: 1 addition & 0 deletions x-pack/plugins/lists/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export * from './read_list_index_route';
export * from './read_list_item_route';
export * from './read_list_route';
export * from './read_privileges_route';
export * from './summary_exception_list_route';
export * from './update_endpoint_list_item_route';
export * from './update_exception_list_item_route';
export * from './update_exception_list_route';
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/lists/server/routes/init_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
readListItemRoute,
readListRoute,
readPrivilegesRoute,
summaryExceptionListRoute,
updateEndpointListItemRoute,
updateExceptionListItemRoute,
updateExceptionListRoute,
Expand Down Expand Up @@ -95,4 +96,7 @@ export const initRoutes = (router: ListsPluginRouter, config: ConfigType): void
updateEndpointListItemRoute(router);
deleteEndpointListItemRoute(router);
findEndpointListItemRoute(router);

// exception list items summary
summaryExceptionListRoute(router);
};
Loading