-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new e2e test for summart endpoint
- Loading branch information
1 parent
9f6b620
commit 5b17fd5
Showing
2 changed files
with
94 additions
and
0 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
93 changes: 93 additions & 0 deletions
93
x-pack/test/lists_api_integration/security_and_spaces/tests/summary_exception_lists.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,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, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; |