From 5b17fd5c6c6382f4e181218d422a157649be1aa2 Mon Sep 17 00:00:00 2001 From: David Sanchez Soler Date: Thu, 27 May 2021 13:38:08 +0200 Subject: [PATCH] Add new e2e test for summart endpoint --- .../security_and_spaces/tests/index.ts | 1 + .../tests/summary_exception_lists.ts | 93 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 x-pack/test/lists_api_integration/security_and_spaces/tests/summary_exception_lists.ts diff --git a/x-pack/test/lists_api_integration/security_and_spaces/tests/index.ts b/x-pack/test/lists_api_integration/security_and_spaces/tests/index.ts index 61ca693936643..89a1183da6790 100644 --- a/x-pack/test/lists_api_integration/security_and_spaces/tests/index.ts +++ b/x-pack/test/lists_api_integration/security_and_spaces/tests/index.ts @@ -35,5 +35,6 @@ export default ({ loadTestFile }: FtrProviderContext): void => { loadTestFile(require.resolve('./find_exception_lists')); loadTestFile(require.resolve('./find_exception_list_items')); loadTestFile(require.resolve('./read_list_privileges')); + loadTestFile(require.resolve('./summary_exception_lists')); }); }; diff --git a/x-pack/test/lists_api_integration/security_and_spaces/tests/summary_exception_lists.ts b/x-pack/test/lists_api_integration/security_and_spaces/tests/summary_exception_lists.ts new file mode 100644 index 0000000000000..15ed970db6007 --- /dev/null +++ b/x-pack/test/lists_api_integration/security_and_spaces/tests/summary_exception_lists.ts @@ -0,0 +1,93 @@ +/* + * 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 expect from '@kbn/expect'; + +import { EXCEPTION_LIST_URL, EXCEPTION_LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { LIST_ID } from '../../../../plugins/lists/common/constants.mock'; +import { FtrProviderContext } from '../../common/ftr_provider_context'; +import { getCreateExceptionListMinimalSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_exception_list_schema.mock'; +import { getCreateExceptionListItemMinimalSchemaMock } from '../../../../plugins/lists/common/schemas/request/create_exception_list_item_schema.mock'; +import { createListsIndex, deleteListsIndex, deleteAllExceptions } from '../../utils'; + +// eslint-disable-next-line import/no-default-export +export default ({ getService }: FtrProviderContext) => { + const supertest = getService('supertest'); + const es = getService('es'); + + describe('summary_exception_lists', () => { + describe('summary exception lists', () => { + afterEach(async () => { + await deleteListsIndex(supertest); + await deleteAllExceptions(es); + }); + beforeEach(async () => { + await createListsIndex(supertest); + }); + + it('should give a validation error if the list_id and the id are not supplied', async () => { + const { body } = await supertest + .get(`${EXCEPTION_LIST_URL}/summary`) + .set('kbn-xsrf', 'true') + .send(getCreateExceptionListMinimalSchemaMock()) + .expect(400); + + expect(body).to.eql({ + message: 'id or list_id required', + status_code: 400, + }); + }); + + it('should return init summary when there are no items created', async () => { + const { body } = await supertest + .get(`${EXCEPTION_LIST_URL}/summary?list_id=${LIST_ID}`) + .set('kbn-xsrf', 'true') + .send() + .expect(200); + + expect(body).to.eql({ + linux: 0, + macos: 0, + total: 0, + windows: 0, + }); + }); + + it('should return right summary when there are items created', async () => { + await supertest + .post(EXCEPTION_LIST_URL) + .set('kbn-xsrf', 'true') + .send(getCreateExceptionListMinimalSchemaMock()) + .expect(200); + + const item = getCreateExceptionListItemMinimalSchemaMock(); + + for (const os of ['windows', 'linux', 'macos']) { + await supertest + .post(EXCEPTION_LIST_ITEM_URL) + .set('kbn-xsrf', 'true') + .send({ ...item, os_types: [os], item_id: `${item.item_id}-${os}` }) + .expect(200); + } + + const { body } = await supertest + .get(`${EXCEPTION_LIST_URL}/summary?list_id=${LIST_ID}`) + .set('kbn-xsrf', 'true') + .send() + .expect(200); + + delete body.cursor; + expect(body).to.eql({ + linux: 1, + macos: 1, + total: 3, + windows: 1, + }); + }); + }); + }); +};